$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r54446 - in sandbox/monotonic: boost boost/heterogenous libs/monotonic/test/clones
From: christian.schladetsch_at_[hidden]
Date: 2009-06-28 03:12:03
Author: cschladetsch
Date: 2009-06-28 03:12:02 EDT (Sun, 28 Jun 2009)
New Revision: 54446
URL: http://svn.boost.org/trac/boost/changeset/54446
Log:
moved cloneable into heterogenous
Text files modified: 
   sandbox/monotonic/boost/cloneable.hpp                 |   140 --------------------------------------- 
   sandbox/monotonic/boost/heterogenous/vector.hpp       |   141 +++++++++++++++++++++++++++++++++++++++ 
   sandbox/monotonic/libs/monotonic/test/clones/main.cpp |     9 +-                                      
   3 files changed, 145 insertions(+), 145 deletions(-)
Modified: sandbox/monotonic/boost/cloneable.hpp
==============================================================================
--- sandbox/monotonic/boost/cloneable.hpp	(original)
+++ sandbox/monotonic/boost/cloneable.hpp	2009-06-28 03:12:02 EDT (Sun, 28 Jun 2009)
@@ -6,149 +6,13 @@
 #ifndef BOOST_CLONEABLE_HPP
 #define BOOST_CLONEABLE_HPP
 
-#include <boost/abstract_allocator.hpp>
-#include <boost/aligned_storage.hpp>
-#include <boost/type_traits/is_convertible.hpp>
-#include <boost/ptr_container/ptr_vector.hpp>
+
 
 namespace boost 
 {
-	// move to boost::heterogenous?
+	// moved to boost::heterogenous
         namespace cloneable 
         {
-		/// common base for all base types for hierachies
-		struct common_base
-		{
-			virtual ~common_base() { }
-
-			virtual common_base *allocate(abstract_allocator &alloc) const = 0;
-			virtual void deallocate(common_base *, abstract_allocator &alloc) const = 0;
-			virtual common_base *create(abstract_allocator &alloc) const = 0;
-			virtual common_base *copy_construct(const common_base &original, abstract_allocator &alloc) const = 0;
-		};
-
-		/// base of the given derived type
-		template <class Derived>
-		struct base : common_base
-		{
-			typedef Derived derived_type;
-			typedef base<derived_type> this_type;
-
-		private:
-			static size_t alignment;
-			mutable derived_type *self_ptr;
-
-			derived_type *&self(derived_type *ptr) const
-			{
-				return ptr->this_type::self_ptr;
-			}
-
-		public:
-			base() : self_ptr(0) { }
-
-			virtual base<Derived> *allocate(boost::abstract_allocator &alloc) const 
-			{
-				boost::abstract_allocator::pointer bytes = alloc.allocate_bytes(sizeof(derived_type), alignment);
-				Derived *ptr = reinterpret_cast<Derived *>(bytes);
-				self(ptr) = ptr;
-				return ptr;
-			}
-
-			void deallocate(common_base *object, abstract_allocator &alloc) const
-			{
-				alloc.deallocate_bytes(reinterpret_cast<abstract_allocator::pointer>(object));
-			}
-
-			virtual base<Derived> *create(boost::abstract_allocator &alloc) const 
-			{
-				base<Derived> *ptr = allocate(alloc);
-				new (ptr->self_ptr) Derived();
-				return ptr;
-			}
-
-			virtual base<Derived> *copy_construct(const common_base &original, boost::abstract_allocator &alloc) const 
-			{ 
-				base<Derived> *ptr = allocate(alloc);
-				new (ptr->self_ptr) Derived(static_cast<const Derived &>(original));
-				return ptr;
-			}
-		};
-
-		/// ensure correct alignment when allocating derived instances
-		template <class Derived>
-		size_t base<Derived>::alignment = aligned_storage<sizeof(Derived)>::alignment;
-
-		/// a cloning allocator
-		struct allocator
-		{
-			template <class Base>
-			static Base* allocate_clone( const Base& object )
-			{
-				throw;
-			}
-
-			template <class Base>
-			static void deallocate_clone( const Base* clone )
-			{
-				throw;
-			}
-
-			template <class Base, class Alloc>
-			static Base* allocate_clone(const Base& object, Alloc &alloc )
-			{
-				// calling copy_construct must be disabled at compile-time for types that are not boost::is_convertible<cloneable::base<U> *, U*>
-				return object.copy_construct(object, alloc);
-			}
-
-			template <class Base, class Alloc>
-			static void deallocate_clone(const Base *object, Alloc &alloc )
-			{
-				object->deallocate(const_cast<Base *>(object), alloc);
-			}
-		};
-
-		namespace impl
-		{
-			template <class Alloc>
-			struct cloneable_allocator : Alloc, boost::abstract_allocator
-			{
-				typedef typename Alloc::template rebind<char>::other CharAlloc;
-
-				boost::abstract_allocator::pointer allocate_bytes(size_t num_bytes, size_t alignment)
-				{
-					CharAlloc alloc;
-					// todo: alignment; this is done already for monotonic, copy that here
-					return alloc.allocate(num_bytes);
-				}
-
-				void deallocate_bytes(boost::abstract_allocator::pointer ptr)
-				{
-					CharAlloc alloc;
-					alloc.deallocate(ptr, 1);
-				}
-			};
-
-			template <class Alloc, bool>
-			struct make_cloneable_allocator
-			{		
-				typedef cloneable_allocator<Alloc> type;
-			};
-
-			template <class Alloc>
-			struct make_cloneable_allocator<Alloc, true>
-			{
-				typedef Alloc type;
-			};
-		}
-
-		template <class Alloc>
-		struct make_cloneable_allocator
-		{
-			typedef boost::is_convertible<Alloc *, boost::abstract_allocator *> is_convertible;
-			BOOST_STATIC_CONSTANT(bool, is_cloneable = is_convertible::value);
-			typedef typename impl::make_cloneable_allocator<Alloc, is_cloneable>::type type;
-		};
-
         } // namespace cloneable
 
 } // namespace boost
