Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55791 - in trunk/libs/serialization: build doc src test vc7ide
From: ramey_at_[hidden]
Date: 2009-08-26 16:47:03


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

Log:
moved code from header to library to reduce code bloat
Added:
   trunk/libs/serialization/src/archive_exception.cpp (contents, props changed)
   trunk/libs/serialization/src/shared_ptr_helper.cpp (contents, props changed)
   trunk/libs/serialization/src/xml_archive_exception.cpp (contents, props changed)
Text files modified:
   trunk/libs/serialization/build/Jamfile.v2 | 3 +++
   trunk/libs/serialization/doc/exceptions.html | 10 +++++++++-
   trunk/libs/serialization/src/basic_iarchive.cpp | 4 ++--
   trunk/libs/serialization/src/basic_serializer_map.cpp | 2 +-
   trunk/libs/serialization/src/polymorphic_oarchive.cpp | 2 --
   trunk/libs/serialization/test/test_shared_ptr.cpp | 3 +--
   trunk/libs/serialization/vc7ide/Library.vcproj | 15 ++++++++++++---
   7 files changed, 28 insertions(+), 11 deletions(-)

Modified: trunk/libs/serialization/build/Jamfile.v2
==============================================================================
--- trunk/libs/serialization/build/Jamfile.v2 (original)
+++ trunk/libs/serialization/build/Jamfile.v2 2009-08-26 16:47:01 EDT (Wed, 26 Aug 2009)
@@ -75,9 +75,12 @@
     text_iarchive
     text_oarchive
     void_cast
+ archive_exception
     xml_grammar
     xml_iarchive
     xml_oarchive
+ xml_archive_exception
+ shared_ptr_helper
 ;
     
 WSOURCES =

Modified: trunk/libs/serialization/doc/exceptions.html
==============================================================================
--- trunk/libs/serialization/doc/exceptions.html (original)
+++ trunk/libs/serialization/doc/exceptions.html 2009-08-26 16:47:01 EDT (Wed, 26 Aug 2009)
@@ -36,6 +36,7 @@
   <dt>stream_error
   <dt>invalid_class_name
   <dt>unregistered_class
+ <dt>multiple_code_instantiation
   <dt>xml_archive_parsing_error
   <dt>xml_archive_tag_mismatch
   <dt>xml_archive_tag_name_error
@@ -75,9 +76,11 @@
                                 // to insert virus via buffer overrun method.
         unregistered_cast, // base - derived relationship not registered with
                                 // void_cast_register
- unsupported_class_version // type saved with a version # greater than the
+ 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.
+ multiple_code_instantiation // code for implementing serialization for some
+ // type has been instantiated in more than one module.
     } exception_code;
     exception_code code;
     archive_exception(exception_code c) : code(c) {}
@@ -228,6 +231,11 @@
 This exception is thrown if an attempt is made to convert between two pointers
 whose relationship has not been registered,
 
+<h3><a name="multiple_code_instantiation"><code style="white-space: normal">multiple_code_instantiation</code></a></h3>
+This exception is thrown when it is detected that the serialization of the same type
+has been instantiated more that once. This might occur when
+serialization code is instantiated in both the mainline and one or more DLLS.
+
 <h3><a name="xml_archive_parsing_error"><code style="white-space: normal">xml_archive_parsing_error</code></a></h3>
 The XML generated by the serialization process is intimately coupled to the
 C++ class structure, relationships between objects and the serialization

Added: trunk/libs/serialization/src/archive_exception.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/src/archive_exception.cpp 2009-08-26 16:47:01 EDT (Wed, 26 Aug 2009)
@@ -0,0 +1,110 @@
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// archive_exception.cpp:
+
+// (C) Copyright 2009 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to the Boost Software
+// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#if (defined _MSC_VER) && (_MSC_VER == 1200)
+# pragma warning (disable : 4786) // too long name, harmless warning
+#endif
+
+#include <exception>
+#include <cassert>
+#include <string>
+
+#define BOOST_ARCHIVE_SOURCE
+#include <boost/archive/archive_exception.hpp>
+
+namespace boost {
+namespace archive {
+
+BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
+archive_exception::archive_exception(
+ exception_code c,
+ const char * e1,
+ const char * e2
+) :
+ 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 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;
+ }
+}
+BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
+archive_exception::~archive_exception() throw () {}
+
+BOOST_ARCHIVE_DECL(const char *)
+archive_exception::what( ) const throw()
+{
+ return m_msg.c_str();
+}
+BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
+archive_exception::archive_exception() :
+ code(no_exception)
+{}
+
+} // archive
+} // boost

