Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55789 - in trunk/boost/archive: . detail impl
From: ramey_at_[hidden]
Date: 2009-08-26 16:44:56


Author: ramey
Date: 2009-08-26 16:44:55 EDT (Wed, 26 Aug 2009)
New Revision: 55789
URL: http://svn.boost.org/trac/boost/changeset/55789

Log:
moved code from header to library to reduce code bloat
Text files modified:
   trunk/boost/archive/archive_exception.hpp | 95 +++-----------------------
   trunk/boost/archive/detail/basic_serializer_map.hpp | 4
   trunk/boost/archive/impl/basic_binary_iprimitive.ipp | 4
   trunk/boost/archive/polymorphic_iarchive.hpp | 8 +-
   trunk/boost/archive/shared_ptr_helper.hpp | 141 +++++++++++++++++++--------------------
   trunk/boost/archive/text_iarchive.hpp | 4
   trunk/boost/archive/text_wiarchive.hpp | 4
   trunk/boost/archive/xml_archive_exception.hpp | 36 +++------
   trunk/boost/archive/xml_iarchive.hpp | 4
   trunk/boost/archive/xml_wiarchive.hpp | 4
   10 files changed, 108 insertions(+), 196 deletions(-)

Modified: trunk/boost/archive/archive_exception.hpp
==============================================================================
--- trunk/boost/archive/archive_exception.hpp (original)
+++ trunk/boost/archive/archive_exception.hpp 2009-08-26 16:44:55 EDT (Wed, 26 Aug 2009)
@@ -20,13 +20,18 @@
 #include <cassert>
 #include <string>
 
+#include <boost/preprocessor/empty.hpp>
+#include <boost/archive/detail/decl.hpp>
+
+#include <boost/archive/detail/abi_prefix.hpp> // must be the last header
+
 namespace boost {
 namespace archive {
 
 //////////////////////////////////////////////////////////////////////
 // exceptions thrown by archives
 //
-class archive_exception :
+class BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) archive_exception :
     public virtual std::exception
 {
 public:
@@ -56,12 +61,10 @@
         unsupported_class_version, // type saved with a version # greater than the
                             // one used by the program. This indicates that the proggram
                             // needs to be rebuilt.
- inconsistent_pointer_serialization, // an object as been serialized
- // more than once through pointers of different types.
         multiple_code_instantiation // code for implementing serialization for some
                             // type has been instantiated in more than one module.
     } exception_code;
-private:
+protected:
     std::string m_msg;
 public:
     exception_code code;
@@ -69,88 +72,16 @@
         exception_code c,
         const char * e1 = NULL,
         const char * e2 = NULL
- ) :
- code(c)
- {
- m_msg = "programming error";
- switch(code){
- case no_exception:
- m_msg = "uninitialized exception";
- break;
- case unregistered_class:
- m_msg = "unregistered class";
- if(NULL != e1){
- m_msg += " - ";
- m_msg += e1;
- }
- break;
- case invalid_signature:
- m_msg = "invalid signature";
- break;
- case unsupported_version:
- m_msg = "unsupported version";
- break;
- case pointer_conflict:
- m_msg = "pointer conflict";
- break;
- case incompatible_native_format:
- m_msg = "incompatible native format";
- if(NULL != e1){
- m_msg += " - ";
- m_msg += e1;
- }
- break;
- case array_size_too_short:
- m_msg = "array size too short";
- break;
- case stream_error:
- m_msg = "stream error";
- break;
- case invalid_class_name:
- m_msg = "class name too long";
- break;
- case unregistered_cast:
- m_msg = "unregistered void cast ";
- m_msg += (NULL != e1) ? e1 : "?";
- m_msg += "<-";
- m_msg += (NULL != e2) ? e2 : "?";
- break;
- case unsupported_class_version:
- m_msg = "class version";
- break;
- case other_exception:
- // if get here - it indicates a derived exception
- // was sliced by passing by value in catch
- m_msg = "unknown derived exception";
- break;
- case inconsistent_pointer_serialization:
- // same object saved through different kinds of pointers
- m_msg = "inconsistent_pointer_serialization";
- break;
- case multiple_code_instantiation:
- m_msg = "code instantiated in more than one module";
- if(NULL != e1){
- m_msg += " - ";
- m_msg += e1;
- }
- break;
- default:
- assert(false);
- break;
- }
- }
- ~archive_exception() throw () {}
- virtual const char *what( ) const throw()
- {
- return m_msg.c_str();
- }
+ );
+ ~archive_exception() throw ();
+ virtual const char *what( ) const throw();
 protected:
- archive_exception() :
- code(no_exception)
- {}
+ archive_exception();
 };
 
 }// namespace archive
 }// namespace boost
 
+#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
+
 #endif //BOOST_ARCHIVE_ARCHIVE_EXCEPTION_HPP

