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) Lumiera.org
5  2015, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
45 #ifndef LIB_IDI_GENFUNC_H
46 #define LIB_IDI_GENFUNC_H
47 
48 #include "lib/hash-value.h"
49 #include "lib/symbol.hpp"
50 #include "lib/typed-counter.hpp"
51 //#include "lib/hash-standard.hpp"
52 
53 #include <typeinfo>
54 #include <string>
55 
56 
57 namespace lib {
58 namespace meta{
59  std::string demangleCxx (lib::Literal rawName);
60  std::string humanReadableTypeID (lib::Literal);
61  std::string primaryTypeComponent (lib::Literal);
63 }// implemented in format-obj.cpp
64 
65 namespace idi {
66 
67  using lib::HashVal;
68  using std::string;
69 
70  namespace format { // integration helpers...
71 
72  string instance_format (string const& prefix, size_t instanceNr);
73  string instance_hex_format (string const& prefix, size_t instanceNr);
74 
75  } //(End)integration helpers...
76 
77 
78 
85  template<typename TY>
86  inline string
88  {
89  return lib::meta::primaryTypeComponent (typeid(TY).name());
90  }
91 
97  template<typename TY>
98  inline string
100  {
101  return lib::meta::sanitisedFullTypeName (typeid(TY).name());
102  }
103 
104  template<typename TY>
105  inline string
106  categoryFolder()
107  {
108  return typeSymbol<TY>();
109  }
110 
111  template<typename TY>
112  inline string
113  namePrefix()
114  {
115  return typeSymbol<TY>();
116  }
117 
123  template<typename TY>
124  inline string
125  instanceTypeID(const TY *const obj)
126  {
127  return format::instance_hex_format (namePrefix<TY>(), (size_t(obj) / alignof(TY)) % (1<<16));
128  }
129 
130 
131  TypedCounter& sharedInstanceCounter();
132 
133 
143  template<class TY>
144  inline string
146  {
147  return format::instance_format (namePrefix<TY>(), sharedInstanceCounter().inc<TY>());
148  }
149 
157  template<class TY>
158  inline string
159  generateExtendedID(string prefix ="")
160  {
161  return format::instance_format (prefix + typeFullID<TY>(), sharedInstanceCounter().inc<TY>());
162  }
163 
167  template<typename TY>
168  inline HashVal
170  {
171  return typeid(TY).hash_code();
172  }
173 
174 
175 
176 }} // namespace lib::idi
177 #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:159
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:85
Implementation namespace for support and library code.
string primaryTypeComponent(Literal rawType)
extract core name component from a raw type spec
Definition: format-obj.cpp:270
string sanitisedFullTypeName(lib::Literal rawName)
build a sanitised ID from full type name
Definition: format-obj.cpp:308
Marker types to indicate a literal string and a Symbol.
string demangleCxx(Literal rawName)
Fallback type-ID:
Definition: format-obj.cpp:168
string humanReadableTypeID(Literal rawType)
pretty-print an internal C++ type representation
Definition: format-obj.cpp:199
HashVal getTypeHash()
Definition: genfunc.hpp:169
string typeFullID()
Complete unique type identifier.
Definition: genfunc.hpp:99
string typeSymbol()
Short readable type identifier, not necessarily unique or complete.
Definition: genfunc.hpp:87
string instanceTypeID(const TY *const obj)
designation of an distinct object instance
Definition: genfunc.hpp:125
Hash value types and utilities.
size_t HashVal
a STL compatible hash value
Definition: hash-value.h:56
string generateSymbolicID()
build a per-type identifier, with type prefix and running counter.
Definition: genfunc.hpp:145
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption