EntryID implementation changes for #956

- move the santitise operation up into EntryID's ctor
- turn the recast() operation into a real in-place cast

these changes should be transparent to the existing usages
of EntryID (within the asset framework), but allow for use
as attribute name holder in GenNode, since we're now able
to feed existing name/ID values directly into the ctor
of BareEntryID, without any spurious santitise operation.
This commit is contained in:
Fischlurch 2015-07-03 00:45:02 +02:00
parent 9b694044eb
commit 9d42b58aae

View file

@ -133,7 +133,7 @@ namespace idi {
* generates differing hash-IDs for different type parameters * generates differing hash-IDs for different type parameters
*/ */
BareEntryID (string const& symbolID, HashVal seed =0) BareEntryID (string const& symbolID, HashVal seed =0)
: symbol_(util::sanitise(symbolID)) : symbol_(symbolID)
, hash_(buildHash (symbol_, seed)) , hash_(buildHash (symbol_, seed))
{ } { }
@ -169,7 +169,7 @@ namespace idi {
template<typename TAR> template<typename TAR>
EntryID<TAR> recast() const; EntryID<TAR> const& recast() const;
}; };
@ -211,7 +211,7 @@ namespace idi {
*/ */
explicit explicit
EntryID (string const& symbolID) EntryID (string const& symbolID)
: BareEntryID (symbolID, getTypeHash<TY>()) : BareEntryID (util::sanitise(symbolID), getTypeHash<TY>())
{ } { }
@ -226,14 +226,14 @@ namespace idi {
return bID.getHash() == buildHash (bID.getSym(), getTypeHash<TY>()); return bID.getHash() == buildHash (bID.getSym(), getTypeHash<TY>());
} }
static EntryID static EntryID const&
recast (BareEntryID const& bID) recast (BareEntryID const& bID)
{ {
if (!canRecast(bID)) if (!canRecast(bID))
throw error::Logic ("unable to recast EntryID: desired type " throw error::Logic ("unable to recast EntryID: desired type "
"doesn't match original definition" "doesn't match original definition"
, error::LUMIERA_ERROR_WRONG_TYPE); , error::LUMIERA_ERROR_WRONG_TYPE);
return EntryID (bID.getSym()); return static_cast<EntryID const&> (bID);
} }
@ -268,7 +268,8 @@ namespace idi {
* Exception if it doesn't match the stored hash. * Exception if it doesn't match the stored hash.
*/ */
template<typename TAR> template<typename TAR>
EntryID<TAR> BareEntryID::recast() const EntryID<TAR> const&
BareEntryID::recast() const
{ {
return EntryID<TAR>::recast(*this); return EntryID<TAR>::recast(*this);
} }