$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r54515 - in sandbox/monotonic: boost/heterogenous libs/monotonic/test/clones
From: christian.schladetsch_at_[hidden]
Date: 2009-06-29 23:43:22
Author: cschladetsch
Date: 2009-06-29 23:43:20 EDT (Mon, 29 Jun 2009)
New Revision: 54515
URL: http://svn.boost.org/trac/boost/changeset/54515
Log:
removed requirement for common_base
Text files modified: 
   sandbox/monotonic/boost/heterogenous/allocator.hpp            |     4 +++-                                    
   sandbox/monotonic/boost/heterogenous/base.hpp                 |    20 +++++++++++---------                    
   sandbox/monotonic/boost/heterogenous/common_base.hpp          |    25 +++++++++++++++++++------               
   sandbox/monotonic/boost/heterogenous/make_clone_allocator.hpp |     2 +-                                      
   sandbox/monotonic/boost/heterogenous/vector.hpp               |     4 ++--                                    
   sandbox/monotonic/libs/monotonic/test/clones/clones.vcproj    |     2 ++                                      
   sandbox/monotonic/libs/monotonic/test/clones/tests.cpp        |    40 +++++++++++++++++++++++-----------------
   7 files changed, 61 insertions(+), 36 deletions(-)
Modified: sandbox/monotonic/boost/heterogenous/allocator.hpp
==============================================================================
--- sandbox/monotonic/boost/heterogenous/allocator.hpp	(original)
+++ sandbox/monotonic/boost/heterogenous/allocator.hpp	2009-06-29 23:43:20 EDT (Mon, 29 Jun 2009)
@@ -37,7 +37,9 @@
                         template <class Base, class Alloc>
                         static void deallocate_clone(const Base *object, Alloc &alloc )
                         {
-				object->deallocate(const_cast<Base *>(object), alloc);
+				if (!object)
+					return;
+				object->deallocate(const_cast<Base &>(*object), alloc);
                         }
                 };
 
Modified: sandbox/monotonic/boost/heterogenous/base.hpp
==============================================================================
--- sandbox/monotonic/boost/heterogenous/base.hpp	(original)
+++ sandbox/monotonic/boost/heterogenous/base.hpp	2009-06-29 23:43:20 EDT (Mon, 29 Jun 2009)
@@ -15,11 +15,13 @@
         namespace heterogenous
         {
                 /// base for the given derived type
-		template <class Derived, class Base = common_base>
-		struct base : Base
+		template <class Derived, class Base = default_base_type, class AbstractBase = abstract_base<Base> >
+		struct base : AbstractBase
                 {
                         typedef Derived derived_type;
-			typedef base<Derived, Base> this_type;
+			typedef Base base_type;
+			typedef AbstractBase abstract_base_type;
+			typedef base<Derived, Base, AbstractBase> this_type;
 
                 private:
                         static size_t alignment;			///< required alignment for allocation
@@ -36,20 +38,20 @@
                                 return ptr;
                         }
 
-			void deallocate(common_base *object, abstract_allocator &alloc) const
+			void deallocate(base_type &object, abstract_allocator &alloc) const
                         {
-				Derived *ptr = static_cast<Derived *>(object);
+				Derived *ptr = static_cast<Derived *>(&object);
                                 alloc.deallocate_bytes(reinterpret_cast<abstract_allocator::pointer>(ptr), alignment);
                         }
 
-			virtual this_type *create(abstract_allocator &alloc) const 
+			virtual this_type *create_new(abstract_allocator &alloc) const 
                         {
                                 this_type *ptr = allocate(alloc);
                                 new (ptr->self_ptr) Derived();
                                 return ptr;
                         }
 
-			virtual this_type*copy_construct(const common_base &original, abstract_allocator &alloc) const 
+			virtual this_type *copy_construct(const base_type &original, abstract_allocator &alloc) const 
                         { 
                                 this_type *ptr = allocate(alloc);
                                 new (ptr->self_ptr) Derived(static_cast<const Derived &>(original));
@@ -58,8 +60,8 @@
                 };
 
                 /// ensure correct alignment when allocating derived instances
-		template <class Derived, class Base>
-		size_t base<Derived, Base>::alignment = aligned_storage<sizeof(Derived)>::alignment;
+		template <class Derived, class Base, class AbstractBase>
+		size_t base<Derived, Base, AbstractBase>::alignment = aligned_storage<sizeof(Derived)>::alignment;
 
         } // namespace heterogenous
 
