Boost logo

Boost-Commit :

From: troyer_at_[hidden]
Date: 2008-06-14 07:22:56


Author: troyer
Date: 2008-06-14 07:22:55 EDT (Sat, 14 Jun 2008)
New Revision: 46385
URL: http://svn.boost.org/trac/boost/changeset/46385

Log:
Changed determination of when to use array optimizations to a traits class used only by the array wrapper, removing the need for deriving from the array/[io]archive base class and allowing mor specific enabling of array optimization, with less cost to users who don't need it.
Text files modified:
   trunk/boost/archive/array/iarchive.hpp | 49 ++++++---------------------------------
   trunk/boost/archive/array/oarchive.hpp | 49 +++++++--------------------------------
   trunk/boost/archive/basic_binary_iarchive.hpp | 16 ++++++------
   trunk/boost/archive/basic_binary_oarchive.hpp | 20 +++++----------
   trunk/boost/archive/binary_iarchive.hpp | 1
   trunk/boost/archive/binary_oarchive.hpp | 1
   trunk/boost/archive/detail/iserializer.hpp | 4 +-
   trunk/boost/archive/detail/oserializer.hpp | 4 +-
   8 files changed, 38 insertions(+), 106 deletions(-)

Modified: trunk/boost/archive/array/iarchive.hpp
==============================================================================
--- trunk/boost/archive/array/iarchive.hpp (original)
+++ trunk/boost/archive/array/iarchive.hpp 2008-06-14 07:22:55 EDT (Sat, 14 Jun 2008)
@@ -10,14 +10,7 @@
 #include <boost/archive/basic_archive.hpp>
 #include <boost/archive/detail/common_iarchive.hpp>
 #include <boost/serialization/array.hpp>
-#include <boost/serialization/collection_size_type.hpp>
-#include <boost/serialization/nvp.hpp>
-#include <boost/serialization/detail/get_data.hpp>
-#include <boost/type_traits/is_same.hpp>
-#include <boost/mpl/apply.hpp>
-#include <boost/mpl/bool.hpp>
 #include <boost/pfto.hpp>