Modified: trunk/boost/archive/detail/basic_serializer_map.hpp
==============================================================================
--- trunk/boost/archive/detail/basic_serializer_map.hpp (original)
+++ trunk/boost/archive/detail/basic_serializer_map.hpp 2009-08-26 16:44:55 EDT (Wed, 26 Aug 2009)
@@ -19,10 +19,10 @@
 #include <set>
 
 #include <boost/config.hpp>
+#include <boost/utility.hpp>
 #include <boost/archive/detail/auto_link_archive.hpp>
-#include <boost/archive/detail/abi_prefix.hpp> // must be the last header
 
-#include <boost/utility.hpp>
+#include <boost/archive/detail/abi_prefix.hpp> // must be the last header
 
 namespace boost {
 namespace serialization {

Modified: trunk/boost/archive/impl/basic_binary_iprimitive.ipp
==============================================================================
--- trunk/boost/archive/impl/basic_binary_iprimitive.ipp (original)
+++ trunk/boost/archive/impl/basic_binary_iprimitive.ipp 2009-08-26 16:44:55 EDT (Wed, 26 Aug 2009)
@@ -92,10 +92,10 @@
 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
 basic_binary_iprimitive<Archive, Elem, Tr>::load(wchar_t * ws)
 {
- std::size_t l;
+ std::size_t l; // number of wchar_t !!!
     this->This()->load(l);
     load_binary(ws, l * sizeof(wchar_t) / sizeof(char));
- ws[l / sizeof(wchar_t)] = L'\0';
+ ws[l] = L'\0';
 }
 
 template<class Archive, class Elem, class Tr>

Modified: trunk/boost/archive/polymorphic_iarchive.hpp
==============================================================================
--- trunk/boost/archive/polymorphic_iarchive.hpp (original)
+++ trunk/boost/archive/polymorphic_iarchive.hpp 2009-08-26 16:44:55 EDT (Wed, 26 Aug 2009)
@@ -18,15 +18,15 @@
 
 #include <cstddef> // std::size_t
 #include <climits> // ULONG_MAX
-#include <boost/config.hpp>
+#include <string>
 
+#include <boost/config.hpp>
 #if defined(BOOST_NO_STDC_NAMESPACE)
 namespace std{
     using ::size_t;
 } // namespace std
 #endif
 
-#include <string>
 #include <boost/cstdint.hpp>
 
 #include <boost/serialization/pfto.hpp>
@@ -166,6 +166,8 @@
 } // namespace archive
 } // namespace boost
 
+#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
+
 // note special treatment of shared_ptr. This type needs a special
 // structure associated with every archive. We created a "mix-in"
 // class to provide this functionality. Since shared_ptr holds a
@@ -189,6 +191,4 @@
 // required by export
 BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::archive::polymorphic_iarchive)
 
-#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
-
 #endif // BOOST_ARCHIVE_POLYMORPHIC_IARCHIVE_HPP

Modified: trunk/boost/archive/shared_ptr_helper.hpp
==============================================================================
--- trunk/boost/archive/shared_ptr_helper.hpp (original)
+++ trunk/boost/archive/shared_ptr_helper.hpp 2009-08-26 16:44:55 EDT (Wed, 26 Aug 2009)
@@ -24,11 +24,15 @@
 #include <boost/config.hpp>
 #include <boost/shared_ptr.hpp>
 
+#include <boost/type_traits/is_polymorphic.hpp>
 #include <boost/serialization/type_info_implementation.hpp>
 #include <boost/serialization/shared_ptr_132.hpp>
 #include <boost/serialization/throw_exception.hpp>
 
 #include <boost/archive/archive_exception.hpp>
+#include <boost/archive/detail/decl.hpp>
+
+#include <boost/archive/detail/abi_prefix.hpp> // must be the last header
 
 namespace boost_132 {
     template<class T> class shared_ptr;
@@ -44,20 +48,15 @@
             const unsigned int file_version
         );
     }
