00001 // don't use this yet. i'm not quite sure what the hell it's really for. 00002 //////////////////////////////////////////////////////////////////////// 00003 // Boilerplate code for doing some registration stuff for 00004 // non-Serializables 00005 00006 // It is compatible with ALL types. 00007 00008 // License: Public Domain 00009 // Author: stephan@s11n.net 00010 //////////////////////////////////////////////////////////////////////// 00011 00012 //////////////////////////////////////////////////////////////////////// 00013 // NOTE: this file does not use a conventional BLAH_H_INCLUDED guard. 00014 // Yes, that's on purpose. 00015 //////////////////////////////////////////////////////////////////////// 00016 // Boilerplate code for a 00017 // proxies. 00018 // 00019 // 00020 // The s11n header files are expected to have been included by the 00021 // time this file is ever included. 00022 // 00023 // 00024 // Sample usage: 00025 // 00026 // #define NONS11N_TYPE std::map<Foo,Bar> 00027 // #define NONS11N_NAME "std::map<Foo,Bar>" 00028 // #include [this file] 00029 // 00030 // // repeat for each type: 00031 // #define NONS11N_TYPE std::map<Foo *,Bar *> 00032 // #define NONS11N_NAME "std::map<Foo*,Bar*>" 00033 // #include [this file] 00034 // 00035 // If NONS11N_TYPE is a subtype of another Serializable, 00036 // and should be available via that base-type's classloader 00037 // (Yes, you normally WANT this) then define this macro: 00038 // 00039 // NONS11N_BASE_TYPE 00040 // 00041 // to the type name of NONS11N_TYPE's BaseType base type. 00042 // 00043 // Not setting NONS11N_BASE_TYPE is functionaly identical 00044 // to setting it to NONS11N_TYPE. 00045 // 00046 // After each include all of these macros are unset so that they may 00047 // be immediately re-used for another registration. 00048 //////////////////////////////////////////////////////////////////////// 00049 00050 00051 #ifndef NONS11N_TYPE 00052 # error "NONS11N_TYPE is not set. Set it to the type you want to proxy before including this file!" 00053 #endif 00054 00055 #ifndef NONS11N_NAME 00056 # error "NONS11N_NAME must be set to the string form of NONS11N_TYPE" 00057 #endif 00058 00059 #ifndef NONS11N_BASE 00060 # define NONS11N_BASE NONS11N_TYPE 00061 #endif 00062 00063 //////////////////////////////////////////////////////////////////////// 00064 // set up the type name registry 00065 #define NAME_TYPE S11N_TYPE 00066 #define TYPE_NAME S11N_NAME 00067 #include <s11n/name_type.h> 00068 //////////////////////////////////////////////////////////////////////// 00069 00070 namespace { // anonymous namespace is important for complex linking reasons. 00071 00072 #ifndef s11n_NONS11N_REG_CONTEXT_DEFINED 00073 #define s11n_NONS11N_REG_CONTEXT_DEFINED 1 00074 /////////////////////////////////////////////////////////////// 00075 // we must not include this more than once per compilation unit 00076 /////////////////////////////////////////////////////////////// 00077 // A unique (per Context/per compilation unit) space to assign 00078 // a bogus value for classloader registration purposes (see 00079 // the classloader docs for a full description of how this 00080 // works). 00081 template <typename Context > 00082 struct nons11n_reg_context 00083 { 00084 static bool placeholder; 00085 }; 00086 template <typename Context > bool nons11n_reg_context< Context >::placeholder = false; 00087 // must be set by specializations^^^ 00088 #endif 00089 // !s11n_NONS11N_REG_CONTEXT_DEFINED 00090 //////////////////////////////////////////////////////////////////////////////// 00091 00092 //////////////////////////////////////////////////////////////////////// 00093 // Register a factory with the classloader (this could be done any 00094 // number of ways, actually): 00095 bool nons11n_reg_context< NONS11N_TYPE >::placeholder= 00096 #ifdef NONS11N_ABSTRACT 00097 (cllite::register_abstract_base< 00098 NONS11N_BASE 00099 #else 00100 (cllite::register_factory< 00101 NONS11N_BASE , 00102 NONS11N_TYPE 00103 #endif 00104 >( ::classname< NONS11N_TYPE >() ) 00105 ,true); 00106 00107 } // anon namespace 00108 00109 //////////////////////////////////////////////////////////////////////////////// 00110 // end proxy code for [NONS11N_TYPE] 00111 //////////////////////////////////////////////////////////////////////////////// 00112 #undef NONS11N_TYPE 00113 #undef NONS11N_NAME 00114 #undef NONS11N_BASE 00115 #ifdef NONS11N_ABSTRACT 00116 # undef NONS11N_ABSTRACT 00117 #endif