40 #ifndef LIB_IDI_ENTRY_ID_H 41 #define LIB_IDI_ENTRY_ID_H 49 #include <boost/functional/hash.hpp> 50 #include <boost/operators.hpp> 110 size_t l = sym.length();
111 if (l > 1) boost::hash_combine(seed, KNUTH_MAGIC * sym[l-1]);
112 if (l > 2) boost::hash_combine(seed, KNUTH_MAGIC * sym[l-2]);
113 if (l > 3) boost::hash_combine(seed, KNUTH_MAGIC * sym[l-3]);
114 if (l > 4) boost::hash_combine(seed, KNUTH_MAGIC * sym[l-4]);
116 boost::hash_combine(seed, sym);
119 return reinterpret_cast<LuidH&
> (tmpLUID);
134 :
public boost::equality_comparable<BareEntryID>
181 operator string()
const;
186 :
public std::unary_function<BareEntryID, size_t>
188 size_t operator() (
BareEntryID const& obj)
const {
return obj.getHash(); }
192 template<
typename TAR>
221 , boost::totally_ordered< EntryID<TY> >
239 :
BareEntryID (util::sanitise(symbolID), getTypeHash<TY>())
260 return bID.getHash() ==
buildHash (bID.getSym(), getTypeHash<TY>());
267 throw error::Logic (
"unable to recast EntryID: desired type " 268 "doesn't match original definition" 269 , error::LUMIERA_ERROR_WRONG_TYPE);
270 return static_cast<EntryID const&
> (bID);
274 operator string()
const;
276 friend bool operator< (
EntryID const& i1,
EntryID const& i2) {
return i1.getSym() < i2.getSym(); }
283 return i1.getHash() == i2.getHash();
297 RandID (
string const& symbolID)
300 RandID (
const char* symbolID)
320 template<
typename TAR>
329 BareEntryID::operator string()
const 331 return "bID-"+lib::idi::format::instance_hex_format(symbol_, hash_);
338 return "ID<"+typeSymbol<TY>()+
">-"+EntryID::getSym();
type erased baseclass for building a combined hash and symbolic ID.
Entry-ID with a symbolic tag but just a plain random hash part.
EntryID(string const &symbolID)
case-2: explicitly specify a symbolic ID to use.
const size_t KNUTH_MAGIC
lousy old tinkerer's trick: hash values with poor distribution can be improved by spreading the input...
typed symbolic and hash ID for asset-like position accounting.
EntryID()
case-1: auto generated symbolic ID
Implementation namespace for support and library code.
Generic functions to build identification schemes.
static bool canRecast(BareEntryID const &bID)
BareEntryID(string const &symbolID, HashVal seed)
Not to be created stand-alone.
Derived specific exceptions within Lumiera's exception hierarchy.
Token or Atom with distinct identity.
EntryID< TAR > const & recast() const
try to upcast this BareEntryID to a fully typed EntryID.
BareEntryID(string const &symbolID)
store the symbol but use a random hash part
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A template for generating hash based ID tags carrying compile-time type info.
Lumiera error handling (C++ interface).
string typeSymbol()
Short readable type identifier, not necessarily unique or complete.
Hash implementation based on a lumiera unique object id (LUID) When invoking the default ctor...
size_t HashVal
a STL compatible hash value
EntryID(Symbol const &internalSymbol)
case-2b: rely on an internal, already sanitised symbol.
string generateSymbolicID()
build a per-type identifier, with type prefix and running counter.
unsigned char lumiera_uid[16]
storage for a Lumiera unique ID, based on a 128bit random number
LuidH buildHash(string const &sym, HashVal seed=0)
build up a hash value, packaged as LUID.
using BareEntryID derived objects as keys within std::unordered_map
void lumiera_uid_set_ptr(lumiera_uid *luid, void *ptr)
Store a generic pointer in a luid.