Modified: trunk/libs/serialization/src/basic_iarchive.cpp
==============================================================================
--- trunk/libs/serialization/src/basic_iarchive.cpp (original)
+++ trunk/libs/serialization/src/basic_iarchive.cpp 2009-08-26 16:47:01 EDT (Wed, 26 Aug 2009)
@@ -28,11 +28,11 @@
 #include <boost/serialization/throw_exception.hpp>
 #include <boost/serialization/tracking.hpp>
 
-#include <boost/archive/archive_exception.hpp>
-
 #define BOOST_ARCHIVE_SOURCE
 #define BOOST_SERIALIZATION_SOURCE
 
+#include <boost/archive/archive_exception.hpp>
+
 #include <boost/archive/detail/decl.hpp>
 #include <boost/archive/basic_archive.hpp>
 #include <boost/archive/detail/basic_iserializer.hpp>

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-08-26 16:47:01 EDT (Wed, 26 Aug 2009)
@@ -15,10 +15,10 @@
 #include <set>
 #include <utility>
 
+#define BOOST_ARCHIVE_SOURCE
 #include <boost/archive/archive_exception.hpp>
 #include <boost/serialization/throw_exception.hpp>
 
-#define BOOST_ARCHIVE_SOURCE
 #include <boost/archive/detail/basic_serializer.hpp>
 #include <boost/archive/detail/basic_serializer_map.hpp>
 

Modified: trunk/libs/serialization/src/polymorphic_oarchive.cpp
==============================================================================
--- trunk/libs/serialization/src/polymorphic_oarchive.cpp (original)
+++ trunk/libs/serialization/src/polymorphic_oarchive.cpp 2009-08-26 16:47:01 EDT (Wed, 26 Aug 2009)
@@ -14,8 +14,6 @@
 
 #define BOOST_ARCHIVE_SOURCE
 #include <boost/archive/detail/archive_serializer_map.hpp>
-#define BOOST_ARCHIVE_SOURCE
-#include <boost/archive/detail/archive_serializer_map.hpp>
 
 #include <boost/archive/impl/archive_serializer_map.ipp>
 #include <boost/archive/polymorphic_oarchive.hpp>

Added: trunk/libs/serialization/src/shared_ptr_helper.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/src/shared_ptr_helper.cpp 2009-08-26 16:47:01 EDT (Wed, 26 Aug 2009)
@@ -0,0 +1,113 @@
+// MS compatible compilers support #pragma once
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// shared_ptr_helper.hpp: serialization for boost shared pointer
+
+// (C) Copyright 2004-2009 Robert Ramey, Martin Ecker and Takatoshi Kondo
+// Use, modification and distribution is subject to the Boost Software
+// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#include <map>
+#include <list>
+#include <utility>
+#include <cstddef> // NULL
+
+#define BOOST_ARCHIVE_SOURCE
+
+#include <boost/serialization/throw_exception.hpp>
+#include <boost/serialization/void_cast.hpp>
+#include <boost/serialization/extended_type_info.hpp>
+#include <boost/archive/shared_ptr_helper.hpp>
+#include <boost/archive/archive_exception.hpp>
+
+namespace boost {
+namespace archive{
+namespace detail {
+
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// a common class for holding various types of shared pointers
+
+// returns pointer to object and an indicator whether this is a
+// new entry (true) or a previous one (false)
+BOOST_ARCHIVE_DECL(shared_ptr_helper::result_type)
+shared_ptr_helper::get_od(
+ void * od,
+ const boost::serialization::extended_type_info * true_type,
+ const boost::serialization::extended_type_info * this_type
+){
+ // get void pointer to the most derived type
+ // this uniquely identifies the object referred to
+ od = void_downcast(
+ *true_type,
+ *this_type,
+ od
+ );
+ if(NULL == od)
+ boost::serialization::throw_exception(
+ archive_exception(
+ archive_exception::unregistered_cast,
+ true_type->get_debug_info(),
+ this_type->get_debug_info()
+ )
+ );
+
+ // make tracking array if necessary
+ if(NULL == m_pointers)
+ m_pointers = new collection_type;
+
+ shared_ptr<const void> sp(od, null_deleter());
+ std::pair<collection_type::iterator, bool> result =
+ m_pointers->insert(
+ collection_type::value_type(od, sp)
+ );
+ od = void_upcast(
+ *true_type,
+ *this_type,
+ result.first->first
+ );
+ if(NULL == od)
+ boost::serialization::throw_exception(
+ archive_exception(
+ archive_exception::unregistered_cast,
+ true_type->get_debug_info(),
+ this_type->get_debug_info()
+ )
+ );
+ return result_type(result.first, od);
+}
+
+// #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP
+BOOST_ARCHIVE_DECL(void)
+shared_ptr_helper::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);
+}
+// #endif
+BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
+shared_ptr_helper::shared_ptr_helper() :
+ m_pointers(NULL)
+ #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP
+ , m_pointers_132(NULL)
+ #endif
+{}
+BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
+shared_ptr_helper::~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
+}
+
+} // namespace detail
+} // namespace serialization
+} // namespace boost
+