Modified: sandbox/monotonic/boost/heterogenous/vector.hpp
==============================================================================
--- sandbox/monotonic/boost/heterogenous/vector.hpp	(original)
+++ sandbox/monotonic/boost/heterogenous/vector.hpp	2009-06-28 03:12:02 EDT (Sun, 28 Jun 2009)
@@ -6,17 +6,152 @@
 #ifndef BOOST_HETEROGENOUS_VECTOR_HPP
 #define BOOST_HETEROGENOUS_VECTOR_HPP
 
-#include <boost/cloneable.hpp>
+#include <boost/abstract_allocator.hpp>
+#include <boost/aligned_storage.hpp>
+#include <boost/type_traits/is_convertible.hpp>
 #include <boost/ptr_container/ptr_vector.hpp>
 
 namespace boost 
 {
         namespace heterogenous
         {
-		template <class Alloc = cloneable::make_cloneable_allocator<std::allocator<char> > >
+		/// common base for all base types for hierachies
+		struct common_base
+		{
+			virtual ~common_base() { }
+
+			virtual common_base *allocate(abstract_allocator &alloc) const = 0;
+			virtual void deallocate(common_base *, abstract_allocator &alloc) const = 0;
+			virtual common_base *create(abstract_allocator &alloc) const = 0;
+			virtual common_base *copy_construct(const common_base &original, abstract_allocator &alloc) const = 0;
+		};
+
+		/// base of the given derived type
+		template <class Derived>
+		struct base : common_base
+		{
+			typedef Derived derived_type;
+			typedef base<derived_type> this_type;
+
+		private:
+			static size_t alignment;
+			mutable derived_type *self_ptr;
+
+			derived_type *&self(derived_type *ptr) const
+			{
+				return ptr->this_type::self_ptr;
+			}
+
+		public:
+			base() : self_ptr(0) { }
+
+			virtual base<Derived> *allocate(boost::abstract_allocator &alloc) const 
+			{
+				boost::abstract_allocator::pointer bytes = alloc.allocate_bytes(sizeof(derived_type), alignment);
+				Derived *ptr = reinterpret_cast<Derived *>(bytes);
+				self(ptr) = ptr;
+				return ptr;
+			}
+
+			void deallocate(common_base *object, abstract_allocator &alloc) const
+			{
+				alloc.deallocate_bytes(reinterpret_cast<abstract_allocator::pointer>(object));
+			}
+
+			virtual base<Derived> *create(boost::abstract_allocator &alloc) const 
+			{
+				base<Derived> *ptr = allocate(alloc);
+				new (ptr->self_ptr) Derived();
+				return ptr;
+			}
+
+			virtual base<Derived> *copy_construct(const common_base &original, boost::abstract_allocator &alloc) const 
+			{ 
+				base<Derived> *ptr = allocate(alloc);
+				new (ptr->self_ptr) Derived(static_cast<const Derived &>(original));
+				return ptr;
+			}
+		};
+
+		/// ensure correct alignment when allocating derived instances
+		template <class Derived>
+		size_t base<Derived>::alignment = aligned_storage<sizeof(Derived)>::alignment;
+
+		/// a cloning allocator
+		struct allocator
+		{
+			template <class Base>
+			static Base* allocate_clone( const Base& object )
+			{
+				throw;
+			}
+
+			template <class Base>
+			static void deallocate_clone( const Base* clone )
+			{
+				throw;
+			}
+
+			template <class Base, class Alloc>
+			static Base* allocate_clone(const Base& object, Alloc &alloc )
+			{
+				// calling copy_construct must be disabled at compile-time for types that are not boost::is_convertible<cloneable::base<U> *, U*>
+				return object.copy_construct(object, alloc);
+			}
+
+			template <class Base, class Alloc>
+			static void deallocate_clone(const Base *object, Alloc &alloc )
+			{
+				object->deallocate(const_cast<Base *>(object), alloc);
+			}
+		};
+
+		namespace impl
+		{
+			template <class Alloc>
+			struct cloneable_allocator : Alloc, boost::abstract_allocator
+			{
+				typedef typename Alloc::template rebind<char>::other CharAlloc;
+
+				boost::abstract_allocator::pointer allocate_bytes(size_t num_bytes, size_t alignment)
+				{
+					CharAlloc alloc;
+					// todo: alignment; this is done already for monotonic, copy that here
+					return alloc.allocate(num_bytes);
+				}
+
+				void deallocate_bytes(boost::abstract_allocator::pointer ptr)
+				{
+					CharAlloc alloc;
+					alloc.deallocate(ptr, 1);
+				}
+			};
+
+			template <class Alloc, bool>
+			struct make_cloneable_allocator
+			{		
+				typedef cloneable_allocator<Alloc> type;
+			};
+
+			template <class Alloc>
+			struct make_cloneable_allocator<Alloc, true>
+			{
+				typedef Alloc type;
+			};
+		}
+
+		template <class Alloc>
+		struct make_cloneable_allocator
+		{
+			typedef boost::is_convertible<Alloc *, boost::abstract_allocator *> is_convertible;
+			BOOST_STATIC_CONSTANT(bool, is_cloneable = is_convertible::value);
+			typedef typename impl::make_cloneable_allocator<Alloc, is_cloneable>::type type;
+		};
+
+		template <class Alloc = make_cloneable_allocator<std::allocator<char> > >
                 struct vector
                 {
-			typedef ptr_vector<cloneable::common_base, cloneable::allocator, Alloc> implementation;
+			typedef ptr_vector<common_base, allocator, Alloc> implementation;
                         typedef Alloc allocator_type;
                         typedef typename implementation::value_type value_type;
                         typedef typename implementation::reference reference_type;
Modified: sandbox/monotonic/libs/monotonic/test/clones/main.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/clones/main.cpp	(original)
+++ sandbox/monotonic/libs/monotonic/test/clones/main.cpp	2009-06-28 03:12:02 EDT (Sun, 28 Jun 2009)
@@ -16,15 +16,16 @@
 
 using namespace std;
 using namespace boost;
+using namespace heterogenous;
 
-struct derived : cloneable::base<derived>
+struct derived : base<derived>
 {
         int num;
         derived() : num(0) { }
         explicit derived(int n) : num(n) { }
 };
 
-struct derived2 : cloneable::base<derived2>
+struct derived2 : base<derived2>
 {
         std::string str;
 
@@ -33,7 +34,7 @@
 };
 
 
-struct derived3 : cloneable::base<derived3>
+struct derived3 : base<derived3>
 {
         float real;
         int num;
@@ -75,7 +76,7 @@
                 bool caught = false;
                 try
                 {
-			cloneable::common_base &base = copy.ref_at<derived2>(0);
+			common_base &base = copy.ref_at<derived2>(0);
                 }
                 catch (std::bad_cast)
                 {