00001 //////////////////////////////////////////////////////////////////////// 00002 // reg_s11n_traits.hpp 00003 // 00004 // Supermacro for registering s11n proxies for the s11n API, using 00005 // the s11n_traits<> technique introduced in 0.9.3. 00006 // 00007 // C macros used/expected by this file: 00008 // 00009 // S11N_TYPE: type to be registered 00010 // 00011 // S11N_TYPE_NAME: stringified name of S11N_TYPE 00012 // 00013 // S11N_BASE_TYPE: if S11N_TYPE subclasses a regisitered S11N_TYPE, 00014 // pass it here. If this is set then the rest of the following 00015 // variables need not be set, as they are instead inherited from 00016 // the S11N_BASE_TYPE's registration info. 00017 // 00018 // S11N_SERIALIZE_FUNCTOR: functor type responsible for handling calls 00019 // to serialize<S11N_TYPE>(). Default is 00020 // s11n::default_serialize_functor, which simply calls 00021 // S11N_TYPE::operator()( NodeT & ). 00022 // 00023 // S11N_DESERIALIZE_FUNCTOR: functor type responsible for handling calls 00024 // to serialize(). Defaults to S11N_SERIALIZE_FUNCTOR. In practice 00025 // this never needs to be explicitely set. 00026 // 00027 // S11N_FACTORY_TYPE: functor which is responsible for instantiating 00028 // objects of type S11N_TYPE. Default behaviour is to use 00029 // s11n::cl::object_factory< S11N_BASE_TYPE >, which is fine for the 00030 // majority of cases. 00031 // 00032 // THINGS TO KNOW: 00033 // 00034 // - If the default factory type is NOT used, the caller is 00035 // responsible for registering S11N_TYPE with the appropriate factory, 00036 // using the key S11N_TYPE_NAME. 00037 // 00038 //////////////////////////////////////////////////////////////////////// 00039 // The s11n header files are expected to have been included by the 00040 // time this file is ever included. 00041 // 00042 // 00043 // Sample usage: 00044 // 00045 // #define S11N_TYPE MyBaseType 00046 // #define S11N_TYPE_NAME "MyBaseType" 00047 // #include [this file] 00048 // 00049 // repeat for each type. For subtypes of MyBaseType, do: 00050 // 00051 // #define S11N_TYPE MySubType 00052 // #define S11N_TYPE_NAME "MySubType" 00053 // #define S11N_BASE_TYPE MyBaseType 00054 // #include [this file] 00055 // 00056 // Always use MyBaseType as the S11N_BASE_TYPE, no matter 00057 // now far-inherented MySubType is from MyBaseType. 00058 // 00059 // If S11N_BASE_TYPE is not set then the following macros 00060 // are also used, otherwise they are ignored, inherited from 00061 // the base implementation: 00062 // 00063 // #define S11N_SERIALIZE_FUNCTOR some_serializer_functor 00064 // #define S11N_DESERIALIZE_FUNCTOR some_deserializer_functor 00065 // #define S11N_CLEANUP_FUNCTOR some_cleanup_functor 00066 // 00067 // If S11N_DESERIALIZE_FUNCTOR is defined, that is used as the 00068 // Deserialization proxy, otherwise S11N_SERIALIZE_FUNCTOR functor is 00069 // used for both cases.// If neither are set then 00070 // ::s11n::default_serialize_functor is installed, and S11N_TYPE must 00071 // conform to that proxy's expectations. 00072 // 00073 // The cleanup functor must conform to s11n_traits::cleanup_functor 00074 // conventions. The default is to use 00075 // s11n::default_cleanup_functor<S11N_BASE_TYPE>. 00076 // 00077 // After each include all of these macros are unset so that they may 00078 // be immediately re-used for another registration. 00079 //////////////////////////////////////////////////////////////////////// 00080 00081 00082 #ifndef S11N_TYPE 00083 # error "S11N_TYPE must be set before including this file." 00084 #endif 00085 00086 #ifndef S11N_TYPE_NAME 00087 # ifdef S11N_NAME // older convention 00088 # define S11N_TYPE_NAME S11N_NAME 00089 # undef S11N_NAME 00090 # else 00091 # error "S11N_TYPE_NAME must be set before including this file. Set it to the stringified form of S11N_TYPE." 00092 # endif 00093 #endif 00094 00095 00096 // S11N_BASE_TYPE only needs to be set when registering subtypes of an 00097 // already-registered base type... 00098 #ifdef S11N_BASE_TYPE 00099 # define S11N_INHERIT 1 00100 #else 00101 # define S11N_BASE_TYPE S11N_TYPE 00102 # define S11N_INHERIT 0 00103 # ifndef S11N_SERIALIZE_FUNCTOR 00104 # define S11N_SERIALIZE_FUNCTOR ::s11n::default_serialize_functor 00105 # endif 00106 # ifndef S11N_DESERIALIZE_FUNCTOR 00107 # define S11N_DESERIALIZE_FUNCTOR S11N_SERIALIZE_FUNCTOR 00108 # endif 00109 # ifndef S11N_CLEANUP_FUNCTOR 00110 # define S11N_CLEANUP_FUNCTOR ::s11n::default_cleanup_functor< S11N_BASE_TYPE > 00111 # endif 00112 #endif // S11N_BASE_TYPE 00113 00114 00115 #ifndef S11N_FACTORY_TYPE 00116 // then register a factory of our own... 00117 # define S11N_REG_DEFAULTFAC 1 00118 # define S11N_FACTORY_TYPE ::s11n::cl::object_factory< S11N_BASE_TYPE > 00119 #else 00120 // assume the user knows what he's doing... 00121 # define S11N_REG_DEFAULTFAC 0 00122 #endif // S11N_FACTORY_TYPE 00123 00124 //////////////////////////////////////////////////////////////////////// 00125 // Set up s11n_traits<> specialization... 00126 namespace s11n { 00127 00128 template <> 00129 struct s11n_traits < S11N_TYPE > 00130 #if S11N_INHERIT 00131 : public s11n_traits < S11N_BASE_TYPE > 00132 #endif 00133 { 00134 #if ! S11N_INHERIT 00135 typedef S11N_TYPE serializable_type; 00136 typedef S11N_SERIALIZE_FUNCTOR serialize_functor; 00137 typedef S11N_DESERIALIZE_FUNCTOR deserialize_functor; 00138 typedef S11N_FACTORY_TYPE factory_type; 00139 typedef S11N_CLEANUP_FUNCTOR cleanup_functor; 00140 #endif // ! S11N_INHERIT 00141 static const std::string class_name( const serializable_type * instance_hint ) 00142 { 00143 return S11N_TYPE_NAME; 00144 } 00145 00146 }; 00147 00148 } // namespace s11n 00149 // end s11n_traits<> 00150 //////////////////////////////////////////////////////////////////////// 00151 00152 00153 //////////////////////////////////////////////////////////////////////// 00154 // We don't actually need to install a factory registration for abstract 00155 // types, but we do because there is a very subtle difference between 00156 // registering and not registering one: 00157 // the factory layer might do a DLL lookup for our abstract type if it 00158 // doesn't have a factory, but won't do so if it finds a factory but 00159 // the factory returns 0. 00160 #if S11N_REG_DEFAULTFAC 00161 # define S11N_FACREG_TYPE S11N_TYPE 00162 # define S11N_FACREG_TYPE_NAME S11N_TYPE_NAME 00163 # define S11N_FACREG_INTERFACE_TYPE S11N_BASE_TYPE 00164 # ifdef S11N_ABSTRACT_BASE 00165 # define S11N_FACREG_TYPE_IS_ABSTRACT 1 00166 # endif 00167 # include <s11n.net/s11n/factory_reg.hpp> 00168 #endif // S11N_REG_DEFAULTFAC 00169 //////////////////////////////////////////////////////////////////////// 00170 00171 00172 //////////////////////////////////////////////////////////////////////// 00173 // clean up for the next #include ... 00174 #undef S11N_TYPE 00175 #undef S11N_TYPE_NAME 00176 #undef S11N_BASE_TYPE 00177 #undef S11N_SERIALIZE_FUNCTOR 00178 #undef S11N_DESERIALIZE_FUNCTOR 00179 #undef S11N_FACTORY_TYPE 00180 #undef S11N_INHERIT 00181 #undef S11N_REG_DEFAULTFAC 00182 #undef S11N_CLEANUP_FUNCTOR 00183 #ifdef S11N_ABSTRACT_BASE 00184 # undef S11N_ABSTRACT_BASE 00185 #endif