Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members

reg_serializer.h

00001 //////////////////////////////////////////////////////////////////////// 00002 // "supermacro" code for doing some registration stuff for Serializers. 00003 // License: Public Domain 00004 // Author: stephan@s11n.net 00005 //////////////////////////////////////////////////////////////////////// 00006 // NOTE: this file does not use a conventional BLAH_H_INCLUDED guard. 00007 // Yes, that's on purpose. 00008 //////////////////////////////////////////////////////////////////////// 00009 // Boilerplate code for a 00010 // proxies. 00011 // 00012 // 00013 // The s11n header files are expected to have been included by the 00014 // time this file is ever included. 00015 // 00016 // 00017 // usage: 00018 // define: 00019 // SERIALIZER_TYPE serializer_class 00020 // SERIALIZER_BASE base_of_serializer (or SERIALIZER_TYPE) 00021 // SERIALIZER_MAGIC_COOKIE optional "#!/magic/cookie/string" 00022 // SERIALIZER_ALIAS optional "alias_string" for classloading 00023 // 00024 // #include <this_file> 00025 // 00026 // After each include all of these macros are unset so that they may 00027 // be immediately re-used for another registration. 00028 // 00029 // The cookie is required if s11n is to be able to load 00030 // your files transparently. An alias is convenient for s11nconvert 00031 // and such, but not required. 00032 //////////////////////////////////////////////////////////////////////// 00033 //////////////////////////////////////////////////////////////////////// 00034 // General notes: 00035 // 00036 // By s11n convention S11N_NAME should contain no spaces, even for 00037 // template types. Thus, please use: 00038 // 00039 // "std::list<std::list<foo*>>" 00040 // 00041 // instead of: 00042 // 00043 // "std::list<std::<list<foo *> >" 00044 // 00045 // C++ needs a space between "> >", but s11n does not. 00046 // That said, s11n DOESN'T CARE what class names you use, as long 00047 // as you're consistent. 00048 // 00049 //////////////////////////////////////////////////////////////////////// 00050 00051 #include <stdlib.h> // abort 00052 00053 #define DEBUG_REG 0 00054 #if DEBUG_REG 00055 # include <s11n/debuggering_macros.h> 00056 #endif 00057 00058 00059 #ifndef SERIALIZER_TYPE 00060 # error "SERIALIZER_TYPE is not set. Set it to the type you want to proxy before including this file!" 00061 #endif 00062 00063 #ifndef SERIALIZER_NAME 00064 # error "SERIALIZER_NAME must be set to the string form of SERIALIZER_TYPE" 00065 #endif 00066 00067 #ifndef SERIALIZER_BASE 00068 # error "SERIALIZER_BASE must be the base-most type of SERIALIZER_TYPE (may be the same)." 00069 #endif 00070 00071 // #warning "Running reg for serializer" 00072 00073 namespace { // anonymous namespace is important for complex linking reasons. 00074 00075 //////////////////////////////////////////////////////////////////////// 00076 // A utility to keep us from having to hard-code or macro-ize the class 00077 // name (macroing won't work with commas in the class names, anyway). 00078 template <> struct class_name< SERIALIZER_TYPE > { 00079 static const char * name() 00080 { 00081 return SERIALIZER_NAME; 00082 } 00083 }; 00084 00085 00086 00087 #ifndef s11n_SERIALIZER_REG_CONTEXT_DEFINED 00088 #define s11n_SERIALIZER_REG_CONTEXT_DEFINED 1 00089 /////////////////////////////////////////////////////////////// 00090 // we must not include this more than once per compilation unit 00091 /////////////////////////////////////////////////////////////// 00092 // A unique (per SERIALIZER_BASE/per compilation unit) space to assign 00093 // a bogus value for classloader registration purposes (see 00094 // the classloader docs for a full description of how this 00095 // works). 00096 template <typename Context> 00097 struct serializer_reg_context 00098 { 00099 typedef Context context; 00100 static bool placeholder; 00101 static void reg() 00102 { 00103 CERR << "ACHTUNG: << " << ::classname< serializer_reg_context<context> >() 00104 << " is not specialized, which means that registration hasn't been done.\n" 00105 << "For instructions see: " << __FILE__ << "\n"; 00106 abort(); 00107 } 00108 }; 00109 template <typename Context> bool serializer_reg_context<Context>::placeholder = false; 00110 #endif 00111 // !s11n_SERIALIZER_REG_CONTEXT_DEFINED 00112 //////////////////////////////////////////////////////////////////////////////// 00113 00114 template <> 00115 struct serializer_reg_context< SERIALIZER_TYPE > 00116 { 00117 typedef SERIALIZER_TYPE context; 00118 static bool placeholder; 00119 static void reg() 00120 { 00121 #if DEBUG_REG 00122 CERR << "\nRegistering Serializer: " << SERIALIZER_NAME << "\n" 00123 << "classname() says: " << ::classname< SERIALIZER_TYPE >() << "\n" 00124 # ifdef SERIALIZER_MAGIC_COOKIE 00125 << "cookie="<< SERIALIZER_MAGIC_COOKIE << "\n" 00126 # endif 00127 # ifdef SERIALIZER_ALIAS 00128 << "alias="<< SERIALIZER_ALIAS << "\n" 00129 # endif 00130 ; // CERR 00131 #endif // DEBUG_REG 00132 00133 #ifdef SERIALIZER_ABSTRACT 00134 cllite::register_abstract_base< SERIALIZER_BASE >( ::classname< context >() ); 00135 # undef SERIALIZER_ABSTRACT 00136 #else 00137 cllite::register_factory< SERIALIZER_BASE, SERIALIZER_TYPE >( ::classname< context >() ); 00138 cllite::register_factory< SERIALIZER_TYPE, SERIALIZER_TYPE >( ::classname< context >() ); 00139 #endif 00140 #ifdef SERIALIZER_MAGIC_COOKIE 00141 cllite::alias< SERIALIZER_BASE >( SERIALIZER_MAGIC_COOKIE, ::classname< context >() ); 00142 cllite::alias< SERIALIZER_TYPE >( SERIALIZER_MAGIC_COOKIE, ::classname< context >() ); 00143 # undef SERIALIZER_MAGIC_COOKIE 00144 #endif 00145 #ifdef SERIALIZER_ALIAS 00146 cllite::alias< SERIALIZER_BASE >( SERIALIZER_ALIAS, ::classname< context >() ); 00147 cllite::alias< SERIALIZER_TYPE >( SERIALIZER_ALIAS, ::classname< context >() ); 00148 # undef SERIALIZER_ALIAS 00149 #endif 00150 } 00151 }; 00152 00153 bool serializer_reg_context< SERIALIZER_TYPE >::placeholder = ( 00154 serializer_reg_context< SERIALIZER_TYPE >::reg() 00155 , 00156 true 00157 ); 00158 00159 } // anon namespace 00160 00161 //////////////////////////////////////////////////////////////////////////////// 00162 // end proxy code for [SERIALIZER] 00163 //////////////////////////////////////////////////////////////////////////////// 00164 #undef SERIALIZER_TYPE 00165 #undef SERIALIZER_NAME 00166 #undef DEBUG_REG 00167 00168

Generated on Tue Jul 20 10:46:48 2004 for s11n by doxygen 1.3.7