Lumiera  0.pre.03
»edit your freedom«
genfunc.hpp
Go to the documentation of this file.
1 /*
2  GENFUNC.hpp - generic identification functions
3 
4  Copyright (C)
5  2015, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
36 #ifndef LIB_IDI_GENFUNC_H
37 #define LIB_IDI_GENFUNC_H
38 
39 #include "lib/hash-value.h"
40 #include "lib/symbol.hpp"
41 #include "lib/typed-counter.hpp"
42 //#include "lib/hash-standard.hpp"
43 
44 #include <typeinfo>
45 #include <string>
46 
47 
48 namespace lib {
49 namespace meta{
50  std::string demangleCxx (lib::Literal rawName);
51  std::string humanReadableTypeID (lib::Literal);
52  std::string primaryTypeComponent (lib::Literal);
54 }// implemented in format-obj.cpp
55 
56 namespace idi {
57 
58  using lib::HashVal;
59  using std::string;
60 
61  namespace format { // integration helpers...
62 
63  string instance_format (string const& prefix, size_t instanceNr);
64  string instance_hex_format (string const& prefix, size_t instanceNr);
65 
66  } //(End)integration helpers...
67 
68 
69 
76  template<typename TY>
77  inline string
79  {
80  return lib::meta::primaryTypeComponent (typeid(TY).name());
81  }
82 
88  template<typename TY>
89  inline string
91  {
92  return lib::meta::sanitisedFullTypeName (typeid(TY).name());
93  }
94 
95  template<typename TY>
96  inline string
97  categoryFolder()
98  {
99  return typeSymbol<TY>();
100  }
101 
102  template<typename TY>
103  inline string
104  namePrefix()
105  {
106  return typeSymbol<TY>();
107  }
108 
114  template<typename TY>
115  inline string
116  instanceTypeID(const TY *const obj)
117  {
118  return format::instance_hex_format (namePrefix<TY>(), (size_t(obj) / alignof(TY)) % (1<<16));
119  }
120 
121 
122  TypedCounter& sharedInstanceCounter();
123 
124 
134  template<class TY>
135  inline string
137  {
138  return format::instance_format (namePrefix<TY>(), sharedInstanceCounter().inc<TY>());
139  }
140 
148  template<class TY>
149  inline string
150  generateExtendedID(string prefix ="")
151  {
152  return format::instance_format (prefix + typeFullID<TY>(), sharedInstanceCounter().inc<TY>());
153  }
154 
158  template<typename TY>
159  inline HashVal
161  {
162  return typeid(TY).hash_code();
163  }
164 
165 
166 
167 }} // namespace lib::idi
168 #endif /*LIB_IDI_GENFUNC_H*/
Creating series of type-based contexts.
Utility providing a set of counters, each tied to a specific type.
string generateExtendedID(string prefix="")
build a long type based identifier, with running counter and custom prefix.
Definition: genfunc.hpp:150
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:76
Implementation namespace for support and library code.
string primaryTypeComponent(Literal rawType)
extract core name component from a raw type spec
Definition: format-obj.cpp:268
string sanitisedFullTypeName(lib::Literal rawName)
build a sanitised ID from full type name
Definition: format-obj.cpp:306
Marker types to indicate a literal string and a Symbol.
string demangleCxx(Literal rawName)
Fallback type-ID:
Definition: format-obj.cpp:159
string humanReadableTypeID(Literal rawType)
pretty-print an internal C++ type representation
Definition: format-obj.cpp:190
HashVal getTypeHash()
Definition: genfunc.hpp:160
string typeFullID()
Complete unique type identifier.
Definition: genfunc.hpp:90
string typeSymbol()
Short readable type identifier, not necessarily unique or complete.
Definition: genfunc.hpp:78
string instanceTypeID(const TY *const obj)
designation of an distinct object instance
Definition: genfunc.hpp:116
Hash value types and utilities.
size_t HashVal
a STL compatible hash value
Definition: hash-value.h:52
string generateSymbolicID()
build a per-type identifier, with type prefix and running counter.
Definition: genfunc.hpp:136
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption