Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55324 - trunk/libs/serialization/src
From: ramey_at_[hidden]
Date: 2009-07-31 17:02:49


Author: ramey
Date: 2009-07-31 17:02:48 EDT (Fri, 31 Jul 2009)
New Revision: 55324
URL: http://svn.boost.org/trac/boost/changeset/55324

Log:
Fix test_no_rtti test
extended_type_info system not based on type_id
Text files modified:
   trunk/libs/serialization/src/basic_serializer_map.cpp | 59 +++++++++++++++++++++------------------
   trunk/libs/serialization/src/extended_type_info.cpp | 13 ++++----
   trunk/libs/serialization/src/extended_type_info_no_rtti.cpp | 23 +++++++++++++--
   trunk/libs/serialization/src/extended_type_info_typeid.cpp | 13 ++++----
   4 files changed, 64 insertions(+), 44 deletions(-)

Modified: trunk/libs/serialization/src/basic_serializer_map.cpp
==============================================================================
--- trunk/libs/serialization/src/basic_serializer_map.cpp (original)
+++ trunk/libs/serialization/src/basic_serializer_map.cpp 2009-07-31 17:02:48 EDT (Fri, 31 Jul 2009)
@@ -12,8 +12,6 @@
 # pragma warning (disable : 4786) // too long name, harmless warning
 #endif
 
-#include <set>
-
 #define BOOST_ARCHIVE_SOURCE
 #include <boost/archive/detail/basic_serializer.hpp>
 #include <boost/archive/detail/basic_serializer_map.hpp>
