00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #define DEBUG_REG 0
00054 #if DEBUG_REG
00055 # include <s11n/debuggering_macros.h>
00056 #endif
00057
00058
00059 #ifndef S11N_TYPE
00060 # error "S11N_TYPE is not set. Set it to the type you want to proxy before including this file!"
00061 #endif
00062
00063 #ifndef S11N_NAME
00064 # error "S11N_NAME must be set to the string form of S11N_TYPE"
00065 #endif
00066
00067
00068 #ifndef S11N_BASE_TYPE
00069 # define S11N_BASE_TYPE S11N_TYPE
00070
00071
00072 #endif
00073
00074
00075 #ifndef S11N_SERIALIZE_FUNCTION
00076 # define S11N_SERIALIZE_FUNCTION operator()
00077 #endif
00078
00079 #ifndef S11N_DESERIALIZE_FUNCTION
00080 # define S11N_DESERIALIZE_FUNCTION operator()
00081 #endif
00082
00083
00084
00085 #define NAME_TYPE S11N_TYPE
00086 #define TYPE_NAME S11N_NAME
00087 #include <s11n/name_type.h>
00088
00089
00090
00091 namespace {
00092
00093
00094
00095 #ifndef s11n_SERIALIZER_REG_CONTEXT_DEFINED
00096 #define s11n_SERIALIZER_REG_CONTEXT_DEFINED 1
00097
00098
00099
00100
00101
00102
00103
00104 template <typename Context>
00105 struct serializer_reg_context
00106 {
00107 typedef Context context;
00108 static bool placeholder;
00109 static void reg()
00110 {
00111 CERR << "ACHTUNG: " << ::classname< serializer_reg_context<context> >()
00112 << " is not specialized, which means that registration hasn't been done.\n"
00113 << "For instructions see: " << __FILE__ << "\n";
00114 abort();
00115 }
00116
00117 };
00118 template <typename Context> bool serializer_reg_context<Context>::placeholder = false;
00119 #endif // !s11n_SERIALIZER_REG_CONTEXT_DEFINED
00120
00121 template <>
00122 struct serializer_reg_context< S11N_TYPE >
00123 {
00124 typedef S11N_TYPE context;
00125 static bool placeholder;
00126 static void reg()
00127 {
00128 #if DEBUG_REG
00129 CERR << "\nRegistering Serializable: " << S11N_NAME << "\n"
00130 << "::classname<>() says: " << ::classname< S11N_TYPE >() << "\n"
00131 ;
00132 #endif // DEBUG_REG
00133
00134 #ifdef S11N_ABSTRACT_BASE
00135 cllite::register_abstract_base< S11N_BASE_TYPE >( ::classname< context >() );
00136 # undef S11N_ABSTRACT_BASE
00137 #else
00138 cllite::register_factory< S11N_BASE_TYPE, S11N_TYPE >( ::classname< context >() );
00139 cllite::register_factory< S11N_TYPE, S11N_TYPE >( ::classname< context >() );
00140 #endif
00141 }
00142 };
00143
00144 bool serializer_reg_context< S11N_TYPE >::placeholder = (
00145 serializer_reg_context< S11N_TYPE >::reg()
00146 ,
00147 true
00148 );
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 template <> struct s11n_api_marshaler< S11N_TYPE >
00167 {
00168 typedef S11N_TYPE serializable_type;
00169 template <typename NodeType>
00170 static bool serialize( NodeType &dest, const serializable_type & src )
00171 {
00172 dest.impl_class( ::classname< S11N_TYPE >() );
00173
00174 return src.S11N_SERIALIZE_FUNCTION( dest );
00175 }
00176
00177 template <typename NodeType>
00178 static bool deserialize( const NodeType & src, serializable_type & dest )
00179 {
00180 return dest.S11N_DESERIALIZE_FUNCTION( src );
00181 }
00182
00183 };
00184
00185 }
00186
00187
00188
00189
00190 #undef S11N_TYPE
00191 #undef S11N_BASE_TYPE
00192 #undef S11N_NAME
00193 #undef S11N_SERIALIZE_FUNCTION
00194 #undef S11N_DESERIALIZE_FUNCTION
00195 #undef DEBUG_REG
00196