Boost logo

Boost-Commit :

From: ramey_at_[hidden]
Date: 2007-10-29 15:37:11


Author: ramey
Date: 2007-10-29 15:37:09 EDT (Mon, 29 Oct 2007)
New Revision: 40560
URL: http://svn.boost.org/trac/boost/changeset/40560

Log:
First implementation of thread safe lock free serialization
Added:
   branches/serialization_next_release/boost/boost/serialization/array.hpp (contents, props changed)
   branches/serialization_next_release/boost/boost/serialization/collection_size_type.hpp (contents, props changed)
   branches/serialization_next_release/boost/boost/serialization/ephemeral.hpp (contents, props changed)
   branches/serialization_next_release/boost/boost/serialization/singleton.hpp (contents, props changed)
   branches/serialization_next_release/boost/boost/serialization/valarray.hpp (contents, props changed)
   branches/serialization_next_release/boost/boost/serialization/wrapper.hpp (contents, props changed)
Text files modified:
   branches/serialization_next_release/boost/boost/serialization/export.hpp | 62 ++++++++++------------
   branches/serialization_next_release/boost/boost/serialization/extended_type_info.hpp | 51 ++++++-----------
   branches/serialization_next_release/boost/boost/serialization/extended_type_info_no_rtti.hpp | 59 +++------------------
   branches/serialization_next_release/boost/boost/serialization/extended_type_info_typeid.hpp | 53 ++++++++----------
   branches/serialization_next_release/boost/boost/serialization/type_info_implementation.hpp | 2
   branches/serialization_next_release/boost/boost/serialization/void_cast.hpp | 110 +++++++++++++--------------------------
   6 files changed, 117 insertions(+), 220 deletions(-)

Added: branches/serialization_next_release/boost/boost/serialization/array.hpp
==============================================================================
--- (empty file)
+++ branches/serialization_next_release/boost/boost/serialization/array.hpp 2007-10-29 15:37:09 EDT (Mon, 29 Oct 2007)
@@ -0,0 +1,107 @@
+#ifndef BOOST_SERIALIZATION_ARRAY_HPP
+#define BOOST_SERIALIZATION_ARRAY_HPP
+
+// (C) Copyright 2005 Matthias Troyer and Dave Abrahams
+// 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)
+
+#include <boost/serialization/nvp.hpp>
+#include <boost/serialization/split_free.hpp>
+#include <boost/serialization/wrapper.hpp>
+#include <boost/serialization/collection_size_type.hpp>
+#include <boost/archive/archive_exception.hpp>
+#include <boost/throw_exception.hpp>
+#include <iostream>
+
+namespace boost { namespace serialization {
+
+template<class T>
+class array
+ : public wrapper_traits<array<T> >
+{
+public:
+ typedef T value_type;
+
+ array(value_type* t, std::size_t s) :
+ m_t(t),
+ m_element_count(s)
+ {}
+
+ // default implementation
+ template<class Archive>
+ void serialize(Archive &ar, const unsigned int) const
+ {
+ // default implemention does the loop
+ std::size_t c = count();
+ value_type * t = address();
+ while(0 < c--)
+ ar & make_nvp("item", *t++);
+ }
+
+ value_type* address() const
+ {
+ return m_t;
+ }
+
+ std::size_t count() const
+ {
+ return m_element_count;
+ }
+
+
+private:
+ value_type* m_t;
+ std::size_t const m_element_count;
+};
+
+template<class T>
+inline
+#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
+const
+#endif
+array<T> make_array( T* t, std::size_t s){
+ return array<T>(t, s);
+}
+
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// T[N]
+
+/*
+
+template<class Archive, class U, std::size_t N>
+void save( Archive & ar, U const (& t)[N], const unsigned int file_version )
+{
+ const serialization::collection_size_type count(N);
+ ar << BOOST_SERIALIZATION_NVP(count);
+ if (N)
+ ar << serialization::make_array(&t[0],N);
+}
+
+template<class Archive, class U, std::size_t N>
+void load( Archive & ar, U (& t)[N], const unsigned int file_version )
+{
+ serialization::collection_size_type count;
+ ar >> BOOST_SERIALIZATION_NVP(count);
+ if(count > N)
+ boost::throw_exception(archive::archive_exception(
+ boost::archive::archive_exception::array_size_too_short
+ ));
+ if (N)
+ ar >> serialization::make_array(&t[0],count);
+}
+
+
+// split non-intrusive serialization function member into separate
+// non intrusive save/load member functions
+template<class Archive, class U, std::size_t N>
+inline void serialize( Archive & ar, U (& t)[N], const unsigned int file_version)
+{
+ boost::serialization::split_free(ar, t, file_version);
+}
+*/
+
+
+} } // end namespace boost::serialization
+
+#endif //BOOST_SERIALIZATION_ARRAY_HPP

