Index: boost/serialization/export.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/serialization/export.hpp,v retrieving revision 1.40 diff -u -r1.40 export.hpp --- boost/serialization/export.hpp 16 Dec 2006 05:53:26 -0000 1.40 +++ boost/serialization/export.hpp 23 Mar 2007 14:41:56 -0000 @@ -88,6 +88,26 @@ BOOST_DLLEXPORT guid_initializer(const char *key = 0) BOOST_USED ; }; +template +struct alias_initializer +{ + typedef typename + boost::serialization::type_info_implementation::type eti_type; + + static void alias_register(const char *alias) + { + eti_type::alias_register(alias); + } + + static const alias_initializer& get_instance(char const* alias) + { + static alias_initializer const instance(alias); + return instance; + } + + BOOST_DLLEXPORT alias_initializer(const char *alias = 0) BOOST_USED ; +}; + template BOOST_DLLEXPORT guid_initializer::guid_initializer(const char *key) @@ -101,6 +121,13 @@ instantiate_ptr_serialization((T*)0, 0); } +template +BOOST_DLLEXPORT alias_initializer::alias_initializer(const char *alias) +{ + if(0 != alias) + alias_register(alias); +} + // On many platforms, naming a specialization of this template is // enough to cause its argument to be instantiated. template @@ -161,6 +188,14 @@ = ::boost::archive::detail::guid_initializer< T >::get_instance(K); \ } +#define BOOST_CLASS_EXPORT_ALIAS(T, K) \ +namespace \ +{ \ + ::boost::archive::detail::alias_initializer< T > const& \ + BOOST_PP_CAT(boost_serialization_alias_initializer_, __LINE__) \ + = ::boost::archive::detail::alias_initializer< T >::get_instance(K); \ +} + #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205)) // CodeWarrior fails to construct static members of class templates Index: boost/serialization/extended_type_info.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/serialization/extended_type_info.hpp,v retrieving revision 1.9 diff -u -r1.9 extended_type_info.hpp --- boost/serialization/extended_type_info.hpp 11 Dec 2005 06:14:36 -0000 1.9 +++ boost/serialization/extended_type_info.hpp 23 Mar 2007 14:41:56 -0000 @@ -45,10 +45,12 @@ // so that different derivations of this class can be simultaneously // included in implementation of sets and maps. const char * m_type_info_key; - // flag to indicate wheter its been registered by type; + // flag to indicate whether it's been registered by type; bool m_self_registered; - // flag to indicate wheter its been registered by type; + // flag to indicate whether it's been registered by type; bool m_key_registered; + // flag to indicate whether it's been registered by type; + bool m_alias_registered; // flag indicating that no virtual function should be called here // this is necessary since it seems that at least one compiler (borland // and one version of gcc call less_than above when erasing even @@ -65,6 +67,7 @@ public: void self_register(); void key_register(const char *key); + void alias_register(const char *key); bool is_destructing() const { return m_is_destructing; } Index: boost/serialization/extended_type_info_no_rtti.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/serialization/extended_type_info_no_rtti.hpp,v retrieving revision 1.8 diff -u -r1.8 extended_type_info_no_rtti.hpp --- boost/serialization/extended_type_info_no_rtti.hpp 4 Feb 2006 21:16:08 -0000 1.8 +++ boost/serialization/extended_type_info_no_rtti.hpp 23 Mar 2007 14:41:56 -0000 @@ -91,6 +91,12 @@ eti->key_register(key); // initialize key and add to table eti->self_register(); // add type to type table } + static void + alias_register(const char * alias){ + boost::serialization::extended_type_info * eti; + eti = get_instance(); + eti->alias_register(alias); // initialize alias and add to table + } }; } // namespace detail Index: boost/serialization/extended_type_info_typeid.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/serialization/extended_type_info_typeid.hpp,v retrieving revision 1.9 diff -u -r1.9 extended_type_info_typeid.hpp --- boost/serialization/extended_type_info_typeid.hpp 12 Feb 2006 05:52:03 -0000 1.9 +++ boost/serialization/extended_type_info_typeid.hpp 23 Mar 2007 14:41:56 -0000 @@ -100,6 +100,10 @@ export_register(const char * key){ get_instance()->key_register(key); } + static void + alias_register(const char * alias){ + get_instance()->alias_register(alias); + } }; } // namespace detail Index: libs/serialization/src/extended_type_info.cpp =================================================================== RCS file: /cvsroot/boost/boost/libs/serialization/src/extended_type_info.cpp,v retrieving revision 1.12 diff -u -r1.12 extended_type_info.cpp --- libs/serialization/src/extended_type_info.cpp 4 Oct 2006 05:38:29 -0000 1.12 +++ libs/serialization/src/extended_type_info.cpp 23 Mar 2007 14:42:20 -0000 @@ -13,6 +13,7 @@ #endif #include +#include #include #include @@ -91,7 +92,7 @@ // note: the following can't be used as this function // is called from a destructor of extended_type_info. // This will generate an error on some machines - which - // makes sense be cause by this time the derived class data + // makes sense because by this time the derived class data // might be gone. Leave this in as a reminder not to do this #if 0 tkmap::type::iterator it; @@ -119,19 +120,19 @@ struct key_compare { bool - operator()(const extended_type_info * lhs, const extended_type_info * rhs) const + operator()(const char * lhs, const char * rhs) const { // shortcut to exploit string pooling - if(lhs->get_key() == rhs->get_key()) + if(lhs == rhs) return false; - if(NULL == lhs->get_key()) + if(NULL == lhs) return true; - if(NULL == rhs->get_key()) + if(NULL == rhs) return false; - return std::strcmp(lhs->get_key(), rhs->get_key()) < 0; + return std::strcmp(lhs, rhs) < 0; } }; - typedef std::multiset type; + typedef std::map type; //typedef std::set type; type m_map; static ktmap * m_self; @@ -153,8 +154,7 @@ }; static ktmap::type::iterator lookup(const char *key){ - extended_type_info_arg arg(key); - return m_self->m_map.find(&arg); + return m_self->m_map.find(key); } public: @@ -162,26 +162,25 @@ m_self = NULL; } static void - insert(const extended_type_info * eti){ + insert(const char * key, const extended_type_info * eti){ if(NULL == m_self){ static ktmap instance; m_self = & instance; } // make sure that all GUIDs are unique - assert(lookup(eti->get_key()) == m_self->m_map.end()); - m_self->m_map.insert(eti); + assert(lookup(key) == m_self->m_map.end()); + m_self->m_map.insert(std::make_pair(key, eti)); } static const extended_type_info * find(const char *key) { if(NULL == m_self) return NULL; - extended_type_info_arg arg(key); ktmap::type::const_iterator it; - it = m_self->m_map.find(&arg); + it = m_self->m_map.find(key); if(it == m_self->m_map.end()) return NULL; - return *it; + return it->second; } static void purge(const extended_type_info * eti){ @@ -190,7 +189,7 @@ // note: the following can't be used as this function // is called from a destructor of extended_type_info. // This will generate an error on some machines - which - // makes sense be cause by this time the derived class data + // makes sense because by this time the derived class data // might be gone. Leave this in as a reminder not to do this #if 0 ktmap::type::iterator it; @@ -205,7 +204,7 @@ while(i != k){ // note that the erase might invalidate i so save it here ktmap::type::iterator j = i++; - if(*j == eti) + if(j->second == eti) m_self->m_map.erase(j); } } @@ -233,10 +232,18 @@ if(NULL == key_) return; m_key = key_; - detail::ktmap::insert(this); + detail::ktmap::insert(key_, this); m_key_registered = true; } +BOOST_SERIALIZATION_DECL(void) +extended_type_info::alias_register(const char *alias) { + if(NULL == alias) + return; + detail::ktmap::insert(alias, this); + m_alias_registered = true; +} + BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) extended_type_info::extended_type_info( const char * type_info_key @@ -244,6 +251,7 @@ m_type_info_key(type_info_key), m_self_registered(false), m_key_registered(false), + m_alias_registered(false), m_is_destructing(false) {} @@ -254,7 +262,7 @@ BOOST_TRY{ if(m_self_registered) detail::tkmap::purge(this); - if(m_key_registered) + if(m_key_registered || m_alias_registered) detail::ktmap::purge(this); unregister_void_casts(this); }