"Fossies" - the Fresh Open Source Software Archive

Member "src/Platform/SerializerFactory.h" (10 Oct 2018, 2629 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "SerializerFactory.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  Derived from source code of TrueCrypt 7.1a, which is
    3  Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
    4  by the TrueCrypt License 3.0.
    5 
    6  Modifications and additions to the original source code (contained in this file)
    7  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
    8  and are governed by the Apache License 2.0 the full text of which is
    9  contained in the file License.txt included in VeraCrypt binary and source
   10  code distribution packages.
   11 */
   12 
   13 #ifndef TC_HEADER_Platform_SerializerFactory
   14 #define TC_HEADER_Platform_SerializerFactory
   15 
   16 #include <typeinfo>
   17 #include "PlatformBase.h"
   18 #include "StringConverter.h"
   19 
   20 namespace VeraCrypt
   21 {
   22     class Serializable;
   23 
   24     class SerializerFactory
   25     {
   26     public:
   27         ~SerializerFactory ();
   28 
   29         static void Deinitialize ();
   30         static string GetName (const type_info &typeInfo);
   31         static Serializable *GetNewSerializable (const string &typeName);
   32         static void Initialize ();
   33 
   34         struct MapEntry
   35         {
   36             MapEntry () { }
   37             MapEntry (const string &typeName, Serializable* (*getNewPtr) ())
   38                 : TypeName (typeName), GetNewPtr (getNewPtr) { }
   39 
   40             MapEntry &operator= (const MapEntry &right)
   41             {
   42                 TypeName = right.TypeName;
   43                 GetNewPtr = right.GetNewPtr;
   44                 return *this;
   45             }
   46 
   47             string TypeName;
   48             Serializable* (*GetNewPtr) ();
   49         };
   50 
   51         static map <string, MapEntry> *NameToTypeMap;
   52         static map <string, string> *TypeToNameMap;
   53 
   54     protected:
   55         SerializerFactory ();
   56 
   57         static int UseCount;
   58     };
   59 
   60 }
   61 
   62 #define TC_SERIALIZER_FACTORY_ADD_EXCEPTION_SET(TYPE) \
   63     struct TYPE##SerializerFactoryInitializer \
   64     { \
   65         TYPE##SerializerFactoryInitializer () \
   66         { \
   67             SerializerFactory::Initialize(); \
   68             TC_EXCEPTION_SET; \
   69         } \
   70         ~TYPE##SerializerFactoryInitializer () \
   71         { \
   72             SerializerFactory::Deinitialize(); \
   73         } \
   74     }; \
   75     static TYPE##SerializerFactoryInitializer TYPE##SerializerFactoryInitializer
   76 
   77 #define TC_SERIALIZER_FACTORY_ADD_CLASS(TYPE) \
   78     struct TYPE##SerializerFactoryInitializer \
   79     { \
   80         TYPE##SerializerFactoryInitializer () \
   81         { \
   82             SerializerFactory::Initialize(); \
   83             TC_SERIALIZER_FACTORY_ADD (TYPE); \
   84         } \
   85         ~TYPE##SerializerFactoryInitializer () \
   86         { \
   87             SerializerFactory::Deinitialize(); \
   88         } \
   89     }; \
   90     static TYPE##SerializerFactoryInitializer TYPE##SerializerFactoryInitializerInst
   91 
   92 #define TC_SERIALIZER_FACTORY_ADD(TYPE) \
   93     (*SerializerFactory::NameToTypeMap)[#TYPE] = SerializerFactory::MapEntry (StringConverter::GetTypeName (typeid (TYPE)), &TYPE::GetNewSerializable); \
   94     (*SerializerFactory::TypeToNameMap)[StringConverter::GetTypeName (typeid (TYPE))] = #TYPE
   95 
   96 
   97 #endif // TC_HEADER_Platform_SerializerFactory