reg_s11n_traits_template2.hpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////
00002 // A supermacro to generate some partial template specializations for
00003 // s11n-proxying class templates taking two parameterized types. Works
00004 // with std::map and std::pair-like types, with the appropriate
00005 // proxies. See the various proxy files, like std/map.hpp and
00006 // std/pair.hpp, for how to use it.
00007 //
00008 // Achtung: only suitable for monomorphic or base-most template types.
00009 ////////////////////////////////////////////////////////////////////////
00010 
00011 #ifndef S11N_TEMPLATE_TYPE
00012 #error "You must define S11N_TEMPLATE_TYPE before including this file. e.g., to std::map or std::multimap."
00013 #endif
00014 
00015 #ifndef S11N_TEMPLATE_TYPE_NAME
00016 #error "You must define S11N_TEMPLATE_TYPE_NAME before including this file. e.g., to \"map\" or \"multimap\"."
00017 #endif
00018 
00019 #ifndef S11N_TEMPLATE_TYPE_PROXY
00020 #  error "You must define S11N_TEMPLATE_TYPE_PROXY before including this file. e.g., ::s11n::map::map_serializable_proxy"
00021 #endif
00022 
00023 #ifndef S11N_TEMPLATE_TYPE_DESER_PROXY
00024 #  define S11N_TEMPLATE_TYPE_DESER_PROXY S11N_TEMPLATE_TYPE_PROXY
00025 #endif
00026 
00027 ////////////////////////////////////////////////////////////////////////
00028 // The S11N_TEMPLATE_TYPENAME_Tn macros are used when one or more of
00029 // the template parameters are concrete types, as opposed to typenames.
00030 // Define any of S11N_TEMPLATE_TYPENAME_Tn to a type name, e.g.:
00031 // #  define S11N_TEMPLATE_TYPENAME_T1 unsigned int
00032 ////////////////////////////////////////////////////////////////////////
00033 
00034 #ifndef S11N_TEMPLATE_TYPENAME_T1
00035 #  define S11N_TEMPLATE_TYPENAME_T1 typename
00036 #endif
00037 
00038 #ifndef S11N_TEMPLATE_TYPENAME_T2
00039 #  define S11N_TEMPLATE_TYPENAME_T2 typename
00040 #endif
00041 
00042 
00043 #define S11N_TEMPLATE_TYPE_Q S11N_TEMPLATE_TYPE< T1, T2 >
00044 
00045 #ifndef S11N_BASE_TYPE
00046 #define S11N_BASE_TYPE S11N_TEMPLATE_TYPE_Q
00047 #endif
00048 
00049 #define S11N_TYPENAMES S11N_TEMPLATE_TYPENAME_T1 T1, \
00050     S11N_TEMPLATE_TYPENAME_T2 T2
00051 namespace s11n {
00052 
00053     /**
00054        s11n_traits<> specialization for template types taking two
00055        template parameters, like std::map and std::pair
00056        types. (Yes, std::map can take more, but it is not commonly
00057        used that way.)
00058     */
00059     template < S11N_TYPENAMES >
00060     struct S11N_EXPORT_API s11n_traits < S11N_TEMPLATE_TYPE_Q, S11N_BASE_TYPE >
00061     {
00062     typedef S11N_TEMPLATE_TYPE_Q serializable_type;
00063     typedef S11N_BASE_TYPE serializable_interface_type;
00064     typedef S11N_TEMPLATE_TYPE_PROXY serialize_functor;
00065     typedef S11N_TEMPLATE_TYPE_DESER_PROXY deserialize_functor;
00066     typedef ::s11n::default_cleanup_functor< S11N_TEMPLATE_TYPE_Q > cleanup_functor;
00067     typedef ::s11n::cl::object_factory<serializable_interface_type> factory_type;
00068     static bool cl_reg_placeholder; 
00069     static const std::string class_name( const serializable_type * )
00070     {
00071         if( cl_reg_placeholder == true ){} // just to reference it. w/o this cl reg never happens :(
00072         return S11N_TEMPLATE_TYPE_NAME;
00073     }
00074     };
00075     template < S11N_TYPENAMES >
00076     bool s11n_traits<
00077     S11N_TEMPLATE_TYPE_Q, S11N_BASE_TYPE
00078     >::cl_reg_placeholder = (
00079                  ::s11n::cl::classloader_register_base< S11N_TEMPLATE_TYPE_Q >(S11N_TEMPLATE_TYPE_NAME),
00080                  true
00081                  );
00082     
00083     
00084 } // namespace s11n
00085 
00086 
00087 #undef S11N_TEMPLATE_TYPE_Q
00088 #undef S11N_TEMPLATE_TYPE_PROXY
00089 #undef S11N_TEMPLATE_TYPE_DESER_PROXY
00090 #undef S11N_TEMPLATE_TYPE_NAME
00091 #undef S11N_TEMPLATE_TYPE
00092 #undef S11N_TEMPLATE_TYPENAME_T1
00093 #undef S11N_TEMPLATE_TYPENAME_T2
00094 #undef S11N_BASE_TYPE
00095 #undef S11N_TYPENAMES

Generated on Sat Mar 20 12:29:24 2010 for libs11n-1.2.10 by  doxygen 1.6.1