-
 namespace archive{
 namespace detail {
 
-struct null_deleter {
- void operator()(void const *) const {}
-};
-
 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
 // a common class for holding various types of shared pointers
 
 class shared_ptr_helper {
     typedef std::map<
- const void *,
+ void *,
         boost::shared_ptr<const void>
> collection_type;
     typedef collection_type::const_iterator iterator_type;
@@ -68,6 +67,10 @@
     // a "mix-in" even if shared_ptr isn't used.
     collection_type * m_pointers;
 
+ struct null_deleter {
+ void operator()(void const *) const {}
+ };
+
 #ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
 public:
 #else
@@ -91,6 +94,36 @@
     std::list<boost_132::shared_ptr<void> > * m_pointers_132;
 // #endif
 
+ typedef std::pair<const iterator_type, void *> result_type;
+
+ // returns pointer to object and an indicator whether this is a
+ // new entry (true) or a previous one (false)
+ BOOST_ARCHIVE_DECL(result_type) get_od(
+ void * od,
+ const boost::serialization::extended_type_info * true_type,
+ const boost::serialization::extended_type_info * this_type
+ );
+
+ template<class T>
+ struct non_polymorphic {
+ static const boost::serialization::extended_type_info *
+ get_object_identifier(T & t){
+ return boost::serialization::singleton<
+ BOOST_DEDUCED_TYPENAME
+ boost::serialization::type_info_implementation<T>::type
+ >::get_const_instance();
+ }
+ };
+ template<class T>
+ struct polymorphic {
+ static const boost::serialization::extended_type_info *
+ get_object_identifier(T & t){
+ return boost::serialization::singleton<
+ BOOST_DEDUCED_TYPENAME
+ boost::serialization::type_info_implementation<T>::type
+ >::get_const_instance().get_derived_extended_type_info(t);
+ }
+ };
 public:
     template<class T>
     void reset(shared_ptr<T> & s, T * t){
@@ -101,13 +134,18 @@
         const boost::serialization::extended_type_info * this_type
             = & boost::serialization::type_info_implementation<T>::type
                     ::get_const_instance();
+
         // get pointer to the most derived object. This is effectively
         // the object identifer
- const boost::serialization::extended_type_info * true_type
- = boost::serialization::singleton<
- BOOST_DEDUCED_TYPENAME
- boost::serialization::type_info_implementation<T>::type
- >::get_const_instance().get_derived_extended_type_info(*t);
+ typedef BOOST_DEDUCED_TYPENAME mpl::eval_if<
+ is_polymorphic<T>,
+ mpl::identity<polymorphic<T> >,
+ mpl::identity<non_polymorphic<T> >
+ >::type type;
+
+ const boost::serialization::extended_type_info * true_type
+ = type::get_object_identifier(*t);
+
         // note:if this exception is thrown, be sure that derived pointer
         // is either registered or exported.
         if(NULL == true_type)
@@ -117,78 +155,33 @@
                     this_type->get_debug_info()
                 )
             );
-
- // get void pointer to the most derived type
- // this uniquely identifies the object referred to
- const void * od = void_downcast(
- *true_type,
- *this_type,
- static_cast<const void *>(t)
- );
- if(NULL == od)
- boost::serialization::throw_exception(
- archive_exception(
- archive_exception::unregistered_cast,
- true_type->get_debug_info(),
- this_type->get_debug_info()
- )
+ result_type r =
+ get_od(
+ t,
+ true_type,
+ this_type
             );
-
- // make tracking array if necessary
- if(NULL == m_pointers)
- m_pointers = new collection_type;
-
- iterator_type it = m_pointers->find(od);
-
- // create a new shared pointer to a void
- if(it == m_pointers->end()){
- s.reset(t);
- shared_ptr<const void> sp(s, od);
- m_pointers->insert(collection_type::value_type(od, sp));
- return;
- }
- od = void_upcast(
- *true_type,
- *this_type,
- ((*it).second.get())
+ s = shared_ptr<T>(
+ r.first->second,
+ static_cast<T *>(r.second)
         );
- if(NULL == od)
- boost::serialization::throw_exception(
- archive_exception(
- archive_exception::unregistered_cast,
- true_type->get_debug_info(),
- this_type->get_debug_info()
- )
- );
- t = static_cast<T *>(const_cast<void *>(od));
- s = shared_ptr<T>((*it).second, t); // aliasing
     }
+
 // #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP
- void append(const boost_132::shared_ptr<void> & t){
- if(NULL == m_pointers_132)
- m_pointers_132 = new std::list<boost_132::shared_ptr<void> >;
- m_pointers_132->push_back(t);
- }
+ BOOST_ARCHIVE_DECL(void)
+ append(const boost_132::shared_ptr<void> & t);
 // #endif
 public:
- shared_ptr_helper() :
- m_pointers(NULL)
- #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP
- , m_pointers_132(NULL)
- #endif
- {}
- ~shared_ptr_helper(){
- if(NULL != m_pointers)
- delete m_pointers;
- #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP
- if(NULL != m_pointers_132)
- delete m_pointers_132;
- #endif
- }
+ BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
+ shared_ptr_helper();
+ BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
+ ~shared_ptr_helper();
 };
 
 } // namespace detail
-} // namespace serialization
+} // namespace archive
 } // namespace boost
 
+#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
+
 #endif // BOOST_ARCHIVE_SHARED_PTR_HELPER_HPP

Modified: trunk/boost/archive/text_iarchive.hpp
==============================================================================
--- trunk/boost/archive/text_iarchive.hpp (original)
+++ trunk/boost/archive/text_iarchive.hpp 2009-08-26 16:44:55 EDT (Wed, 26 Aug 2009)
@@ -94,6 +94,8 @@
 } // namespace archive
 } // namespace boost
 