Added: branches/serialization_next_release/boost/boost/serialization/collection_size_type.hpp
==============================================================================
--- (empty file)
+++ branches/serialization_next_release/boost/boost/serialization/collection_size_type.hpp 2007-10-29 15:37:09 EDT (Mon, 29 Oct 2007)
@@ -0,0 +1,20 @@
+#ifndef BOOST_SERIALIZATION_COLLECTION_SIZE_TYPE_HPP
+#define BOOST_SERIALIZATION_COLLECTION_SIZE_TYPE_HPP
+
+// (C) Copyright 2005 Matthias Troyer
+// 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)
+
+#include <boost/strong_typedef.hpp>
+#include <boost/serialization/level.hpp>
+
+namespace boost { namespace serialization {
+
+BOOST_STRONG_TYPEDEF(std::size_t, collection_size_type)
+
+} } // end namespace boost::serialization
+
+BOOST_CLASS_IMPLEMENTATION(boost::serialization::collection_size_type, primitive_type)
+
+#endif //BOOST_SERIALIZATION_COLLECTION_SIZE_TYPE_HPP

Added: branches/serialization_next_release/boost/boost/serialization/ephemeral.hpp
==============================================================================
--- (empty file)
+++ branches/serialization_next_release/boost/boost/serialization/ephemeral.hpp 2007-10-29 15:37:09 EDT (Mon, 29 Oct 2007)
@@ -0,0 +1,80 @@
+#ifndef BOOST_SERIALIZATION_EPHEMERAL_HPP
+#define BOOST_SERIALIZATION_EPHEMERAL_HPP
+
+// MS compatible compilers support
+#pragma once
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// ephemeral_object.hpp: interface for serialization system.
+
+// (C) Copyright 2007 Matthias Troyer.
+// 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 <utility>
+
+#include <boost/config.hpp>
+#include <boost/detail/workaround.hpp>
+// supress noise
+#if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
+# pragma warning (disable : 4786) // too long name, harmless warning
+#endif
+
+#include <boost/mpl/integral_c.hpp>
+#include <boost/mpl/integral_c_tag.hpp>
+
+#include <boost/serialization/level.hpp>
+#include <boost/serialization/tracking.hpp>
+#include <boost/serialization/split_member.hpp>
+#include <boost/serialization/base_object.hpp>
+#include <boost/serialization/traits.hpp>
+#include <boost/serialization/wrapper.hpp>
+
+namespace boost {
+namespace serialization {
+
+template<class T>
+struct ephemeral_object :
+ public wrapper_traits<ephemeral_object<T> >
+{
+ explicit ephemeral_object(T& t) :
+ val(t)
+ {}
+
+ T & value() const {
+ return val;
+ }
+
+ const T & const_value() const {
+ return val;
+ }
+
+ template<class Archive>
+ void serialize(Archive &ar, const unsigned int) const
+ {
+ ar & val;
+ }
+
+private:
+ T & val;
+};
+
+template<class T>
+inline
+#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
+const
+#endif
+ephemeral_object<T> ephemeral(const char * name, T & t){
+ return ephemeral_object<T>(name, t);
+}
+
+} // seralization
+} // boost
+
+#endif // BOOST_SERIALIZATION_EPHEMERAL_HPP

Modified: branches/serialization_next_release/boost/boost/serialization/export.hpp
==============================================================================
--- branches/serialization_next_release/boost/boost/serialization/export.hpp (original)
+++ branches/serialization_next_release/boost/boost/serialization/export.hpp 2007-10-29 15:37:09 EDT (Mon, 29 Oct 2007)
@@ -26,11 +26,12 @@
 #include <boost/config.hpp>
 #include <boost/static_assert.hpp>
 #include <boost/preprocessor/stringize.hpp>
+#include <boost/type_traits/is_polymorphic.hpp>
 
-#include <boost/archive/detail/dynamically_initialized.hpp>
 #include <boost/serialization/type_info_implementation.hpp>
 #include <boost/serialization/is_abstract.hpp>
 #include <boost/serialization/force_include.hpp>
+#include <boost/serialization/singleton.hpp>
 
 #include <boost/archive/detail/register_archive.hpp>
 #include <boost/mpl/assert.hpp>
