Update README.md
[nemesis.git] / Platform / SerializerFactory.h
1 /*
2  Copyright (c) 2008 TrueCrypt Developers Association. All rights reserved.
3
4  Governed by the TrueCrypt License 3.0 the full text of which is contained in
5  the file License.txt included in TrueCrypt binary and source code distribution
6  packages.
7 */
8
9 #ifndef TC_HEADER_Platform_SerializerFactory
10 #define TC_HEADER_Platform_SerializerFactory
11
12 #include <typeinfo>
13 #include "PlatformBase.h"
14 #include "StringConverter.h"
15
16 namespace TrueCrypt
17 {
18         class Serializable;
19
20         class SerializerFactory
21         {
22         public:
23                 ~SerializerFactory ();
24
25                 static void Deinitialize ();
26                 static string GetName (const type_info &typeInfo);
27                 static Serializable *GetNewSerializable (const string &typeName);
28                 static void Initialize ();
29
30                 struct MapEntry
31                 {
32                         MapEntry () { }
33                         MapEntry (const string &typeName, Serializable* (*getNewPtr) ())
34                                 : TypeName (typeName), GetNewPtr (getNewPtr) { }
35
36                         MapEntry &operator= (const MapEntry &right)
37                         {
38                                 TypeName = right.TypeName;
39                                 GetNewPtr = right.GetNewPtr;
40                                 return *this;
41                         }
42
43                         string TypeName;
44                         Serializable* (*GetNewPtr) ();
45                 };
46
47                 static map <string, MapEntry> *NameToTypeMap;
48                 static map <string, string> *TypeToNameMap;
49
50         protected:
51                 SerializerFactory ();
52
53                 static int UseCount;
54         };
55
56 }
57
58 #define TC_SERIALIZER_FACTORY_ADD_EXCEPTION_SET(TYPE) \
59         struct TYPE##SerializerFactoryInitializer \
60         { \
61                 TYPE##SerializerFactoryInitializer () \
62                 { \
63                         SerializerFactory::Initialize(); \
64                         TC_EXCEPTION_SET; \
65                 } \
66                 ~TYPE##SerializerFactoryInitializer () \
67                 { \
68                         SerializerFactory::Deinitialize(); \
69                 } \
70         }; \
71         static TYPE##SerializerFactoryInitializer TYPE##SerializerFactoryInitializer
72
73 #define TC_SERIALIZER_FACTORY_ADD_CLASS(TYPE) \
74         struct TYPE##SerializerFactoryInitializer \
75         { \
76                 TYPE##SerializerFactoryInitializer () \
77                 { \
78                         SerializerFactory::Initialize(); \
79                         TC_SERIALIZER_FACTORY_ADD (TYPE); \
80                 } \
81                 ~TYPE##SerializerFactoryInitializer () \
82                 { \
83                         SerializerFactory::Deinitialize(); \
84                 } \
85         }; \
86         static TYPE##SerializerFactoryInitializer TYPE##SerializerFactoryInitializerInst
87
88 #define TC_SERIALIZER_FACTORY_ADD(TYPE) \
89         (*SerializerFactory::NameToTypeMap)[#TYPE] = SerializerFactory::MapEntry (StringConverter::GetTypeName (typeid (TYPE)), &TYPE::GetNewSerializable); \
90         (*SerializerFactory::TypeToNameMap)[StringConverter::GetTypeName (typeid (TYPE))] = #TYPE
91
92
93 #endif // TC_HEADER_Platform_SerializerFactory
This page took 0.019693 seconds and 3 git commands to generate. Download a nemesis OSX (sierra+high sierra, tested/working) binary, with fuse-ext3 via e2fsprogs, at this link. application and installer are signed by screwjack, llc. must install fuse with macFUSE layer first.