+#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
+
 // note special treatment of shared_ptr. This type needs a special
 // structure associated with every archive. We created a "mix-in"
 // class to provide this functionality. Since shared_ptr holds a
@@ -121,6 +123,4 @@
 // required by export
 BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::archive::text_iarchive)
 
-#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
-
 #endif // BOOST_ARCHIVE_TEXT_IARCHIVE_HPP

Modified: trunk/boost/archive/text_wiarchive.hpp
==============================================================================
--- trunk/boost/archive/text_wiarchive.hpp (original)
+++ trunk/boost/archive/text_wiarchive.hpp 2009-08-26 16:44:55 EDT (Wed, 26 Aug 2009)
@@ -91,6 +91,8 @@
 } // namespace archive
 } // namespace boost
 
+#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
+
 // note special treatment of shared_ptr. This type needs a special
 // structure associated with every archive. We created a "mix-in"
 // class to provide this functionality. Since shared_ptr holds a
@@ -117,7 +119,5 @@
 // required by export
 BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::archive::text_wiarchive)
 
-#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
-
 #endif // BOOST_NO_STD_WSTREAMBUF
 #endif // BOOST_ARCHIVE_TEXT_WIARCHIVE_HPP

Modified: trunk/boost/archive/xml_archive_exception.hpp
==============================================================================
--- trunk/boost/archive/xml_archive_exception.hpp (original)
+++ trunk/boost/archive/xml_archive_exception.hpp 2009-08-26 16:44:55 EDT (Wed, 26 Aug 2009)
@@ -20,6 +20,10 @@
 #include <cassert>
 
 #include <boost/archive/archive_exception.hpp>
+#include <boost/preprocessor/empty.hpp>
+#include <boost/archive/detail/decl.hpp>
+
+#include <boost/archive/detail/abi_prefix.hpp> // must be the last header
 
 namespace boost {
 namespace archive {
@@ -27,7 +31,7 @@
 //////////////////////////////////////////////////////////////////////
 // exceptions thrown by xml archives
 //
-class xml_archive_exception :
+class BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) xml_archive_exception :
     public virtual archive_exception
 {
 public:
@@ -36,32 +40,16 @@
         xml_archive_tag_mismatch,
         xml_archive_tag_name_error
     } exception_code;
- exception_code m_code;
- xml_archive_exception(exception_code code) :
- m_code(code)
- {}
- virtual const char *what( ) const throw( )
- {
- const char *msg;
- switch(m_code){
- case xml_archive_parsing_error:
- msg = "unrecognized XML syntax";
- break;
- case xml_archive_tag_mismatch:
- msg = "XML start/end tag mismatch";
- break;
- case xml_archive_tag_name_error:
- msg = "Invalid XML tag name";
- break;
- default:
- msg = archive_exception::what();
- break;
- }
- return msg;
- }
+ xml_archive_exception(
+ exception_code c,
+ const char * e1 = NULL,
+ const char * e2 = NULL
+ );
 };
 
 }// namespace archive
 }// namespace boost
 
+#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
+
 #endif //BOOST_XML_ARCHIVE_ARCHIVE_EXCEPTION_HPP

Modified: trunk/boost/archive/xml_iarchive.hpp
==============================================================================
--- trunk/boost/archive/xml_iarchive.hpp (original)
+++ trunk/boost/archive/xml_iarchive.hpp 2009-08-26 16:44:55 EDT (Wed, 26 Aug 2009)
@@ -102,6 +102,8 @@
 } // namespace archive
 } // namespace boost
 
+#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
+
 // note special treatment of shared_ptr. This type needs a special
 // structure associated with every archive. We created a "mix-in"
 // class to provide this functionality. Since shared_ptr holds a
@@ -128,6 +130,4 @@
 // required by export
 BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::archive::xml_iarchive)
 
-#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
-
 #endif // BOOST_ARCHIVE_XML_IARCHIVE_HPP

Modified: trunk/boost/archive/xml_wiarchive.hpp
==============================================================================
--- trunk/boost/archive/xml_wiarchive.hpp (original)
+++ trunk/boost/archive/xml_wiarchive.hpp 2009-08-26 16:44:55 EDT (Wed, 26 Aug 2009)
@@ -106,6 +106,8 @@
 } // namespace archive
 } // namespace boost
 
+#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
+
 // note special treatment of shared_ptr. This type needs a special
 // structure associated with every archive. We created a "mix-in"
 // class to provide this functionality. Since shared_ptr holds a
@@ -132,7 +134,5 @@
 // required by export
 BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::archive::xml_wiarchive)
 
-#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
-
 #endif // BOOST_NO_STD_WSTREAMBUF
 #endif // BOOST_ARCHIVE_XML_WIARCHIVE_HPP


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