HOPS
HOPS class reference
MHO_ClassIdentity.hh
Go to the documentation of this file.
1 #ifndef MHO_ClassIdentity_HH__
2 #define MHO_ClassIdentity_HH__
3 
5 #include "MHO_Message.hh"
7 #include "MHO_Types.hh"
8 #include "MHO_UUID.hh"
9 #include <string>
10 
11 namespace hops
12 {
13 
22 typedef uint32_t MHO_ClassVersion;
23 
34 template< typename XClassType > struct MHO_TypeTag
35 {
36  static std::string Value() { return MHO_ClassName< XClassType >(); }
37 };
38 
43 {
44 
51  template< typename XClassType > static std::string ClassName() { return MHO_ClassName< XClassType >(); };
52 
60  template< typename XClassType > static std::string ClassName(const XClassType&)
61  {
62  return MHO_ClassName< XClassType >();
63  };
64 
72  template< typename XClassType > static MHO_UUID GetUUIDFromClass()
73  {
75  }
76 
84  template< typename XClassType > static MHO_UUID GetUUIDFromClass(const XClassType&)
85  {
87  }
88 
95  static MHO_UUID GetUUIDFromClassName(std::string name)
96  {
98  gen.Initialize();
99  gen << name;
100  gen.Finalize();
101  MHO_UUID type_uuid = gen.GetDigestAsUUID();
102  return type_uuid;
103  }
104 
112  template< typename XClassType > static void ClassVersionErrorMsg(const XClassType& obj, MHO_ClassVersion version)
113  {
114  msg_error("file", "Failed to stream object data for: " << MHO_ClassIdentity::ClassName(obj)
115  << ", version: " << version << " is not recognized." << eom);
116  };
117 };
118 
119 } // namespace hops
120 
127 #define HOPS_REGISTER_TYPE_TAG(T, NAME) \
128  namespace hops \
129  { \
130  template<> struct MHO_TypeTag< T > \
131  { \
132  static std::string Value() { return std::string(NAME); } \
133  }; \
134  }
135 
136 #endif
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:238
Class MHO_MD5HashGenerator declares the concrete class which does the work for file streams.
Definition: MHO_MD5HashGenerator.hh:134
void Finalize()
Finalizes the MD5 hash calculation and stores the result in fDigest.
Definition: MHO_MD5HashGenerator.hh:155
MHO_UUID GetDigestAsUUID()
Getter for digest as uuid.
Definition: MHO_MD5HashGenerator.hh:181
void Initialize()
Recursive function to initialize a game state.
Definition: MHO_MD5HashGenerator.hh:143
Class MHO_UUID - a class for a 16 byte UUID (for object and type identification)
Definition: MHO_UUID.hh:27
const char version[]
Definition: difx2mark4.c:37
Definition: MHO_AdhocFlagging.hh:18
uint32_t MHO_ClassVersion
Definition: MHO_ClassIdentity.hh:22
Class MHO_ClassIdentity.
Definition: MHO_ClassIdentity.hh:43
static MHO_UUID GetUUIDFromClass()
Returns the class name as a string.
Definition: MHO_ClassIdentity.hh:72
static std::string ClassName(const XClassType &)
Returns the class name as a string.
Definition: MHO_ClassIdentity.hh:60
static MHO_UUID GetUUIDFromClassName(std::string name)
Generates a UUID from the class name.
Definition: MHO_ClassIdentity.hh:95
static MHO_UUID GetUUIDFromClass(const XClassType &)
Returns the UUID associated with a class type.
Definition: MHO_ClassIdentity.hh:84
static void ClassVersionErrorMsg(const XClassType &obj, MHO_ClassVersion version)
Generates an error message for when an unknown or unsupported class version is encountered.
Definition: MHO_ClassIdentity.hh:112
static std::string ClassName()
Returns the class name as a string.
Definition: MHO_ClassIdentity.hh:51
Compiler-independent type tag used as the input to UUID generation.
Definition: MHO_ClassIdentity.hh:35
static std::string Value()
Definition: MHO_ClassIdentity.hh:36