49 #ifndef LIB_IDI_ENTRY_ID_H 50 #define LIB_IDI_ENTRY_ID_H 58 #include <boost/functional/hash.hpp> 59 #include <boost/operators.hpp> 119 size_t l = sym.length();
120 if (l > 1) boost::hash_combine(seed, KNUTH_MAGIC * sym[l-1]);
121 if (l > 2) boost::hash_combine(seed, KNUTH_MAGIC * sym[l-2]);
122 if (l > 3) boost::hash_combine(seed, KNUTH_MAGIC * sym[l-3]);
123 if (l > 4) boost::hash_combine(seed, KNUTH_MAGIC * sym[l-4]);
125 boost::hash_combine(seed, sym);
128 return reinterpret_cast<LuidH&
> (tmpLUID);
143 :
public boost::equality_comparable<BareEntryID>
190 operator string()
const;
195 :
public std::unary_function<BareEntryID, size_t>
197 size_t operator() (
BareEntryID const& obj)
const {
return obj.getHash(); }
201 template<
typename TAR>
230 , boost::totally_ordered< EntryID<TY> >
248 :
BareEntryID (util::sanitise(symbolID), getTypeHash<TY>())
269 return bID.getHash() ==
buildHash (bID.getSym(), getTypeHash<TY>());
276 throw error::Logic (
"unable to recast EntryID: desired type " 277 "doesn't match original definition" 278 , error::LUMIERA_ERROR_WRONG_TYPE);
279 return static_cast<EntryID const&
> (bID);
283 operator string()
const;
285 friend bool operator< (
EntryID const& i1,
EntryID const& i2) {
return i1.getSym() < i2.getSym(); }
292 return i1.getHash() == i2.getHash();
306 RandID (
string const& symbolID)
309 RandID (
const char* symbolID)
329 template<
typename TAR>
338 BareEntryID::operator string()
const 340 return "bID-"+lib::idi::format::instance_hex_format(symbol_, hash_);
347 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.