Added: trunk/libs/serialization/src/xml_archive_exception.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/src/xml_archive_exception.cpp 2009-08-26 16:47:01 EDT (Wed, 26 Aug 2009)
@@ -0,0 +1,56 @@
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// xml_archive_exception.cpp:
+
+// (C) Copyright 2009 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to the Boost Software
+// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#if (defined _MSC_VER) && (_MSC_VER == 1200)
+# pragma warning (disable : 4786) // too long name, harmless warning
+#endif
+
+#define BOOST_ARCHIVE_SOURCE
+
+#include <exception>
+#include <cassert>
+#include <string>
+
+#include <boost/archive/xml_archive_exception.hpp>
+
+namespace boost {
+namespace archive {
+
+BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
+xml_archive_exception::xml_archive_exception(
+ exception_code c,
+ const char * e1,
+ const char * e2
+ ) :
+ archive_exception(other_exception, e1, e2)
+ {
+ m_msg = "programming error";
+ switch(c){
+ case xml_archive_parsing_error:
+ m_msg = "unrecognized XML syntax";
+ break;
+ case xml_archive_tag_mismatch:
+ m_msg = "XML start/end tag mismatch";
+ if(NULL != e1){
+ m_msg += " - ";
+ m_msg += e1;
+ }
+ break;
+ case xml_archive_tag_name_error:
+ m_msg = "Invalid XML tag name";
+ break;
+ default:
+ assert(false);
+ break;
+ }
+ }
+
+} // archive
+} // boost

Modified: trunk/libs/serialization/test/test_shared_ptr.cpp
==============================================================================
--- trunk/libs/serialization/test/test_shared_ptr.cpp (original)
+++ trunk/libs/serialization/test/test_shared_ptr.cpp 2009-08-26 16:47:01 EDT (Wed, 26 Aug 2009)
@@ -23,11 +23,10 @@
 #include <boost/serialization/shared_ptr.hpp>
 #include <boost/serialization/weak_ptr.hpp>
 #include <boost/serialization/nvp.hpp>
+#include <boost/serialization/export.hpp>
 
 #include "test_tools.hpp"
 
-#include <boost/serialization/export.hpp>
-
 // This is a simple class. It contains a counter of the number
 // of objects of this class which have been instantiated.
 class A

Modified: trunk/libs/serialization/vc7ide/Library.vcproj
==============================================================================
--- trunk/libs/serialization/vc7ide/Library.vcproj (original)
+++ trunk/libs/serialization/vc7ide/Library.vcproj 2009-08-26 16:47:01 EDT (Wed, 26 Aug 2009)
@@ -433,6 +433,9 @@
                         <File
                                 RelativePath="..\..\..\boost\serialization\version.hpp">
                         </File>
+ <File
+ RelativePath="..\..\..\boost\archive\xml_archive_exception.hpp">
+ </File>
                 </Filter>
                 <Filter
                         Name="Serialization Implementations"
@@ -816,9 +819,6 @@
                                 RelativePath="..\..\..\boost\archive\text_oarchive.hpp">
                         </File>
                         <File
- RelativePath="..\..\..\boost\archive\xml_archive_exception.hpp">
- </File>
- <File
                                 RelativePath="..\..\..\boost\archive\xml_iarchive.hpp">
                         </File>
                         <File
@@ -881,6 +881,9 @@
                         Name="Source"
                         Filter="">
                         <File
+ RelativePath="..\src\archive_exception.cpp">
+ </File>
+ <File
                                 RelativePath="..\src\basic_archive.cpp">
                         </File>
                         <File
@@ -956,6 +959,9 @@
                                 RelativePath="..\src\polymorphic_oarchive.cpp">
                         </File>
                         <File
+ RelativePath="..\src\shared_ptr_helper.cpp">
+ </File>
+ <File
                                 RelativePath="..\src\stl_port.cpp">
                         </File>
                         <File
@@ -968,6 +974,9 @@
                                 RelativePath="..\src\void_cast.cpp">
                         </File>
                         <File
+ RelativePath="..\src\xml_archive_exception.cpp">
+ </File>
+ <File
                                 RelativePath="..\src\xml_grammar.cpp">
                         </File>
                         <File


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