Lumiera  0.pre.03
»edit your freedom«
hash-indexed.hpp File Reference

Go to the source code of this file.

Description

A template for generating hash based ID tags carrying compile-time type info.

While the actual storage is assumed to be based on a POD, the type info is crucial to circumvent the problems with an "object" base class. Frequently, the need to manage some objects in a central facility drives us to rely on a common base class, irrespective of an actual common denominator in the semantics of the objects to be managed within this collection. Typically this results in this common base class being almost worthless as an API or interface, causing lots of type casts when using such a common object management facility. Passing additional context or API information on a metaprogramming level through the management interface helps avoiding these shortcomings.

Here we build an ID facility with the following properties:

  • based on a configurable storage/implementation of the actual hash or index code.
  • tied to a specific hierarchy of objects (template parameter "BA")
  • providing an additional template parameter to pass the desired type info
  • establishing an type hierarchy relation between ID related to the base class and the IDs denoting specific subclasses, such that the latter can stand-in for the generic ID.
  • providing a Mixin, which allows any hierarchy to use this facility without much code duplication, including an adapter for std::unordered_map
  • equality comparison
See also
HashIndexed_test
Placement usage example

Definition in file hash-indexed.hpp.

#include "lib/hash-value.h"
#include "lib/hash-standard.hpp"
#include "lib/error.hpp"
#include "lib/luid.h"
#include <functional>

Classes

struct  HashIndexed< BA, IMP >
 A Mixin to add a private ID type to the target class, together with storage to hold an instance of this ID, getter and setter, and a templated version of the ID type which can be used to pass specific subclass type info. More...
 
struct  HashIndexed< BA, IMP >::Id< T >
 Hash based ID, typed to a specific subclass of BA. More...
 
struct  HashIndexed< BA, IMP >::ID
 generic hash based ID, corresponding to the base class BA More...
 
class  LuidH
 Hash implementation based on a lumiera unique object id (LUID) When invoking the default ctor, a new LUID is generated. More...
 
class  Plain
 simple Hash implementation directly incorporating the hash value. More...
 
struct  HashIndexed< BA, IMP >::UseEmbeddedHash
 enables use of BA objects as keys within std::unordered_map More...
 
struct  HashIndexed< BA, IMP >::UseHashID
 trivial hash functor using the ID as hash More...
 

Functions

HashVal hash_value (Plain const &plainHash)
 
HashVal hash_value (LuidH const &luid_Hash)
 

Namespaces

 lib
 Implementation namespace for support and library code.
 
 lib::hash
 Hash implementations usable for the HashIndexed mixin as well as key within std::unordered_map.