@@ -56,12 +57,16 @@
 {
     static const basic_pointer_iserializer &
     enable_load(mpl::true_){
- return pointer_iserializer<Archive, Serializable>::get_instance();
+ return boost::serialization::singleton<
+ pointer_iserializer<Archive, Serializable>
+ >::get_const_instance();
     }
 
     static const basic_pointer_oserializer &
     enable_save(mpl::true_){
- return pointer_oserializer<Archive, Serializable>::get_instance();
+ return boost::serialization::singleton<
+ pointer_oserializer<Archive, Serializable>
+ >::get_const_instance();
     }
 
     inline static void enable_load(mpl::false_) {}
@@ -70,37 +75,22 @@
 
 template<class T>
 struct guid_initializer
-{
- typedef typename
- boost::serialization::type_info_implementation<T>::type eti_type;
-
- static void export_register(const char *key)
- {
- eti_type::export_register(key);
- }
-
- static const guid_initializer& get_instance(char const* key)
+{
+ const guid_initializer & export_guid(char const* key)
     {
- static guid_initializer const instance(key);
- return instance;
+ assert(NULL != key);
+ boost::serialization::singleton<
+ boost::serialization::type_info_implementation<T>::type
+ >::get_mutable_instance().key_register(key);
+
+ // generates the statically-initialized objects whose constructors
+ // register the information allowing serialization of T objects
+ // through pointers to their base classes.
+ instantiate_ptr_serialization((T*)0, 0);
+ return *this;
     }
-
- BOOST_DLLEXPORT guid_initializer(const char *key = 0) BOOST_USED ;
 };
 
-
-template<class T>
-BOOST_DLLEXPORT guid_initializer<T>::guid_initializer(const char *key)
-{
- if(0 != key)
- export_register(key);
-
- // generates the statically-initialized objects whose constructors
- // register the information allowing serialization of T objects
- // through pointers to their base classes.
- instantiate_ptr_serialization((T*)0, 0);
-}
-
 // On many platforms, naming a specialization of this template is
 // enough to cause its argument to be instantiated.
 template <void(*)()>
@@ -146,9 +136,11 @@
 #define BOOST_CLASS_EXPORT_GUID(T, K) \
 namespace \
 { \
- ::boost::archive::detail::guid_initializer< T > const& \
+ ::boost::archive::detail::guid_initializer< T > const & \
         BOOST_PP_CAT(boost_serialization_guid_initializer_, __LINE__) \
- = ::boost::archive::detail::guid_initializer< T >::get_instance(K); \
+ = ::boost::serialization::singleton< \
+ ::boost::archive::detail::guid_initializer< T > \
+ >::get_mutable_instance().export_guid(K); \
 }
 
 // the following is solely to support de-serialization of pointers serialized
@@ -156,9 +148,11 @@
 #define BOOST_CLASS_EXPORT_GUID_1(T, K) \
 namespace \
 { \
- ::boost::archive::detail::guid_initializer< T > const& \
+ ::boost::archive::detail::guid_initializer< T > const & \
     BOOST_PP_CAT(boost_serialization_guid_initializer_, __LINE__ ## _1) \
- = ::boost::archive::detail::guid_initializer< T >::get_instance(K); \
+ = ::boost::serialization::singleton< \
+ ::boost::archive::detail::guid_initializer< T > \
+ >::get_mutable_instance().export_guid(K); \
 }
 
 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))

Modified: branches/serialization_next_release/boost/boost/serialization/extended_type_info.hpp
==============================================================================
--- branches/serialization_next_release/boost/boost/serialization/extended_type_info.hpp (original)
+++ branches/serialization_next_release/boost/boost/serialization/extended_type_info.hpp 2007-10-29 15:37:09 EDT (Mon, 29 Oct 2007)
@@ -36,52 +36,39 @@
 class BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) extended_type_info :
     private boost::noncopyable
 {
-private:
- virtual bool
- less_than(const extended_type_info &rhs) const = 0;
- int type_info_key_cmp(const extended_type_info & rhs) const;
-
- // used to uniquely identify the type of class derived from this one
- // 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;
- bool m_self_registered;
- // flag to indicate wheter its been registered by type;
- bool m_key_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
- // when given an iterator argument.
- bool m_is_destructing;
 protected:
     const char * m_key;
- extended_type_info(const char * type_info_key);
+
+ // this class can't be used as is. It's just the
+ // common functionality for all type_info replacement
+ // systems. Hence, make these protected
+ extended_type_info();
     // account for bogus gcc warning
     #if defined(__GNUC__)
     virtual
     #endif
- ~extended_type_info();
+ virtual ~extended_type_info();
 public:
- void self_register();
     void key_register(const char *key);
- bool is_destructing() const {
- return m_is_destructing;
- }
- bool operator<(const extended_type_info &rhs) const;
- bool operator==(const extended_type_info &rhs) const {
- return this == & rhs;
- }
- bool operator!=(const extended_type_info &rhs) const {
- return this != & rhs;
- }
     const char * get_key() const {
         return m_key;
     }
     static const extended_type_info * find(const char *key);
- static const extended_type_info * find(const extended_type_info * t);
 };
 
