CkptTypeRegistry.h

Go to the documentation of this file.
00001 #ifndef CKPTTYPEREGISTER_H_
00002 #define CKPTTYPEREGISTER_H_
00003 
00004 #include <stdlib.h>
00005 #include <stdio.h>
00006 #include <string>
00007 #include <iostream>
00008 #include <map>
00009 
00010 #define COAL_SERIALIZE_BASE(BaseClass, DaoProvider) \
00011    BaseClass::serialize(DaoProvider)
00012 
00016 #define COAL_DECLARE_CLASSNAME(N) \
00017  virtual char* COAL_getClassname() { return N; }; \
00018  static  char* COAL_static_getClassname() { return N; }; \
00019  virtual char* getClassname() { return COAL_getClassname(); };
00020 
00028 #define COAL_REGISTER_TYPE(T) \
00029 TypeRegistrant<T> const& COAL_registrant_ ## T = \
00030         TypeRegistrant<T>::instance(T::COAL_static_getClassname());
00031 
00032 typedef void* (*SerializedFactoryFunc)();
00033 
00039 template<class T>
00040 struct TypeRegistrant {
00041         TypeRegistrant(const char *name=0);
00042 
00043         static const TypeRegistrant& instance(char *name) {
00044             static TypeRegistrant const _instance(name);
00045             return _instance;
00046         }
00047 
00048         static void* create() { return new T(); }
00049 };
00050 
00051 extern std::map<std::string, SerializedFactoryFunc> ofMap;
00052 
00053 template<class T>
00054 TypeRegistrant<T>::TypeRegistrant(const char *name) {
00055         if (name != NULL) {
00056            std::string nS(name);
00057            ofMap[name] = create;
00058         }
00059 };
00060 
00061 #endif /*CKPTTYPEREGISTER_H_*/
00062 

Generated on Fri Apr 27 17:20:01 2007 for aiscoal by  doxygen 1.5.2