Modified: sandbox/monotonic/boost/heterogenous/common_base.hpp
==============================================================================
--- sandbox/monotonic/boost/heterogenous/common_base.hpp	(original)
+++ sandbox/monotonic/boost/heterogenous/common_base.hpp	2009-06-29 23:43:20 EDT (Mon, 29 Jun 2009)
@@ -13,15 +13,28 @@
 {
         namespace heterogenous
         {
+		struct default_base_type
+		{
+			virtual ~default_base_type() { }
+		};
+
                 /// common base for all base types for hierachies
-		struct common_base
+		template <class Base = default_base_type>
+		struct abstract_base : Base
                 {
-			virtual ~common_base() { }
+			typedef Base base_type;
+			typedef abstract_base<Base> this_type;
+
+			//virtual base_type *allocate(abstract_allocator &alloc) const /*= 0;*/ { return 0; }
+			//virtual void deallocate(base_type *, abstract_allocator &alloc) const /*= 0;*/ { }
+			//virtual base_type *create(abstract_allocator &alloc) const /*= 0;*/ { return 0; }
+			//virtual base_type *copy_construct(const base_type &original, abstract_allocator &alloc) const /*= 0;*/ { return 0; }
+
+			virtual this_type *allocate(abstract_allocator &alloc) const = 0;
+			virtual void deallocate(base_type &, abstract_allocator &alloc) const = 0;
 
-			virtual common_base *allocate(abstract_allocator &alloc) const /*= 0;*/ { return 0; }
-			virtual void deallocate(common_base *, abstract_allocator &alloc) const /*= 0;*/ { }
-			virtual common_base *create(abstract_allocator &alloc) const /*= 0;*/ { return 0; }
-			virtual common_base *copy_construct(const common_base &original, abstract_allocator &alloc) const /*= 0;*/ { return 0; }
+			virtual this_type *create_new(abstract_allocator &alloc) const = 0;
+			virtual this_type *copy_construct(const base_type &original, abstract_allocator &alloc) const = 0;
                 };
 
         } // namespace heterogenous
Modified: sandbox/monotonic/boost/heterogenous/make_clone_allocator.hpp
==============================================================================
--- sandbox/monotonic/boost/heterogenous/make_clone_allocator.hpp	(original)
+++ sandbox/monotonic/boost/heterogenous/make_clone_allocator.hpp	2009-06-29 23:43:20 EDT (Mon, 29 Jun 2009)
@@ -16,7 +16,7 @@
         {
                 namespace impl
                 {
-			/// adapts a given Alloc type, modelling a v1 std::allocator concept, to provide
+			/// adapts a given Alloc type, modelling the v1 std::allocator concept, to provide
                         /// services required by abstract_allocator
                         template <class Alloc>
                         struct clone_allocator : Alloc, abstract_allocator
Modified: sandbox/monotonic/boost/heterogenous/vector.hpp
==============================================================================
--- sandbox/monotonic/boost/heterogenous/vector.hpp	(original)
+++ sandbox/monotonic/boost/heterogenous/vector.hpp	2009-06-29 23:43:20 EDT (Mon, 29 Jun 2009)
@@ -20,12 +20,12 @@
         namespace heterogenous
         {
                 /// a vector of heterogenous objects
-		template <class Alloc = monotonic::allocator<int>, class Base = common_base >
+		template <class Base = default_base_type, class Alloc = monotonic::allocator<int>, class AbstractBase = abstract_base<Base> >
                 struct vector
                 {
                         typedef Base base_type;
                         typedef typename make_clone_allocator<Alloc>::type allocator_type;
-			typedef ptr_vector<Base, allocator, allocator_type> implementation;
+			typedef ptr_vector<AbstractBase, allocator, allocator_type> implementation;
                         typedef typename implementation::value_type value_type;
                         typedef typename implementation::reference reference;
                         typedef typename implementation::const_reference const_reference;
Modified: sandbox/monotonic/libs/monotonic/test/clones/clones.vcproj
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/clones/clones.vcproj	(original)
+++ sandbox/monotonic/libs/monotonic/test/clones/clones.vcproj	2009-06-29 23:43:20 EDT (Mon, 29 Jun 2009)
@@ -44,8 +44,10 @@
                                 AdditionalIncludeDirectories="$(ProjectDir)/../../../.."
                                 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
                                 MinimalRebuild="true"
+				ExceptionHandling="1"
                                 BasicRuntimeChecks="3"
                                 RuntimeLibrary="3"
+				RuntimeTypeInfo="true"
                                 UsePrecompiledHeader="0"
                                 WarningLevel="3"
                                 DebugInformationFormat="4"
Modified: sandbox/monotonic/libs/monotonic/test/clones/tests.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/clones/tests.cpp	(original)
+++ sandbox/monotonic/libs/monotonic/test/clones/tests.cpp	2009-06-29 23:43:20 EDT (Mon, 29 Jun 2009)
@@ -18,14 +18,19 @@
 using namespace boost;
 using namespace heterogenous;
 
-struct derived : base<derived>
+struct my_base
+{
+	virtual ~my_base() { }
+};
+
+struct derived : base<derived, my_base>
 {
         int num;
         derived() : num(0) { }
         derived(int n) : num(n) { }
 };
 
-struct derived2 : base<derived2>
+struct derived2 : base<derived2, my_base>
 {
         std::string str;
 
@@ -33,7 +38,7 @@
         derived2(std::string const &n) : str(n) { }
 };
 
-struct derived3 : base<derived3>
+struct derived3 : base<derived3, my_base>
 {
         float real;
         int num;
@@ -73,7 +78,7 @@
         test_map();
 
         // a 'heterogenous' container of objects of any type that derives from common_base
-	typedef heterogenous::vector<> vec;
+	typedef heterogenous::vector<my_base> vec;
 
         {
                 vec bases;
@@ -94,10 +99,10 @@
 
                 BOOST_ASSERT(copy.size() == 3);
 
-		// each object in the container can be retrieved generically as a common_base
-		common_base &generic0 = copy[0];
-		common_base &generic1 = copy[1];
-		common_base &generic2 = copy[2];
+		// each object in the container can be retrieved generically as a default_base_type
+		my_base &generic0 = copy[0];
+		my_base &generic1 = copy[1];
+		my_base &generic2 = copy[2];
 
                 // get a reference; will throw bad_cast on type mismatch
                 derived &p1 = copy.ref_at<derived>(0);
@@ -116,7 +121,7 @@
                 bool caught = false;
                 try
                 {
-			common_base &base = copy.ref_at<derived2>(0);
+			my_base &base = copy.ref_at<derived2>(0);
                 }
                 catch (std::bad_cast)
                 {
@@ -159,31 +164,32 @@
 
 }
 
-struct my_base : heterogenous::common_base
+struct my_base2
 {
         int number;
-	my_base(int n = 0) : number(n) { }
+	my_base2(int n = 0) : number(n) { }
+	virtual ~my_base2() { }
 };
 
-struct T0 : heterogenous::base<T0, my_base>
+struct T0 : heterogenous::base<T0, my_base2>
 {
 };
 
-struct T1 : heterogenous::base<T1, my_base>
+struct T1 : heterogenous::base<T1, my_base2>
 {
 };
 
-struct T2 : heterogenous::base<T2, my_base>
+struct T2 : heterogenous::base<T2, my_base2>
 {
 };
 
-struct T3 : heterogenous::base<T3, my_base>
+struct T3 : heterogenous::base<T3, my_base2>
 {
 };
 
 struct my_less
 {
-	bool operator()(my_base const *left, my_base const *right) const
+	bool operator()(my_base2 const *left, my_base2 const *right) const
         {
                 return left->number < right->number;
         }
@@ -191,7 +197,7 @@
 
 void test_map()
 {
-	heterogenous::map<my_less, my_base> map;
+	heterogenous::map<my_less, my_base2> map;
 
         map .key<T0>().value<T1>()
                 .key<T2>().value<T3>()