+// in order
+BOOST_SERIALIZATION_DECL(bool)
+operator==(
+ const extended_type_info & lhs,
+ const extended_type_info & rhs
+);
+
+BOOST_SERIALIZATION_DECL(bool)
+operator<(
+ const extended_type_info & lhs,
+ const extended_type_info & rhs
+);
+
 } // namespace serialization
 } // namespace boost
 

Modified: branches/serialization_next_release/boost/boost/serialization/extended_type_info_no_rtti.hpp
==============================================================================
--- branches/serialization_next_release/boost/boost/serialization/extended_type_info_no_rtti.hpp (original)
+++ branches/serialization_next_release/boost/boost/serialization/extended_type_info_no_rtti.hpp 2007-10-29 15:37:09 EDT (Mon, 29 Oct 2007)
@@ -32,44 +32,26 @@
 
 namespace boost {
 namespace serialization {
-namespace detail {
 ///////////////////////////////////////////////////////////////////////
 // define a special type_info that doesn't depend on rtti which is not
 // available in all situations.
 
-// common base class to share type_info_key. This is used to
-// identify the method used to keep track of the extended type
-class BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) extended_type_info_no_rtti_0 :
+template<class T>
+class extended_type_info_no_rtti :
     public extended_type_info
 {
- virtual bool
- less_than(const boost::serialization::extended_type_info &rhs) const ;
-protected:
- extended_type_info_no_rtti_0();
- // account for bogus gcc warning
- #if defined(__GNUC__)
- virtual
- #endif
- ~extended_type_info_no_rtti_0();
 public:
     struct is_polymorphic
     {
         typedef boost::mpl::bool_<true> type;
         BOOST_STATIC_CONSTANT(bool, value = is_polymorphic::type::value);
     };
-};
-
-template<class T>
-class extended_type_info_no_rtti_1 :
- public extended_type_info_no_rtti_0
-{
-protected:
- extended_type_info_no_rtti_1(){}
-public:
- // note borland complains at making this destructor protected
- ~extended_type_info_no_rtti_1(){};
- static const boost::serialization::extended_type_info *
- get_derived_extended_type_info(const T & t){
+ // private constructor to inhibit any existence other than the
+ // static one
+ extended_type_info_no_rtti(){}
+ ~extended_type_info_no_rtti(){};
+ const boost::serialization::extended_type_info *
+ get_derived_extended_type_info(const T & t) const {
         // find the type that corresponds to the most derived type.
         // this implementation doesn't depend on typeid() but assumes
         // that the specified type has a function of the following signature.
@@ -79,29 +61,6 @@
         assert(NULL != derived_key);
         return boost::serialization::extended_type_info::find(derived_key);
     }
- static boost::serialization::extended_type_info *
- get_instance(){
- static extended_type_info_no_rtti_1<T> instance;
- return & instance;
- }
- static void
- export_register(const char * key){
- boost::serialization::extended_type_info * eti;
- eti = get_instance();
- eti->key_register(key); // initialize key and add to table
- eti->self_register(); // add type to type table
- }
-};
-} // namespace detail
-
-template<class T>
-class extended_type_info_no_rtti :
- public detail::extended_type_info_no_rtti_1<const T>
-{
- // private constructor to inhibit any existence other than the
- // static one
- extended_type_info_no_rtti(){}
- ~extended_type_info_no_rtti(){};
 };
 
 } // namespace serialization
@@ -119,7 +78,7 @@
     template<class T>
     struct extended_type_info_impl {
         typedef BOOST_DEDUCED_TYPENAME
- boost::serialization::extended_type_info_no_rtti<const T> type;
+ boost::serialization::extended_type_info_no_rtti<T> type;
     };
     } // namespace serialization
     } // namespace boost

Modified: branches/serialization_next_release/boost/boost/serialization/extended_type_info_typeid.hpp
==============================================================================
--- branches/serialization_next_release/boost/boost/serialization/extended_type_info_typeid.hpp (original)
+++ branches/serialization_next_release/boost/boost/serialization/extended_type_info_typeid.hpp 2007-10-29 15:37:09 EDT (Mon, 29 Oct 2007)
@@ -19,11 +19,12 @@
 
 #include <typeinfo>
 #include <boost/config.hpp>