@@ -25,45 +23,52 @@
 namespace archive {
 namespace detail {
 
-bool
-basic_serializer_map::type_info_pointer_compare::operator()(
- const basic_serializer * lhs, const basic_serializer * rhs
-) const {
- return *lhs < *rhs;
-}
+// note: We can't implement this as an associative
+// container as such a container might be dependent
+// upon the extended_type_info::m_key which might not
+// be assigned until later. So we use a "slower" method.
+// This not a big deal however as the slower "find" operations
+// operations are only called occasionally:
+// a) At module unloading
+// b) Once per input archive - the value is cached in the archive
+// implemenation.
 
-BOOST_ARCHIVE_DECL(bool)
+BOOST_ARCHIVE_DECL(void)
 basic_serializer_map::insert(const basic_serializer * bs){
- return m_map.insert(bs).second;
+ m_map.push_back(bs);
 }
 
 BOOST_ARCHIVE_DECL(void)
 basic_serializer_map::erase(const basic_serializer * bs){
     map_type::iterator it = m_map.begin();
     map_type::iterator it_end = m_map.end();
-
- while(it != it_end){
- // note item 9 from Effective STL !!! it++
- if(*it == bs)
- m_map.erase(it++);
- else
- it++;
+ it = std::find(it, it_end, bs);
+ if(it != it_end){
+ m_map.erase(it);
     }
- // note: we can't do this since some of the eti records
- // we're pointing to might be expired and the comparison
- // won't work. Leave this as a reminder not to "optimize" this.
- //it = m_map.find(bs);
- //assert(it != m_map.end());
- //if(*it == bs)
- // m_map.erase(it);
+ else
+ assert(false); // this should never occur
 }
+
+class equals {
+ const boost::serialization::extended_type_info * m_eti;
+public:
+ bool operator()(const basic_serializer * bs) const {
+ return *m_eti == bs->get_eti();
+ }
+ equals(const boost::serialization::extended_type_info * eti) :
+ m_eti(eti)
+ {}
+};
+
+// find the "oldest" matching pointer serializer
 BOOST_ARCHIVE_DECL(const basic_serializer *)
 basic_serializer_map::find(
     const boost::serialization::extended_type_info & eti
 ) const {
- const basic_serializer_arg bs(eti);
- map_type::const_iterator it;
- it = m_map.find(& bs);
+ map_type::const_iterator it = m_map.begin();
+ map_type::const_iterator it_end = m_map.end();
+ it = std::find_if(it, it_end, equals(& eti));
     assert(it != m_map.end());
     return *it;
 }

Modified: trunk/libs/serialization/src/extended_type_info.cpp
==============================================================================
--- trunk/libs/serialization/src/extended_type_info.cpp (original)
+++ trunk/libs/serialization/src/extended_type_info.cpp 2009-07-31 17:02:48 EDT (Fri, 31 Jul 2009)
@@ -43,6 +43,9 @@
         const extended_type_info * lhs,
         const extended_type_info * rhs
     ) const {
+ // performance shortcut
+ if(lhs == rhs)
+ return false;
         const char * l = lhs->get_key();
         assert(NULL != l);
         const char * r = rhs->get_key();
@@ -72,13 +75,6 @@
         assert(false);
         return false;
     };
- virtual bool &
- get_is_destroyed() const {
- static bool dummy = true;
- assert(false);
- return dummy;
- }
-
 public:
     extended_type_info_arg(const char * key) :
         extended_type_info()
@@ -156,6 +152,9 @@
 
 BOOST_SERIALIZATION_DECL(bool)
 extended_type_info::operator<(const extended_type_info &rhs) const {
+ // short cut for a common cases
+ if(this == & rhs)
+ return false;
     if(m_type_info_key == rhs.m_type_info_key){
         return is_less_than(rhs);
     }

Modified: trunk/libs/serialization/src/extended_type_info_no_rtti.cpp
==============================================================================
--- trunk/libs/serialization/src/extended_type_info_no_rtti.cpp (original)
+++ trunk/libs/serialization/src/extended_type_info_no_rtti.cpp 2009-07-31 17:02:48 EDT (Fri, 31 Jul 2009)
@@ -11,6 +11,7 @@
 
 #include <cstring>
 #include <cstddef> // NULL
+#include <cassert>
 
 #include <boost/config.hpp>
 #if defined(BOOST_NO_STDC_NAMESPACE)
@@ -35,8 +36,20 @@
 extended_type_info_no_rtti_0::is_less_than(
     const boost::serialization::extended_type_info &rhs) const
 {
+ // shortcut for common case
+ if(this == & rhs)
+ return false;
     const char * l = m_key;
     const char * r = rhs.get_key();
+ // if this assertion is triggered, it could mean one of the following
+ // a) This class was never exported - make sure all calls which use
+ // this method of type id are in fact exported.
+ // b) This class was used (e.g. serialized through a pointer) before
+ // it was exported. Make sure that classes which use this method
+ // of type id are NOT "automatically" registered by serializating
+ // through a pointer to the to most derived class. OR make sure
+ // that the BOOST_CLASS_EXPORT is included in every file
+ // which does this.
     assert(NULL != l);
     assert(NULL != r);
     return std::strcmp(l, r) < 0;
@@ -46,14 +59,18 @@
 extended_type_info_no_rtti_0::is_equal(
     const boost::serialization::extended_type_info &rhs) const
 {
- const char * l = m_key;
- const char * r = rhs.get_key();
- if(l == r)
+ // shortcut for common case
+ if(this == & rhs)
         return true;
+ // null keys don't match with anything
+ const char * l = m_key;
+ //assert(NULL != l);
     if(NULL == l)
         return false;
+ const char * r = rhs.get_key();
     if(NULL == r)
         return false;
+ assert(NULL != r);
     return 0 == std::strcmp(l, r);
 }
 

Modified: trunk/libs/serialization/src/extended_type_info_typeid.cpp
==============================================================================
--- trunk/libs/serialization/src/extended_type_info_typeid.cpp (original)
+++ trunk/libs/serialization/src/extended_type_info_typeid.cpp 2009-07-31 17:02:48 EDT (Fri, 31 Jul 2009)
@@ -48,6 +48,9 @@
 extended_type_info_typeid_0::is_less_than(
     const boost::serialization::extended_type_info & rhs
 ) const {
+ // shortcut for common case
+ if(this == & rhs)
+ return false;
     return static_cast<bool>(m_ti->before(
         *(static_cast<const extended_type_info_typeid_0 &>(rhs).m_ti)
     ));
@@ -57,6 +60,9 @@
 extended_type_info_typeid_0::is_equal(
     const boost::serialization::extended_type_info & rhs
 ) const {
+ // shortcut for common case
+ if(this == & rhs)
+ return true;
     return static_cast<bool>(
         * m_ti
         == *(static_cast<const extended_type_info_typeid_0 &>(rhs).m_ti)
@@ -105,13 +111,6 @@
 class extended_type_info_typeid_arg :
     public extended_type_info_typeid_0
 {
-private:
- virtual bool &
- get_is_destroyed() const {
- static bool dummy = false;
- assert(false);
- return dummy;
- }
 public:
     extended_type_info_typeid_arg(const std::type_info & ti){
         // note absense of self register and key as this is used only as


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk