|
Boost-Commit : |
From: ramey_at_[hidden]
Date: 2007-11-22 00:58:32
Author: ramey
Date: 2007-11-22 00:58:32 EST (Thu, 22 Nov 2007)
New Revision: 41292
URL: http://svn.boost.org/trac/boost/changeset/41292
Log:
tested with statically loaded dlls
Text files modified:
branches/serialization_next_release/boost/boost/serialization/collections_load_imp.hpp | 2
branches/serialization_next_release/boost/boost/serialization/export.hpp | 62 +++++++++++++++----------
branches/serialization_next_release/boost/boost/serialization/extended_type_info.hpp | 35 ++++++--------
branches/serialization_next_release/boost/boost/serialization/extended_type_info_no_rtti.hpp | 15 ++++-
branches/serialization_next_release/boost/boost/serialization/extended_type_info_typeid.hpp | 32 ++++++-------
branches/serialization_next_release/boost/boost/serialization/singleton.hpp | 95 ++++++++++++++++++++++-----------------
branches/serialization_next_release/boost/boost/serialization/valarray.hpp | 4
7 files changed, 133 insertions(+), 112 deletions(-)
Modified: branches/serialization_next_release/boost/boost/serialization/collections_load_imp.hpp
==============================================================================
--- branches/serialization_next_release/boost/boost/serialization/collections_load_imp.hpp (original)
+++ branches/serialization_next_release/boost/boost/serialization/collections_load_imp.hpp 2007-11-22 00:58:32 EST (Thu, 22 Nov 2007)
@@ -26,8 +26,6 @@
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
-#include <boost/aligned_storage.hpp>
-
#include <boost/serialization/access.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/detail/stack_constructor.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-11-22 00:58:32 EST (Thu, 22 Nov 2007)
@@ -25,6 +25,7 @@
#include <boost/config.hpp>
#include <boost/static_assert.hpp>
+#include <boost/static_warning.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <boost/type_traits/is_polymorphic.hpp>
@@ -37,6 +38,7 @@
#include <boost/mpl/assert.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/not.hpp>
+#include <boost/mpl/bool.hpp>
#include <iostream>
@@ -46,11 +48,8 @@
class basic_pointer_iserializer;
class basic_pointer_oserializer;
-
-template<class Archive, class T>
-class pointer_iserializer;
-template<class Archive, class T>
-class pointer_oserializer;
+class basic_iserializer;
+class basic_oserializer;
template <class Archive, class Serializable>
struct export_impl
@@ -68,28 +67,10 @@
pointer_oserializer<Archive, Serializable>
>::get_const_instance();
}
-
inline static void enable_load(mpl::false_) {}
inline static void enable_save(mpl::false_) {}
};
-template<class T>
-struct guid_initializer
-{
- const guid_initializer & export_guid(char const* key)
- {
- assert(NULL != key);
- 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;
- }
-};
-
// On many platforms, naming a specialization of this template is
// enough to cause its argument to be instantiated.
template <void(*)()>
@@ -119,15 +100,44 @@
template <class Archive, class Serializable>
BOOST_DLLEXPORT void ptr_serialization_support<Archive,Serializable>::instantiate()
{
- typedef mpl::not_<serialization::is_abstract<Serializable> > concrete;
export_impl<Archive,Serializable>::enable_save(
- mpl::and_<concrete, BOOST_DEDUCED_TYPENAME Archive::is_saving>());
+ BOOST_DEDUCED_TYPENAME Archive::is_saving()
+ );
export_impl<Archive,Serializable>::enable_load(
- mpl::and_<concrete, BOOST_DEDUCED_TYPENAME Archive::is_loading>());
+ BOOST_DEDUCED_TYPENAME Archive::is_loading::type::type()
+ );
}
+template<class T>
+struct guid_initializer
+{
+ const guid_initializer & export_guid(char const* key, mpl::false_){
+ BOOST_STATIC_WARNING(boost::is_polymorphic<T>::value);
+ 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;
+ }
+ const guid_initializer & export_guid(char const* key, mpl::true_){
+ return *this;
+ }
+ const guid_initializer & export_guid(char const* key){
+ // note: exporting an abstract base class will have no effect
+ // and cannot be used to instantitiate serialization code
+ // (one might be using this in a DLL to instantiate code)
+ BOOST_STATIC_WARNING(! boost::is_abstract<T>::value);
+ return export_guid(key, serialization::is_abstract<T>());
+ }
+};
+
} // namespace detail
} // namespace archive
} // namespace boost
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-11-22 00:58:32 EST (Thu, 22 Nov 2007)
@@ -19,7 +19,6 @@
// for now, extended type info is part of the serialization libraries
// this could change in the future.
#include <boost/config.hpp>
-#include <boost/noncopyable.hpp>
#include <boost/serialization/config.hpp>
#include <boost/config/abi_prefix.hpp> // must be the last header
@@ -33,42 +32,40 @@
namespace boost {
namespace serialization {
-class BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) extended_type_info :
- private boost::noncopyable
+class BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) extended_type_info
{
+private:
+ // 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 unsigned int m_type_info_key;
+ virtual bool
+ less_than(const extended_type_info &rhs) const = 0;
+ void key_unregister();
protected:
const char * m_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();
+ extended_type_info(const unsigned int type_info_key);
// account for bogus gcc warning
#if defined(__GNUC__)
virtual
#endif
~extended_type_info();
public:
- void key_register(const char *key);
const char * get_key() const {
return m_key;
}
+ void key_register(const char *key);
+ bool operator<(const extended_type_info &rhs) const;
+ bool operator==(const extended_type_info &rhs) const;
+ bool operator!=(const extended_type_info &rhs) const {
+ return !(operator==(rhs));
+ }
static const extended_type_info * find(const char *key);
};
-// 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-11-22 00:58:32 EST (Thu, 22 Nov 2007)
@@ -31,6 +31,8 @@
# pragma warning(disable : 4251 4231 4660 4275)
#endif
+#define EXTENDED_TYPE_INFO_NO_RTTI_KEY 2
+
namespace boost {
namespace serialization {
///////////////////////////////////////////////////////////////////////
@@ -43,11 +45,16 @@
public singleton<extended_type_info_no_rtti<T> >
{
public:
- // private constructor to inhibit any existence other than the
- // static one
- extended_type_info_no_rtti(){}
+ virtual bool
+ less_than(const extended_type_info &rhs) const;
+ /*static*/ const extended_type_info *
+ get_extended_type_info(const std::type_info & ti) const;
+
+ extended_type_info_no_rtti() :
+ extended_type_info(EXTENDED_TYPE_INFO_NO_RTTI_KEY)
+ {}
~extended_type_info_no_rtti(){};
- const boost::serialization::extended_type_info *
+ const 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
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-11-22 00:58:32 EST (Thu, 22 Nov 2007)
@@ -1,5 +1,6 @@
#ifndef BOOST_SERIALIZATION_EXTENDED_TYPE_INFO_TYPEID_HPP
#define BOOST_SERIALIZATION_EXTENDED_TYPE_INFO_TYPEID_HPP
+
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
@@ -28,8 +29,8 @@
#include <boost/type_traits/is_polymorphic.hpp>
#include <boost/preprocessor/stringize.hpp>
-#include <boost/serialization/extended_type_info.hpp>
#include <boost/serialization/singleton.hpp>
+#include <boost/serialization/extended_type_info.hpp>
#include <boost/config/abi_prefix.hpp> // must be the last header
#ifdef BOOST_MSVC
@@ -46,14 +47,15 @@
{
protected:
const std::type_info * m_ti;
- extended_type_info_typeid_0() :
- m_ti(NULL)
- {}
+ extended_type_info_typeid_0();
~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);
+ void type_unregister();
+ const extended_type_info *
+ get_extended_type_info(const std::type_info & ti) const;
public:
+ virtual bool
+ less_than(const extended_type_info &rhs) const;
const std::type_info & get_typeid() const {
return *m_ti;
}
@@ -61,26 +63,22 @@
} // namespace detail
-///////////////////////////////////////////////////////////////////////////////
-// layer to fold T and const T into the same table entry.
template<class T>
class extended_type_info_typeid :
public detail::extended_type_info_typeid_0,
- public singleton<extended_type_info_typeid<const T> >
+ public singleton<extended_type_info_typeid<T> >
{
-protected:
-#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x560))
-public:
-#endif
public:
- // protected constructor to inhibit any existence other than the
- // static one
extended_type_info_typeid() :
detail::extended_type_info_typeid_0()
{
type_register(typeid(T));
}
- ~extended_type_info_typeid(){}
+ ~extended_type_info_typeid(){
+ type_unregister();
+ }
+ // get the eti record for the true type of this record
+ // relying upon standard type info implemenation (rtti)
const extended_type_info *
get_derived_extended_type_info(const T & t) const {
// note: this implementation - based on usage of typeid (rtti)
@@ -89,7 +87,7 @@
static_cast<bool>(boost::is_polymorphic<T>::value)
);
return
- detail::extended_type_info_typeid_0::get_derived_extended_type_info(
+ detail::extended_type_info_typeid_0::get_extended_type_info(
typeid(t)
);
}
Modified: branches/serialization_next_release/boost/boost/serialization/singleton.hpp
==============================================================================
--- branches/serialization_next_release/boost/boost/serialization/singleton.hpp (original)
+++ branches/serialization_next_release/boost/boost/serialization/singleton.hpp 2007-11-22 00:58:32 EST (Thu, 22 Nov 2007)
@@ -23,12 +23,11 @@
// 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
+// is called or any entry point into the shared library is invoked.
+// This guarentees no race condition for initialization.
+// In debug mode, we 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)
@@ -49,10 +48,52 @@
// details.
//
+// singletons created by this code are guarenteed to be unique
+// within the executable or shared library which creates them.
+// This is sufficient and in fact ideal for the serialization library.
+// The singleton is created when the module is loaded and destroyed
+// when the module is unloaded.
+
+// This base class has two functions.
+
+// First it provides a module handle for each singleton indicating
+// the executable or shared library in which it was created. This
+// turns out to be necessary and sufficient to implement the tables
+// used by serialization library.
+
+// Second, it provides a mechanism to detect when a non-const function
+// is called after initialization.
+
+// 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. A test program
+// can lock all the single
+
+class singleton_module : public boost::noncopyable
+{
+private:
+ static bool & get_lock(){
+ static bool lock = false;
+ return lock;
+ }
+public:
+// static const void * get_module_handle(){
+// return static_cast<const void *>(get_module_handle);
+// }
+ static void lock(){
+ get_lock() = true;
+ }
+ static void unlock(){
+ get_lock() = false;
+ }
+ static bool is_locked() {
+ return get_lock();
+ }
+};
+
template <class T>
-class singleton : public boost::noncopyable
+class singleton : public singleton_module
{
- friend class global_lock;
private:
BOOST_DLLEXPORT static T & instance;
// include this to provoke instantiation at pre-execution time
@@ -65,48 +106,18 @@
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 T & get_mutable_instance(){
+ assert(! is_locked());
+ return get_instance();
}
- static global_lock & get_mutable_instance(){
+ static const T & get_const_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();
-}
-
+BOOST_DLLEXPORT T & singleton<T>::instance = singleton<T>::get_instance();
} // namespace serialization
} // namespace boost
Modified: branches/serialization_next_release/boost/boost/serialization/valarray.hpp
==============================================================================
--- branches/serialization_next_release/boost/boost/serialization/valarray.hpp (original)
+++ branches/serialization_next_release/boost/boost/serialization/valarray.hpp 2007-11-22 00:58:32 EST (Thu, 22 Nov 2007)
@@ -41,7 +41,7 @@
{
const collection_size_type count(t.size());
ar << BOOST_SERIALIZATION_NVP(count);
- if (count)
+ if (t.size())
ar << make_array(detail::get_data(t), t.size());
}
@@ -52,7 +52,7 @@
collection_size_type count;
ar >> BOOST_SERIALIZATION_NVP(count);
t.resize(count);
- if (count)
+ if (t.size())
ar >> make_array(detail::get_data(t), t.size());
}
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