Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53075 - trunk/boost/serialization
From: ramey_at_[hidden]
Date: 2009-05-18 02:22:30


Author: ramey
Date: 2009-05-18 02:22:29 EDT (Mon, 18 May 2009)
New Revision: 53075
URL: http://svn.boost.org/trac/boost/changeset/53075

Log:
permit protected inheritance of serialization
Text files modified:
   trunk/boost/serialization/access.hpp | 12 ++++++++++--
   trunk/boost/serialization/base_object.hpp | 9 ++++++---
   2 files changed, 16 insertions(+), 5 deletions(-)

Modified: trunk/boost/serialization/access.hpp
==============================================================================
--- trunk/boost/serialization/access.hpp (original)
+++ trunk/boost/serialization/access.hpp 2009-05-18 02:22:29 EDT (Mon, 18 May 2009)
@@ -115,13 +115,21 @@
         // benign on everything else
         delete const_cast<T *>(t);
     }
- template<class Archive, class T>
- static void construct(Archive & /* ar */, T * t){
+ template<class T>
+ static void construct(T * t){
         // default is inplace invocation of default constructor
         // Note the :: before the placement new. Required if the
         // class doesn't have a class-specific placement new defined.
         ::new(t)T;
     }
+ template<class T, class U>
+ static T & cast_reference(U & u){
+ return static_cast<T &>(u);
+ }
+ template<class T, class U>
+ static T * cast_pointer(U * u){
+ return static_cast<T *>(u);
+ }
 };
 
 } // namespace serialization

Modified: trunk/boost/serialization/base_object.hpp
==============================================================================
--- trunk/boost/serialization/base_object.hpp (original)
+++ trunk/boost/serialization/base_object.hpp 2009-05-18 02:22:29 EDT (Mon, 18 May 2009)
@@ -34,6 +34,7 @@
 #include <boost/type_traits/is_polymorphic.hpp>
 
 #include <boost/static_assert.hpp>
+#include <boost/serialization/access.hpp>
 #include <boost/serialization/force_include.hpp>
 #include <boost/serialization/void_cast_fwd.hpp>
 
@@ -62,7 +63,9 @@
     {
         struct polymorphic {
             static void const * invoke(){
- return &void_cast_register((Derived const*)0, (Base const*)0);
+ Base const * const b = 0;
+ Derived const * const d = 0;
+ return & void_cast_register(d, b);
             }
         };
         struct non_polymorphic {
@@ -89,7 +92,7 @@
 {
     BOOST_STATIC_ASSERT(! is_pointer<Derived>::value);
     detail::base_register<Base, Derived>::invoke();
- return static_cast<const Base &>(d);
+ return access::cast_reference<const Base, Derived>(d);
 }
 #else
 template<class Base, class Derived>
@@ -100,7 +103,7 @@
     BOOST_STATIC_ASSERT(! is_pointer<Derived>::value);
     typedef BOOST_DEDUCED_TYPENAME detail::base_cast<Base, Derived>::type type;
     detail::base_register<type, Derived>::invoke();
- return static_cast<type &>(d);
+ return access::cast_reference<type, Derived>(d);
 }
 #endif
 


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