-//#include <boost/archive/archive_exception.hpp>
 
 namespace boost { namespace archive { namespace array {
 
@@ -38,6 +31,11 @@
   // mpl::true_ iff array elements of type T can be serialized
   // with the load_array member function, and to mpl::false_ if
   // the unoptimized procedure must be used.
+ //
+ // * declare your archive to make use of array optimization
+ // by setting the appropriate trait with the
+ // BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION macro
+
 
 template <class Archive>
 class iarchive
@@ -63,20 +61,6 @@
     Base::load_override(t, version);
   }
 
- // the optimized implementation for vector uses serialization::array
- template<class ValueType, class Allocator>
- void load_optimized(
- std::vector<ValueType, Allocator> &t, unsigned int /*version*/, mpl::true_)
- {
- t.clear();
- // retrieve number of elements
- serialization::collection_size_type count;
- *this->This() >> BOOST_SERIALIZATION_NVP(count);
- t.resize(count);
- if (!t.empty())
- * this->This() >> serialization::make_array(serialization::detail::get_data(t),t.size());
- }
-
   // the optimized implementation for serialization::array uses save_array
   template<class ValueType>
   void load_optimized(
@@ -85,30 +69,13 @@
     this->This()->load_array(t,version);
   }
 
- // to load a vector:
- // if the value type is trivially constructable or an optimized array save exists,
- // then we can use the optimized version
-
- template<class ValueType, class Allocator>
- void load_override(std::vector<ValueType,Allocator> &x, unsigned int version)
- {
- typedef BOOST_DEDUCED_TYPENAME mpl::and_<
- mpl::not_<is_same<ValueType,bool> >,
- mpl::apply1<
- BOOST_DEDUCED_TYPENAME Archive::use_array_optimization
- , ValueType>
- >::type use_optimized;
- load_optimized(x,version, use_optimized() );
- }
-
   // dispatch loading of arrays to the optimized version where supported
   template<class ValueType>
   void load_override(serialization::array<ValueType> const& x, unsigned int version)
   {
- typedef BOOST_DEDUCED_TYPENAME mpl::apply1<
- BOOST_DEDUCED_TYPENAME Archive::use_array_optimization
- , ValueType
- >::type use_optimized;
+ typedef BOOST_DEDUCED_TYPENAME serialization
+ ::use_array_optimization<Archive>
+ ::template apply<ValueType>::type use_optimized;
     load_optimized(const_cast<serialization::array<ValueType>&>(x),version,use_optimized());
   }
 

Modified: trunk/boost/archive/array/oarchive.hpp
==============================================================================
--- trunk/boost/archive/array/oarchive.hpp (original)
+++ trunk/boost/archive/array/oarchive.hpp 2008-06-14 07:22:55 EDT (Sat, 14 Jun 2008)
@@ -10,14 +10,7 @@
 #include <boost/archive/basic_archive.hpp>
 #include <boost/archive/detail/common_oarchive.hpp>
 #include <boost/serialization/array.hpp>
-#include <boost/serialization/collection_size_type.hpp>
-#include <boost/serialization/nvp.hpp>
-#include <boost/serialization/detail/get_data.hpp>
-#include <boost/type_traits/is_same.hpp>
-#include <boost/mpl/apply.hpp>
-#include <boost/mpl/bool.hpp>
 #include <boost/pfto.hpp>
-#include <boost/type_traits/remove_const.hpp>
 
 namespace boost { namespace archive { namespace array {
 
@@ -38,6 +31,11 @@
   // mpl::true_ iff array elements of type T can be serialized
   // with the load_array member function, and to mpl::false_ if
   // the unoptimized procedure must be used.
+ //
+ // * declare your archive to make use of array optimization
+ // by setting the appropriate trait with the
+ // BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION macro
+
 
 template <class Archive>
 class oarchive
@@ -50,7 +48,7 @@
    : archive::detail::common_oarchive<Archive>(flags)
   {}
   
- // save_override for std::vector and serialization::array dispatches to
+ // save_override for serialization::array dispatches to
   // save_optimized with an additional argument.
   //
   // If that argument is of type mpl::true_, an optimized serialization is provided
@@ -63,17 +61,6 @@
     Base::save_override(t, version);
   }
 
- // the optimized implementation for vector uses serialization::array
- template<class ValueType, class Allocator>
- void save_optimized(
- const std::vector<ValueType, Allocator> &t, unsigned int, mpl::true_)
- {
- const serialization::collection_size_type count(t.size());
- * this->This() << BOOST_SERIALIZATION_NVP(count);
- if (!t.empty())
- * this->This() << serialization::make_array(serialization::detail::get_data(t),t.size());
- }
-
   // the optimized implementation for serialization::array uses save_array
   template<class ValueType>
   void save_optimized(
@@ -82,31 +69,13 @@
     this->This()->save_array(t,version);
   }
 
- // to save a vector:
- // if the value type is trivially constructable or an optimized array save exists,
- // then we can use the optimized version
-
- template<class ValueType, class Allocator>
- void save_override(std::vector<ValueType,Allocator> const &x, unsigned int version)
- {
- typedef BOOST_DEDUCED_TYPENAME remove_const<ValueType>::type value_type;
- typedef BOOST_DEDUCED_TYPENAME mpl::and_<
- mpl::not_<is_same<value_type,bool> >,
- mpl::apply1<
- BOOST_DEDUCED_TYPENAME Archive::use_array_optimization
- , value_type>
- >::type use_optimized;
- save_optimized(x,version,use_optimized() );
- }
-
   // dispatch saving of arrays to the optimized version where supported
   template<class ValueType>
   void save_override(serialization::array<ValueType> const& x, unsigned int version)
   {
- typedef BOOST_DEDUCED_TYPENAME mpl::apply1<
- BOOST_DEDUCED_TYPENAME Archive::use_array_optimization
- , BOOST_DEDUCED_TYPENAME remove_const<ValueType>::type
- >::type use_optimized;
+ typedef BOOST_DEDUCED_TYPENAME serialization
+ ::use_array_optimization<Archive>
+ ::template apply<ValueType>::type use_optimized;
     save_optimized(x,version,use_optimized());
   }
 

Modified: trunk/boost/archive/basic_binary_iarchive.hpp
==============================================================================
--- trunk/boost/archive/basic_binary_iarchive.hpp (original)
+++ trunk/boost/archive/basic_binary_iarchive.hpp 2008-06-14 07:22:55 EDT (Sat, 14 Jun 2008)
@@ -22,15 +22,15 @@
 // http://www.boost.org/LICENSE_1_0.txt)
 
 // See http://www.boost.org for updates, documentation, and revision history.
-//#include <cstring>
 
 #include <boost/config.hpp>
 #include <boost/detail/workaround.hpp>
 #include <boost/pfto.hpp>
 
-#include <boost/serialization/string.hpp>
+#include <boost/archive/detail/common_iarchive.hpp>
 #include <boost/serialization/collection_size_type.hpp>
-#include <boost/archive/array/iarchive.hpp>
+#include <boost/serialization/string.hpp>
+
 #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
 
 namespace boost {
@@ -40,7 +40,7 @@
 // class basic_binary_iarchive - read serialized objects from a input binary stream
 template<class Archive>
 class basic_binary_iarchive :
- public array::iarchive<Archive>
+ public detail::common_iarchive<Archive>
 {
 protected:
 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
@@ -56,10 +56,10 @@
     // fot templates in the absence of partial function
     // template ordering. If we get here pass to base class
     // note extra nonsense to sneak it pass the borland compiers
- typedef array::iarchive<Archive> array_iarchive;
+ typedef detail::common_iarchive<Archive> detail_common_iarchive;
     template<class T>
- void load_override(T & t, BOOST_PFTO int){
- this->array_iarchive::load_override(t, 0L);
+ void load_override(T & t, BOOST_PFTO int version){
+ this->detail_common_iarchive::load_override(t, static_cast<int>(version));
     }
     // binary files don't include the optional information
     void load_override(class_id_optional_type & /* t */, int){}
@@ -113,7 +113,7 @@
     init();
    
     basic_binary_iarchive(unsigned int flags) :
- array_iarchive(flags)
+ detail::common_iarchive<Archive>(flags)
     {}
 };
 

Modified: trunk/boost/archive/basic_binary_oarchive.hpp
==============================================================================
--- trunk/boost/archive/basic_binary_oarchive.hpp (original)
+++ trunk/boost/archive/basic_binary_oarchive.hpp 2008-06-14 07:22:55 EDT (Sat, 14 Jun 2008)
@@ -27,10 +27,9 @@
 #include <boost/pfto.hpp>
 
 #include <boost/detail/workaround.hpp>
-#include <boost/archive/array/oarchive.hpp>
+#include <boost/archive/detail/common_oarchive.hpp>
 #include <boost/serialization/string.hpp>
 #include <boost/serialization/collection_size_type.hpp>
-#include <boost/archive/array/oarchive.hpp>
 
 namespace boost {
 namespace archive {
@@ -45,7 +44,7 @@
 // of time. So under some circumstances it may be he right choice.
 template<class Archive>
 class basic_binary_oarchive :
- public array::oarchive<Archive>
+ public archive::detail::common_oarchive<Archive>
 {
 protected:
 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
@@ -58,17 +57,12 @@
     friend class detail::interface_oarchive<Archive>;
 #endif
     // any datatype not specifed below will be handled by base class
- typedef array::oarchive<Archive> array_oarchive;
+ typedef detail::common_oarchive<Archive> detail_common_oarchive;
     template<class T>
- void save_override(const T & t, BOOST_PFTO int){
- this->array_oarchive::save_override(t, 0L);
+ void save_override(const T & t, BOOST_PFTO int version){
+ this->detail_common_oarchive::save_override(t, static_cast<int>(version));
     }
- /*
- template<class T>
- void save_override(T & t, BOOST_PFTO int){
- this->save_override(const_cast<const T &>(t), 0L);
- }
- */
+
     // binary files don't include the optional information
     void save_override(const class_id_optional_type & /* t */, int){}
 
@@ -119,7 +113,7 @@
     init();
 
     basic_binary_oarchive(unsigned int flags) :
- array_oarchive(flags)
+ detail::common_oarchive<Archive>(flags)
     {}
 };
 

Modified: trunk/boost/archive/binary_iarchive.hpp
==============================================================================
--- trunk/boost/archive/binary_iarchive.hpp (original)
+++ trunk/boost/archive/binary_iarchive.hpp 2008-06-14 07:22:55 EDT (Sat, 14 Jun 2008)
@@ -88,5 +88,6 @@
 
 // required by export
 BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::archive::binary_iarchive)
+BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION(boost::archive::binary_iarchive)
 
 #endif // BOOST_ARCHIVE_BINARY_IARCHIVE_HPP

Modified: trunk/boost/archive/binary_oarchive.hpp
==============================================================================
--- trunk/boost/archive/binary_oarchive.hpp (original)
+++ trunk/boost/archive/binary_oarchive.hpp 2008-06-14 07:22:55 EDT (Sat, 14 Jun 2008)
@@ -50,5 +50,6 @@
 
 // required by export
 BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::archive::binary_oarchive)
+BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION(boost::archive::binary_oarchive)
 
 #endif // BOOST_ARCHIVE_BINARY_OARCHIVE_HPP

Modified: trunk/boost/archive/detail/iserializer.hpp
==============================================================================
--- trunk/boost/archive/detail/iserializer.hpp (original)
+++ trunk/boost/archive/detail/iserializer.hpp 2008-06-14 07:22:55 EDT (Sat, 14 Jun 2008)
@@ -43,7 +43,7 @@
 #include <boost/type_traits/is_enum.hpp>
 #include <boost/type_traits/is_const.hpp>
 #include <boost/type_traits/remove_const.hpp>
-#include <boost/type_traits/remove_all_extents.hpp>
+#include <boost/type_traits/remove_extent.hpp>
 #include <boost/serialization/assume_abstract.hpp>
 #include <boost/type_traits/is_polymorphic.hpp>
 
@@ -469,7 +469,7 @@
 template<class Archive, class T>
 struct load_array_type {
     static void invoke(Archive &ar, T &t){
- typedef BOOST_DEDUCED_TYPENAME remove_all_extents<T>::type value_type;
+ typedef BOOST_DEDUCED_TYPENAME remove_extent<T>::type value_type;
         
         // convert integers to correct enum to load
         int current_count = sizeof(t) / (

Modified: trunk/boost/archive/detail/oserializer.hpp
==============================================================================
--- trunk/boost/archive/detail/oserializer.hpp (original)
+++ trunk/boost/archive/detail/oserializer.hpp 2008-06-14 07:22:55 EDT (Sat, 14 Jun 2008)
@@ -37,7 +37,7 @@
 #include <boost/type_traits/is_const.hpp>
 //#include <boost/type_traits/is_same.hpp>
 #include <boost/type_traits/is_polymorphic.hpp>
-#include <boost/type_traits/remove_all_extents.hpp>
+#include <boost/type_traits/remove_extent.hpp>
 #include <boost/serialization/assume_abstract.hpp>
 
 #include <boost/mpl/eval_if.hpp>
@@ -464,7 +464,7 @@
 struct save_array_type
 {
     static void invoke(Archive &ar, const T &t){
- typedef BOOST_DEDUCED_TYPENAME remove_all_extents<T>::type value_type;
+ typedef BOOST_DEDUCED_TYPENAME boost::remove_extent<T>::type value_type;
         
         save_access::end_preamble(ar);
         // consider alignment


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