reg_map_specializations.hpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////
00002 // A supermacro to generate some partial template specializations for
00003 // map-type classes. See std/map.hpp for how to use it.
00004 ////////////////////////////////////////////////////////////////////////
00005 
00006 #ifndef S11N_MAP_TYPE
00007 #error "You must define S11N_MAP_TYPE before including this file. e.g., to std::map or std::multimap."
00008 #endif
00009 
00010 #ifndef S11N_MAP_TYPE_NAME
00011 #error "You must define S11N_MAP_TYPE_NAME before including this file. e.g., to \"map\" or \"multimap\"."
00012 #endif
00013 
00014 #ifndef S11N_MAP_TYPE_PROXY
00015 #define S11N_MAP_TYPE_PROXY ::s11n::map::serialize_map_f
00016 // ::s11n::map::map_serializable_proxy
00017 #endif
00018 
00019 #ifndef S11N_MAP_TYPE_DESER_PROXY
00020 #  define S11N_MAP_TYPE_DESER_PROXY ::s11n::map::deserialize_map_f
00021 #endif
00022 
00023 #include <s11n.net/s11n/s11n_debuggering_macros.hpp> // tracing commands
00024 
00025 namespace s11n {
00026 
00027     /**
00028        Specialization for std::map-compliant types.
00029 
00030     */
00031     template <typename T1, typename T2>
00032     struct S11N_EXPORT_API default_cleanup_functor< S11N_MAP_TYPE<T1,T2> >
00033     {
00034         typedef S11N_MAP_TYPE<T1,T2> serializable_type;
00035 
00036         /**
00037            ACHTUNG: it can only deallocate the .second member
00038            of each mapped pair, because the first is const.
00039            Since it would be very unusual to serialize a map
00040            keyed on unmanaged pointers, this is not seen as a
00041            major problem.
00042 
00043            After this call, p is empty.
00044         */
00045         void operator()( serializable_type & p ) const throw()
00046         {
00047             using namespace ::s11n::debug;
00048             S11N_TRACE(TRACE_CLEANUP) << "default_cleanup_functor<> specialization cleaning up map<>...\n";
00049 
00050             // reminder: pair type has a const .first member. If it weren't
00051             // for that pesky const, we could do this all in a simple
00052             // for_each() call.
00053 
00054             typedef typename serializable_type::mapped_type MT;
00055             typedef typename ::s11n::type_traits<MT>::type mapped_type; // strip pointer part
00056             typedef typename serializable_type::iterator MIT;
00057             MIT b = p.begin();
00058             MIT e = p.end();
00059             for( ; e != b; ++b )
00060             {
00061                 ::s11n::cleanup_serializable<mapped_type>( (*b).second );
00062             }
00063             p.clear();
00064         }
00065     };
00066 }
00067 
00068 #define S11N_TEMPLATE_TYPE S11N_MAP_TYPE
00069 #define S11N_TEMPLATE_TYPE_NAME S11N_MAP_TYPE_NAME
00070 #define S11N_TEMPLATE_TYPE_PROXY S11N_MAP_TYPE_PROXY
00071 #define S11N_TEMPLATE_TYPE_DESER_PROXY S11N_MAP_TYPE_DESER_PROXY
00072 #include <s11n.net/s11n/proxy/reg_s11n_traits_template2.hpp>
00073 #undef S11N_MAP_TYPE_DESER_PROXY
00074 #undef S11N_MAP_TYPE_PROXY
00075 #undef S11N_MAP_TYPE_NAME
00076 #undef S11N_MAP_TYPE

Generated on Sun Apr 27 11:46:49 2008 for libs11n-1.2.6 by  doxygen 1.5.3