+#include <boost/detail/workaround.hpp>
 
 //#include <boost/static_warning.hpp>
 #include <boost/static_assert.hpp>
-#include <boost/type_traits/is_polymorphic.hpp>
 #include <boost/type_traits/is_const.hpp>
+#include <boost/type_traits/is_polymorphic.hpp>
 #include <boost/preprocessor/stringize.hpp>
 
 #include <boost/serialization/extended_type_info.hpp>
@@ -36,26 +37,24 @@
 
 namespace boost {
 namespace serialization {
-
 namespace detail {
 
 class BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) extended_type_info_typeid_0 :
     public extended_type_info
 {
-private:
- virtual bool
- less_than(const extended_type_info &rhs) const;
 protected:
+ const std::type_info * m_ti;
+ extended_type_info_typeid_0() :
+ m_ti(NULL)
+ {}
+ virtual ~extended_type_info_typeid_0();
+ void type_register(const std::type_info & ti);
     static const extended_type_info *
     get_derived_extended_type_info(const std::type_info & ti);
- extended_type_info_typeid_0();
- // account for bogus gcc warning
- #if defined(__GNUC__)
- virtual
- #endif
- ~extended_type_info_typeid_0();
 public:
- virtual const std::type_info & get_eti() const = 0;
+ const std::type_info & get_typeid() const {
+ return *m_ti;
+ }
 };
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -64,41 +63,35 @@
 class extended_type_info_typeid_1 :
     public detail::extended_type_info_typeid_0
 {
-private:
- virtual const std::type_info & get_eti() const {
- return typeid(T);
- }
 protected:
- // private constructor to inhibit any existence other than the
+ // protected constructor to inhibit any existence other than the
     // static one
     extended_type_info_typeid_1() :
         detail::extended_type_info_typeid_0()
     {
- self_register(); // add type to type table
+ type_register(typeid(T));
     }
+#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x560))
+public:
+#endif
+ ~extended_type_info_typeid_1(){}
 public:
     struct is_polymorphic
     {
         typedef BOOST_DEDUCED_TYPENAME boost::is_polymorphic<T>::type type;
         BOOST_STATIC_CONSTANT(bool, value = is_polymorphic::type::value);
     };
- static const extended_type_info *
- get_derived_extended_type_info(const T & t){
+ const extended_type_info *
+ get_derived_extended_type_info(const T & t) const {
         // note: this implementation - based on usage of typeid (rtti)
         // only works if the class has at least one virtual function.
 // BOOST_STATIC_WARNING(
 // static_cast<bool>(is_polymorphic::value)
 // );
- return detail::extended_type_info_typeid_0::get_derived_extended_type_info(typeid(t));
- }
- static extended_type_info *
- get_instance(){
- static extended_type_info_typeid_1<T> instance;
- return & instance;
- }
- static void
- export_register(const char * key){
- get_instance()->key_register(key);
+ return
+ detail::extended_type_info_typeid_0::get_derived_extended_type_info(
+ typeid(t)
+ );
     }
 };
 

Added: branches/serialization_next_release/boost/boost/serialization/singleton.hpp
==============================================================================
--- (empty file)
+++ branches/serialization_next_release/boost/boost/serialization/singleton.hpp 2007-10-29 15:37:09 EDT (Mon, 29 Oct 2007)
@@ -0,0 +1,114 @@
+#ifndef BOOST_SERIALIZATION_SINGLETON_HPP
+#define BOOST_SERIALIZATION_SINGLETON_HPP
+
+/////////1/////////2///////// 3/////////4/////////5/////////6/////////7/////////8
+// singleton.hpp
+//
+// Copyright David Abrahams 2006. Original version
+//
+// Copyright Robert Ramey 2007. Changes made to permit
+// application throughout the serialization library.
+//
+// Distributed under 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)
+//
+// The intention here is to define a template which will convert
+// any class into a singleton with the following features:
+//
+// a) initialized before first use.
+// b) thread-safe for const access to the class
+// c) non-locking
+//
+// In order to do this,
+// a) Initialize dynamically when used.
+// b) Require that all singletons be initialized before main
+// is called*. This guarentees no race condition for initialization.
+// In debug mode, assert that no non-const functions are called
+// after main is invoked.
+//
+// * note exception regarding dynamically loaded shared libraries.
+// check documentation
+
+// MS compatible compilers support #pragma once
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+#include <cassert>
+#include <boost/noncopyable.hpp>
+#include <boost/serialization/force_include.hpp>
+
+namespace boost {
+namespace serialization {
+
+//////////////////////////////////////////////////////////////////////
+// Provides a dynamically-initialized (singleton) instance of T in a
+// way that avoids LNK1179 on vc6. See http://tinyurl.com/ljdp8 or
+// http://lists.boost.org/Archives/boost/2006/05/105286.php for
+// details.
+//
+
+template <class T>
+class singleton : public boost::noncopyable
+{
+ friend class global_lock;
+private:
+ BOOST_DLLEXPORT static T & instance;
+ // include this to provoke instantiation at pre-execution time
+ static void use(T const &) {}
+ static T & get_instance(){
+ static T t;
+ // refer to instance, causing it to be instantiated (and
+ // initialized at startup on working compilers)
+ use(instance);
+ return t;
+ }
+public:
+ static const T & get_const_instance();
+ static T & get_mutable_instance();
+};
+
+template<class T>
+BOOST_DLLEXPORT T & singleton<T>::instance = singleton<T>::get_instance();
+
+// make a singleton to lock/unlock all singletons for alteration.
+// The intent is that all singletons created/used by this code
+// are to be initialized before main is called. (note exception
+// for DLLS which is dealt with in the documentation). If
+// the singleton is then used only as read
+
+class global_lock : public singleton<global_lock> {
+ bool locked;
+public:
+ global_lock() : locked(false) {}
+ void lock(){
+ locked = true;
+ }
+ void unlock(){
+ locked = false;
+ }
+ bool is_locked() const {
+ return locked;
+ }
+ static global_lock & get_mutable_instance(){
+ return get_instance();
+ }
+};
+
+template<class T>
+inline T & singleton<T>::get_mutable_instance(){
+ assert(! global_lock::get_mutable_instance().is_locked());
+ return get_instance();
+}
+
+template<class T>
+inline const T & singleton<T>::get_const_instance(){
+ return get_instance();
+}
+
+
+} // namespace serialization
+} // namespace boost
+
+#endif // BOOST_SERIALIZATION_SINGLETON_HPP

Modified: branches/serialization_next_release/boost/boost/serialization/type_info_implementation.hpp
==============================================================================
--- branches/serialization_next_release/boost/boost/serialization/type_info_implementation.hpp (original)
+++ branches/serialization_next_release/boost/boost/serialization/type_info_implementation.hpp 2007-10-29 15:37:09 EDT (Mon, 29 Oct 2007)
@@ -61,7 +61,7 @@
 namespace serialization { \
 template<> \
 struct type_info_implementation< T > { \
- typedef ETI type; \
+ typedef const ETI type; \
 }; \
 } \
 } \

Added: branches/serialization_next_release/boost/boost/serialization/valarray.hpp
==============================================================================
--- (empty file)
+++ branches/serialization_next_release/boost/boost/serialization/valarray.hpp 2007-10-29 15:37:09 EDT (Mon, 29 Oct 2007)
@@ -0,0 +1,74 @@
+#ifndef BOOST_SERIALIZATION_VALARAY_HPP
+#define BOOST_SERIALIZATION_VALARAY_HPP
+
+// MS compatible compilers support #pragma once
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// vector.hpp: serialization for stl vector templates
+
+// (C) Copyright 2005 Matthias Troyer .
+// 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 <valarray>
+#include <boost/config.hpp>
+#include <boost/serialization/split_free.hpp>
+#include <boost/serialization/array.hpp>
+#include <boost/serialization/collection_size_type.hpp>
+#include <boost/serialization/detail/get_data.hpp>
+
+// function specializations must be defined in the appropriate
+// namespace - boost::serialization
+#if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
+#define STD _STLP_STD
+#else
+#define STD std
+#endif
+
+namespace boost { namespace serialization {
+
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// valarray<T>
+
+template<class Archive, class U>
+void save( Archive & ar, const STD::valarray<U> &t, const unsigned int file_version )
+{
+ const collection_size_type count(t.size());
+ ar << BOOST_SERIALIZATION_NVP(count);
+ if (count)
+ ar << make_array(detail::get_data(t), t.size());
+}
+
+
+template<class Archive, class U>
+void load( Archive & ar, STD::valarray<U> &t, const unsigned int file_version )
+{
+ collection_size_type count;
+ ar >> BOOST_SERIALIZATION_NVP(count);
+ t.resize(count);
+ if (count)
+ ar >> make_array(detail::get_data(t), t.size());
+}
+
+// split non-intrusive serialization function member into separate
+// non intrusive save/load member functions
+template<class Archive, class U>
+inline void serialize( Archive & ar, STD::valarray<U> & t, const unsigned int file_version)
+{
+ boost::serialization::split_free(ar, t, file_version);
+}
+
+} } // end namespace boost::serialization
+
+#include <boost/serialization/collection_traits.hpp>
+
+BOOST_SERIALIZATION_COLLECTION_TRAITS(STD::valarray)
+#undef STD
+
+#endif // BOOST_SERIALIZATION_VALARAY_HPP

Modified: branches/serialization_next_release/boost/boost/serialization/void_cast.hpp
==============================================================================
--- branches/serialization_next_release/boost/boost/serialization/void_cast.hpp (original)
+++ branches/serialization_next_release/boost/boost/serialization/void_cast.hpp 2007-10-29 15:37:09 EDT (Mon, 29 Oct 2007)
@@ -18,10 +18,9 @@
 // See http://www.boost.org for updates, documentation, and revision history.
 
 #include <boost/smart_cast.hpp>
-#include <boost/mpl/eval_if.hpp>
-#include <boost/mpl/identity.hpp>
 
 #include <boost/serialization/config.hpp>
+#include <boost/serialization/singleton.hpp>
 #include <boost/serialization/force_include.hpp>
 #include <boost/serialization/type_info_implementation.hpp>
 
@@ -46,8 +45,7 @@
 void_upcast(
     extended_type_info const & derived_type,
     extended_type_info const & base_type,
- void const * const t,
- bool top = true
+ void const * const t
 );
 
 inline void *
@@ -67,63 +65,59 @@
 void_downcast(
     extended_type_info const & derived_type,
     extended_type_info const & base_type,
- void const * const t,
- bool top = true
+ void const * const t
 );
 
 inline void *
 void_downcast(
- extended_type_info const & derived_type_,
- extended_type_info const & base_type_,
+ extended_type_info const & derived_type,
+ extended_type_info const & base_type,
     void * const t
 ){
     return const_cast<void*>(void_downcast(
- derived_type_,
- base_type_,
+ derived_type,
+ base_type,
         const_cast<void const *>(t)
     ));
 }
 
 namespace void_cast_detail {
 
-// note: can't be abstract because an instance is used as a search argument
 class BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) void_caster
 {
     friend struct void_caster_compare ;
     friend
- BOOST_SERIALIZATION_DECL(void const *)
+ BOOST_SERIALIZATION_DECL(void const *)
     boost::serialization::void_upcast(
- const extended_type_info & derived_type,
- const extended_type_info & base_type,
- const void * t,
- bool top
+ const extended_type_info & derived,
+ const extended_type_info & base,
+ const void * t
     );
     friend
     BOOST_SERIALIZATION_DECL(void const *)
     boost::serialization::void_downcast(
- const extended_type_info & derived_type,
- const extended_type_info & base_type,
- const void * t,
- bool top
+ const extended_type_info & derived,
+ const extended_type_info & base,
+ const void * t
     );
+ // Data members
+ const extended_type_info & m_derived;
+ const extended_type_info & m_base;
     // each derived class must re-implement these;
     virtual void const * upcast(void const * t) const = 0;
     virtual void const * downcast(void const * t) const = 0;
- // Data members
- extended_type_info const & m_derived_type;
- extended_type_info const & m_base_type;
 protected:
- static void static_register(const void_caster *);
+ BOOST_SERIALIZATION_DECL(void)
+ static_register() const;
+ BOOST_SERIALIZATION_DECL(void)
+ static_unregister() const;
 public:
     // Constructor
     void_caster(
- extended_type_info const & derived_type_,
- extended_type_info const & base_type_
+ extended_type_info const & derived,
+ extended_type_info const & base
     );
- // predicate used to determine if this void caster includes
- // a particular eti *
- bool includes(const extended_type_info * eti) const;
- virtual ~void_caster();
+ virtual ~void_caster(){};
 private:
     // cw 8.3 requires this!!
     void_caster& operator=(void_caster const&);
@@ -134,66 +128,36 @@
     public void_caster
 {
     virtual void const* downcast( void const * t ) const {
- Derived * d = boost::smart_cast<const Derived *, const Base *>(
+ const Derived * d = boost::smart_cast<const Derived *, const Base *>(
             static_cast<const Base *>(t)
         );
         return d;
     }
     virtual void const* upcast(void const * t) const {
- Base * b = boost::smart_cast<const Base *, const Derived *>(
+ const Base * b = boost::smart_cast<const Base *, const Derived *>(
             static_cast<const Derived *>(t)
         );
         return b;
     }
-
+public:
     BOOST_DLLEXPORT void_caster_primitive() BOOST_USED;
-
- static BOOST_DLLEXPORT void_caster_primitive const& instance;
-
- // Something we can use to force instantiation without generating
- // warnings.
- static void use(void_caster_primitive const&) {}
-
- public:
- // CodeWarrior fails to construct static members of class
- // templates when they are instantiated from within templates, so
- // we do everything with void_caster_primitive in terms of
- // get_instance. On CodeWarrior, the user must invoke
- // BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED to make this work
- // (see boost/serialization/export.hpp). On other compilers (and
- // if the bug is fixed in a future version of CodeWarriror), the
- // initialization of instance (above) obviates the need for
- // BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED.
- static BOOST_DLLEXPORT void_caster_primitive const& get_instance()
- {
- static void_caster_primitive instance_;
-
- // refer to instance, causing it to be instantiated (and
- // initialized at startup on working compilers)
- use(instance);
-
- return instance_;
- }
+ BOOST_DLLEXPORT ~void_caster_primitive() BOOST_USED;
 };
 
 template <class Derived, class Base>
 BOOST_DLLEXPORT void_caster_primitive<Derived, Base>::void_caster_primitive() :
     void_caster(
- * type_info_implementation<Derived>::type::get_instance(),
- * type_info_implementation<Base>::type::get_instance()
+ singleton<type_info_implementation<Derived>::type>::get_const_instance(),
+ singleton<type_info_implementation<Base>::type>::get_const_instance()
     )
 {
- // calling get_instance() causes infinite recursion, and the
- // instance reference isn't initialized yet, so we must pass this
- // to static_register. It *is* the same object as instance, but
- // there's no way even to assert that here.
- this->static_register(this);
+ static_register();
 }
 
 template <class Derived, class Base>
-BOOST_DLLEXPORT void_caster_primitive<Derived,Base> const&
-void_caster_primitive<Derived,Base>::instance
-= void_caster_primitive<Derived,Base>::get_instance();
+BOOST_DLLEXPORT void_caster_primitive<Derived, Base>::~void_caster_primitive(){
+ static_unregister();
+}
 
 } // void_cast_detail
 
@@ -213,9 +177,9 @@
     const Derived * /* dnull = NULL */,
     const Base * /* bnull = NULL */
 ){
- return void_cast_detail::void_caster_primitive<
- const Derived, const Base
- >::get_instance();
+ return singleton<void_cast_detail::void_caster_primitive<
+ Derived, Base
+ > >::get_const_instance();
 }
 
 } // namespace serialization

Added: branches/serialization_next_release/boost/boost/serialization/wrapper.hpp
==============================================================================
--- (empty file)
+++ branches/serialization_next_release/boost/boost/serialization/wrapper.hpp 2007-10-29 15:37:09 EDT (Mon, 29 Oct 2007)
@@ -0,0 +1,63 @@
+#ifndef BOOST_SERIALIZATION_WRAPPER_HPP
+#define BOOST_SERIALIZATION_WRAPPER_HPP
+
+// (C) Copyright 2005-2006 Matthias Troyer
+// 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)
+
+#include <boost/serialization/traits.hpp>
+#include <boost/type_traits/is_base_and_derived.hpp>
+#include <boost/mpl/eval_if.hpp>
+
+namespace boost { namespace serialization {
+
+/// the base class for serialization wrappers
+///
+/// wrappers need to be treated differently at various places in the serialization library,
+/// e.g. saving of non-const wrappers has to be possible. Since partial specialization
+// is not supported by all compilers, we derive all wrappers from wrapper_traits.
+
+template<
+ class T,
+ int Level = object_serializable,
+ int Tracking = track_never,
+ unsigned int Version = 0,
+ class ETII = extended_type_info_impl< T >
+>
+struct wrapper_traits : public traits<T,Level,Tracking,Version,ETII,mpl::true_>
+{};
+
+/// the is_wrapper type traits class.
+
+namespace detail {
+template <class T>
+struct is_wrapper_member
+{
+ typedef BOOST_DEDUCED_TYPENAME T::is_wrapper type;
+};
+
+}
+
+
+template<class T>
+struct is_wrapper
+ : mpl::eval_if<
+ is_base_and_derived<basic_traits,T>,
+ detail::is_wrapper_member<T>,
+ mpl::false_
+ >::type
+{};
+
+} } // end namespace boost::serialization
+
+// A macro to define that a class is a wrapper
+#define BOOST_CLASS_IS_WRAPPER(T) \
+namespace boost { \
+namespace serialization { \
+template<> \
+struct is_wrapper< T > : mpl::true_ {}; \
+}}
+
+
+#endif //BOOST_SERIALIZATION_WRAPPER_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