Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54785 - in sandbox/cloneable: boost/cloneable boost/cloneable/detail boost/ptr_container boost/ptr_container/detail libs/cloneable/test
From: christian.schladetsch_at_[hidden]
Date: 2009-07-07 19:04:50


Author: cschladetsch
Date: 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
New Revision: 54785
URL: http://svn.boost.org/trac/boost/changeset/54785

Log:
changed from tabs to spaces

Text files modified:
   sandbox/cloneable/boost/cloneable/abstract_allocator.hpp | 78 +-
   sandbox/cloneable/boost/cloneable/abstract_base.hpp | 296 +++++-----
   sandbox/cloneable/boost/cloneable/adaptor.hpp | 86 +-
   sandbox/cloneable/boost/cloneable/allocator.hpp | 282 +++++-----
   sandbox/cloneable/boost/cloneable/base.hpp | 136 ++--
   sandbox/cloneable/boost/cloneable/base_type.hpp | 82 +-
   sandbox/cloneable/boost/cloneable/clone.hpp | 294 +++++-----
   sandbox/cloneable/boost/cloneable/detail/allocation.hpp | 84 +-
   sandbox/cloneable/boost/cloneable/detail/associative_container_base.hpp | 246 ++++----
   sandbox/cloneable/boost/cloneable/detail/container_base.hpp | 224 +++---
   sandbox/cloneable/boost/cloneable/detail/create_new.hpp | 88 +-
   sandbox/cloneable/boost/cloneable/detail/make_clone_allocator.hpp | 196 ++++--
   sandbox/cloneable/boost/cloneable/detail/mixin.hpp | 300 +++++-----
   sandbox/cloneable/boost/cloneable/detail/prefix.hpp | 36
   sandbox/cloneable/boost/cloneable/detail/sequence_container_base.hpp | 385 ++++++------
   sandbox/cloneable/boost/cloneable/exception.hpp | 26
   sandbox/cloneable/boost/cloneable/forward_declarations.hpp | 272 ++++----
   sandbox/cloneable/boost/cloneable/heterogenous_map.hpp | 442 +++++++-------
   sandbox/cloneable/boost/cloneable/instance.hpp | 444 +++++++-------
   sandbox/cloneable/boost/cloneable/list.hpp | 92 +-
   sandbox/cloneable/boost/cloneable/map.hpp | 260 ++++----
   sandbox/cloneable/boost/cloneable/set.hpp | 398 +++++++-------
   sandbox/cloneable/boost/cloneable/traits.hpp | 82 +-
   sandbox/cloneable/boost/cloneable/vector.hpp | 190 +++---
   sandbox/cloneable/boost/ptr_container/detail/reversible_ptr_container.hpp | 66 +-
   sandbox/cloneable/boost/ptr_container/detail/scoped_deleter.hpp | 2
   sandbox/cloneable/boost/ptr_container/indirect_fun.hpp | 2
   sandbox/cloneable/boost/ptr_container/ptr_map.hpp | 8
   sandbox/cloneable/boost/ptr_container/ptr_map_adapter.hpp | 2
   sandbox/cloneable/boost/ptr_container/ptr_vector.hpp | 14
   sandbox/cloneable/libs/cloneable/test/tests.cpp | 1123 ++++++++++++++++++++-------------------
   31 files changed, 3143 insertions(+), 3093 deletions(-)

Modified: sandbox/cloneable/boost/cloneable/abstract_allocator.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/abstract_allocator.hpp (original)
+++ sandbox/cloneable/boost/cloneable/abstract_allocator.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -12,46 +12,46 @@
 
 namespace boost
 {
- namespace cloneable
- {
- /// base class for (wrapped) allocators to be used with cloneable::cloneable<>
- /// by cloneable containers
- struct abstract_allocator
- {
- typedef char *pointer;
-
- virtual pointer allocate_bytes(size_t num_bytes, size_t alignment) = 0;
-
- virtual void deallocate_bytes(pointer, size_t alignment) = 0;
-
- static size_t calc_padding(pointer ptr, size_t alignment)
- {
- ptrdiff_t index = ptr - pointer(0);
- size_t extra = index & (alignment - 1); // assumes 2^n alignment!
- if (extra > 0)
- extra = alignment - extra;
- return extra;
- }
-
- // TODO
- //template <class T>
- //T *create()
- //{
- // return cloneable::create<T>(*this);
- //}
- //template <class T, class A0>
- //T *create(A0 a0)
- //{
- // return cloneable::create<T>(*this, a0);
- //}
- //template <class T, class A0, class A1>
- //T *create(A0 a0, A1 a1)
- //{
- // return cloneable::create<T>(*this, a0, a1);
- //}
- };
+ namespace cloneable
+ {
+ /// base class for (wrapped) allocators to be used with cloneable::cloneable<>
+ /// by cloneable containers
+ struct abstract_allocator
+ {
+ typedef char *pointer;
+
+ virtual pointer allocate_bytes(size_t num_bytes, size_t alignment) = 0;
+
+ virtual void deallocate_bytes(pointer, size_t alignment) = 0;
+
+ static size_t calc_padding(pointer ptr, size_t alignment)
+ {
+ ptrdiff_t index = ptr - pointer(0);
+ size_t extra = index & (alignment - 1); // assumes 2^n alignment!
+ if (extra > 0)
+ extra = alignment - extra;
+ return extra;
+ }
+
+ // TODO
+ //template <class T>
+ //T *create()
+ //{
+ // return cloneable::create<T>(*this);
+ //}
+ //template <class T, class A0>
+ //T *create(A0 a0)
+ //{
+ // return cloneable::create<T>(*this, a0);
+ //}
+ //template <class T, class A0, class A1>
+ //T *create(A0 a0, A1 a1)
+ //{
+ // return cloneable::create<T>(*this, a0, a1);
+ //}
+ };
 
- } // namespace cloneable
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/abstract_base.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/abstract_base.hpp (original)
+++ sandbox/cloneable/boost/cloneable/abstract_base.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -15,154 +15,154 @@
 
 namespace boost
 {
- namespace cloneable
- {
- /// root structure for the cloneable object system
- template <class Base>
- struct abstract_base
- : virtual Base
- , virtual is_cloneable_tag
- {
- typedef Base base_type;
- typedef abstract_base<Base> this_type;
-
- virtual const std::type_info &get_type() const = 0;
-
- /// make storage for a new instance, but do not invoke any constructor
- virtual this_type *allocate(abstract_allocator &) const = 0;
-
- /// free memory associated with this instance.
- /// this is effectively 'delete this', but without a call to the destructor
- virtual void deallocate(abstract_allocator &) = 0;
-
- /// create a new object of the derived type
- virtual this_type *create_new(abstract_allocator &) const = 0;
-
- /// create a clone using copy-constructor. this is implemented in cloneable<>, but can
- /// be overriden by the user in the derived type if required.
- virtual this_type *copy_construct(abstract_allocator &) const = 0;
-
- /// optional means to make a clone that does not use copy-construction.
- /// user can overload this in their derived type to provide custom clone implementation.
- virtual this_type *make_copy(abstract_allocator &) const { return 0; }
-
- /// make a copy of the given instance. try the custom clone method first,
- /// then default to using the copy-constructor method
- this_type *clone(abstract_allocator &alloc) const
- {
- if (this_type *copy = make_copy(alloc))
- return copy;
- return copy_construct(alloc);
- }
-
- /// MUTABLE
- virtual this_type *make_copy(abstract_allocator &) { return 0; }
-
- /// MUTABLE
- this_type *clone(abstract_allocator &alloc)
- {
- if (this_type *copy = make_copy(alloc))
- return copy;
- const this_type *const_this = const_cast<const this_type *>(this);
- if (this_type *copy = const_this->make_copy(alloc))
- return copy;
- return const_this->copy_construct(alloc);
- }
-
- /// non-virtual method that allocates using default allocator
- this_type *allocate() const
- {
- make_clone_allocator<default_allocator>::type alloc;
- return allocate(alloc);
- }
-
- /// non-virtual method that deallocates using default allocator
- void deallocate() const
- {
- make_clone_allocator<default_allocator>::type alloc;
- return deallocate(alloc);
- }
-
- /// non-virtual method that creates a new instance of derived type using default allocator
- this_type *create() const
- {
- make_clone_allocator<default_allocator>::type alloc;
- return create_new(alloc);
- }
-
- /// non-virtual method that creates a new instance of derived type using given allocator
- template <class Alloc>
- this_type *create(Alloc &alloc) const
- {
- return create_new(alloc);
- }
-
- /// non-virtual method that creates a new instance of derived type from this instance,
- /// using copy-constructor and default allocator
- this_type *copy_construct() const
- {
- make_clone_allocator<default_allocator>::type alloc;
- return copy_construct(alloc);
- }
-
- /// make a copy of this instance using default allocator
- this_type *clone() const
- {
- make_clone_allocator<default_allocator>::type alloc;
- return clone(alloc);
- }
-
- // these non-virtuals require mixin<D,B> to be defined before they can be
- // implemented. See detail/mixin.hpp for their definitions
- template <class Derived>
- bool can_clone_as() const;
-
- template <class Derived>
- Derived *clone_as() const;
-
- template <class Derived>
- Derived *clone_as(abstract_allocator &) const;
-
- template <class Derived>
- bool can_create_as() const;
-
- template <class Derived>
- bool can_default_create_as() const;
- ///
-
- /// overridable to-string function, for utility
- virtual std::string to_string() const { return "cloneable"; }
-
- /// return a hash value for the object
- /*
- size_t hash() const
- {
- return base_type::hash_value();
- }
- */
-
- friend bool operator==(const abstract_base &left, const abstract_base &right)
- {
- return static_cast<const base_type &>(left) == static_cast<const base_type &>(right);
- }
- friend bool operator<(const abstract_base &left, const abstract_base &right)
- {
- return static_cast<const base_type &>(left) < static_cast<const base_type &>(right);
- }
- };
-
- } // namespace cloneable
-
- /*
- template <class B>
- struct hash<cloneable::abstract_base<B> >
- {
- size_t operator()(cloneable::abstract_base<B> const &base) const
- {
- return base.hash();
- }
- };
- */
+ namespace cloneable
+ {
+ /// root structure for the cloneable object system
+ template <class Base>
+ struct abstract_base
+ : virtual Base
+ , virtual is_cloneable_tag
+ {
+ typedef Base base_type;
+ typedef abstract_base<Base> this_type;
+
+ virtual const std::type_info &get_type() const = 0;
+
+ /// make storage for a new instance, but do not invoke any constructor
+ virtual this_type *allocate(abstract_allocator &) const = 0;
+
+ /// free memory associated with this instance.
+ /// this is effectively 'delete this', but without a call to the destructor
+ virtual void deallocate(abstract_allocator &) = 0;
+
+ /// create a new object of the derived type
+ virtual this_type *create_new(abstract_allocator &) const = 0;
+
+ /// create a clone using copy-constructor. this is implemented in cloneable<>, but can
+ /// be overriden by the user in the derived type if required.
+ virtual this_type *copy_construct(abstract_allocator &) const = 0;
+
+ /// optional means to make a clone that does not use copy-construction.
+ /// user can overload this in their derived type to provide custom clone implementation.
+ virtual this_type *make_copy(abstract_allocator &) const { return 0; }
+
+ /// make a copy of the given instance. try the custom clone method first,
+ /// then default to using the copy-constructor method
+ this_type *clone(abstract_allocator &alloc) const
+ {
+ if (this_type *copy = make_copy(alloc))
+ return copy;
+ return copy_construct(alloc);
+ }
+
+ /// MUTABLE
+ virtual this_type *make_copy(abstract_allocator &) { return 0; }
+
+ /// MUTABLE
+ this_type *clone(abstract_allocator &alloc)
+ {
+ if (this_type *copy = make_copy(alloc))
+ return copy;
+ const this_type *const_this = const_cast<const this_type *>(this);
+ if (this_type *copy = const_this->make_copy(alloc))
+ return copy;
+ return const_this->copy_construct(alloc);
+ }
+
+ /// non-virtual method that allocates using default allocator
+ this_type *allocate() const
+ {
+ make_clone_allocator<default_allocator>::type alloc;
+ return allocate(alloc);
+ }
+
+ /// non-virtual method that deallocates using default allocator
+ void deallocate() const
+ {
+ make_clone_allocator<default_allocator>::type alloc;
+ return deallocate(alloc);
+ }
+
+ /// non-virtual method that creates a new instance of derived type using default allocator
+ this_type *create() const
+ {
+ make_clone_allocator<default_allocator>::type alloc;
+ return create_new(alloc);
+ }
+
+ /// non-virtual method that creates a new instance of derived type using given allocator
+ template <class Alloc>
+ this_type *create(Alloc &alloc) const
+ {
+ return create_new(alloc);
+ }
+
+ /// non-virtual method that creates a new instance of derived type from this instance,
+ /// using copy-constructor and default allocator
+ this_type *copy_construct() const
+ {
+ make_clone_allocator<default_allocator>::type alloc;
+ return copy_construct(alloc);
+ }
+
+ /// make a copy of this instance using default allocator
+ this_type *clone() const
+ {
+ make_clone_allocator<default_allocator>::type alloc;
+ return clone(alloc);
+ }
+
+ // these non-virtuals require mixin<D,B> to be defined before they can be
+ // implemented. See detail/mixin.hpp for their definitions
+ template <class Derived>
+ bool can_clone_as() const;
+
+ template <class Derived>
+ Derived *clone_as() const;
+
+ template <class Derived>
+ Derived *clone_as(abstract_allocator &) const;
+
+ template <class Derived>
+ bool can_create_as() const;
+
+ template <class Derived>
+ bool can_default_create_as() const;
+ ///
+
+ /// overridable to-string function, for utility
+ virtual std::string to_string() const { return "cloneable"; }
+
+ /// return a hash value for the object
+ /*
+ size_t hash() const
+ {
+ return base_type::hash_value();
+ }
+ */
+
+ friend bool operator==(const abstract_base &left, const abstract_base &right)
+ {
+ return static_cast<const base_type &>(left) == static_cast<const base_type &>(right);
+ }
+ friend bool operator<(const abstract_base &left, const abstract_base &right)
+ {
+ return static_cast<const base_type &>(left) < static_cast<const base_type &>(right);
+ }
+ };
+
+ } // namespace cloneable
+
+ /*
+ template <class B>
+ struct hash<cloneable::abstract_base<B> >
+ {
+ size_t operator()(cloneable::abstract_base<B> const &base) const
+ {
+ return base.hash();
+ }
+ };
+ */
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/adaptor.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/adaptor.hpp (original)
+++ sandbox/cloneable/boost/cloneable/adaptor.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -11,49 +11,49 @@
 
 namespace boost
 {
- namespace cloneable
- {
- /// an adaptor for an existing class T, making it cloneable
- template <class T, class Base>
- struct adaptor : T, base<adaptor<T, Base>, Base>
- {
- adaptor() { }
- adaptor(const adaptor &X) : T(X), base<adaptor<T,Base>,Base>(X) { }
-
- template <class A0>
- adaptor(A0 a0) : T(a0)
- {
- }
- template <class A0, class A1>
- adaptor(A0 a0, A1 a1) : T(a0, a1)
- {
- }
- template <class A0, class A1, class A2>
- adaptor(A0 a0, A1 a1, A2 a2) : T(a0, a1, a2)
- {
- }
- };
-
- /// an adaptor for an existing class T, making it cloneable
- template <class T, class D, class Base>
- struct adaptor_base : T, base<adaptor<T, Base>, Base>
- {
- adaptor_base() { }
-
- template <class A0>
- adaptor_base(A0 a0) : T(a0)
- {
- }
- template <class A0, class A1>
- adaptor_base(A0 a0, A1 a1) : T(a0, a1)
- {
- }
- template <class A0, class A1, class A2>
- adaptor_base(A0 a0, A1 a1, A2 a2) : T(a0, a1, a2)
- {
- }
- };
- } // namespace cloneable
+ namespace cloneable
+ {
+ /// an adaptor for an existing class T, making it cloneable
+ template <class T, class Base>
+ struct adaptor : T, base<adaptor<T, Base>, Base>
+ {
+ adaptor() { }
+ adaptor(const adaptor &X) : T(X), base<adaptor<T,Base>,Base>(X) { }
+
+ template <class A0>
+ adaptor(A0 a0) : T(a0)
+ {
+ }
+ template <class A0, class A1>
+ adaptor(A0 a0, A1 a1) : T(a0, a1)
+ {
+ }
+ template <class A0, class A1, class A2>
+ adaptor(A0 a0, A1 a1, A2 a2) : T(a0, a1, a2)
+ {
+ }
+ };
+
+ /// an adaptor for an existing class T, making it cloneable
+ template <class T, class D, class Base>
+ struct adaptor_base : T, base<adaptor<T, Base>, Base>
+ {
+ adaptor_base() { }
+
+ template <class A0>
+ adaptor_base(A0 a0) : T(a0)
+ {
+ }
+ template <class A0, class A1>
+ adaptor_base(A0 a0, A1 a1) : T(a0, a1)
+ {
+ }
+ template <class A0, class A1, class A2>
+ adaptor_base(A0 a0, A1 a1, A2 a2) : T(a0, a1, a2)
+ {
+ }
+ };
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/allocator.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/allocator.hpp (original)
+++ sandbox/cloneable/boost/cloneable/allocator.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -11,148 +11,148 @@
 
 namespace boost
 {
- namespace cloneable
- {
- namespace impl
- {
- template <bool is_class>
- struct allocator
- {
- template <class Object, class Alloc>
- static Object *allocate_clone(const Object &orig, Alloc &alloc)
- {
- typename Alloc::template rebind<Object>::other al(alloc);
- ptr *clone = al.allocate(1);
- new (clone) (orig);
- return clone;
- }
- template <class Object, class Alloc>
- static void deallocate_clone(const Object *ptr, Alloc &alloc)
- {
- if (!ptr)
- return;
- typename Alloc::template rebind<Object>::other al(alloc);
- al.deallocate(const_cast<Object *>(ptr), 1);
- }
- };
- template <>
- struct allocator<true>
- {
- template <class Object, class Alloc>
- static Object *allocate_clone(const Object &orig, Alloc &alloc)
- {
- return orig.clone(alloc);
- }
-
- template <class Object, class Alloc>
- static void deallocate_clone(const Object *ptr, Alloc &alloc)
- {
- const_cast<Object *>(ptr)->deallocate(alloc);
- }
- };
- }
-
- /// a cloning allocator
- struct allocator
- {
- template <class Base>
- static Base* allocate_clone(const Base& orig)
- {
- make_clone_allocator<default_allocator> alloc;
- return impl::allocator<boost::is_class<Base>::value>::allocate_clone(orig, alloc);
- }
-
- template <class Base>
- static void deallocate_clone(const Base* clone)
- {
- if (!clone)
- return;
- impl::allocator<boost::is_class<Base>::value>::deallocate_clone(clone, alloc);
- }
-
- template <class Base, class Alloc>
- static Base* allocate_clone(const Base& object, Alloc &alloc )
- {
- return impl::allocator<boost::is_class<Base>::value>::allocate_clone(object, alloc);
- }
-
- template <class Base, class Alloc>
- static void deallocate_clone(const Base *object, Alloc &alloc )
- {
- impl::allocator<boost::is_class<Base>::value>::deallocate_clone(object, alloc);
- }
- };
-
- template <class T, class Alloc>
- T *allocate(Alloc &alloc)
- {
- typename Alloc::template rebind<T>::other al(alloc);
- return al.allocate(1);
- }
-
- template <class T>
- T *allocate(abstract_allocator &alloc)
- {
- abstract_allocator::pointer ptr = alloc.allocate_bytes(sizeof(T), aligned_storage<sizeof(T)>::alignment);
- return reinterpret_cast<T *>(ptr);
- }
-
- template <class T, class Alloc>
- T *create(Alloc &alloc)
- {
- typename Alloc::template rebind<T>::other al(alloc);
- T *ptr = al.allocate(1);
- al.construct(ptr);
- return ptr;
- }
-
- template <class T>
- T *create(abstract_allocator &alloc)
- {
- T *ptr = allocate<T>(alloc);
- new (ptr) T();
- return ptr;
- }
- template <class T, class A0>
- T *create(abstract_allocator &alloc, A0 a0)
- {
- T *ptr = allocate<T>(alloc);
- new (ptr) T(a0);
- return ptr;
- }
- template <class T, class A0, class A1>
- T *create(abstract_allocator &alloc, A0 a0, A1 a1)
- {
- T *ptr = allocate<T>(alloc);
- new (ptr) T(a0, a1);
- return ptr;
- }
-
- template <class T, class Alloc, class A0>
- T *create(Alloc &alloc, A0 a0)
- {
- typename Alloc::template rebind<T>::other al(alloc);
- T *ptr = al.allocate(1);
- new (ptr) T(a0);
- return ptr;
- }
- template <class T, class Alloc, class A0, class A1>
- T *create(Alloc &alloc, A0 a0, A1 a1)
- {
- typename Alloc::template rebind<T>::other al(alloc);
- T *ptr = al.allocate(1);
- new (ptr) T(a0, a1);
- return ptr;
- }
- template <class T, class Alloc>
- void release(T *ptr, Alloc &alloc)
- {
- typename Alloc::template rebind<T>::other al(alloc);
- al.destroy(ptr);
- al.deallocate(ptr, 1);
- }
+ namespace cloneable
+ {
+ namespace impl
+ {
+ template <bool is_class>
+ struct allocator
+ {
+ template <class Object, class Alloc>
+ static Object *allocate_clone(const Object &orig, Alloc &alloc)
+ {
+ typename Alloc::template rebind<Object>::other al(alloc);
+ ptr *clone = al.allocate(1);
+ new (clone) (orig);
+ return clone;
+ }
+ template <class Object, class Alloc>
+ static void deallocate_clone(const Object *ptr, Alloc &alloc)
+ {
+ if (!ptr)
+ return;
+ typename Alloc::template rebind<Object>::other al(alloc);
+ al.deallocate(const_cast<Object *>(ptr), 1);
+ }
+ };
+ template <>
+ struct allocator<true>
+ {
+ template <class Object, class Alloc>
+ static Object *allocate_clone(const Object &orig, Alloc &alloc)
+ {
+ return orig.clone(alloc);
+ }
+
+ template <class Object, class Alloc>
+ static void deallocate_clone(const Object *ptr, Alloc &alloc)
+ {
+ const_cast<Object *>(ptr)->deallocate(alloc);
+ }
+ };
+ }
+
+ /// a cloning allocator
+ struct allocator
+ {
+ template <class Base>
+ static Base* allocate_clone(const Base& orig)
+ {
+ make_clone_allocator<default_allocator> alloc;
+ return impl::allocator<boost::is_class<Base>::value>::allocate_clone(orig, alloc);
+ }
+
+ template <class Base>
+ static void deallocate_clone(const Base* clone)
+ {
+ if (!clone)
+ return;
+ impl::allocator<boost::is_class<Base>::value>::deallocate_clone(clone, alloc);
+ }
+
+ template <class Base, class Alloc>
+ static Base* allocate_clone(const Base& object, Alloc &alloc )
+ {
+ return impl::allocator<boost::is_class<Base>::value>::allocate_clone(object, alloc);
+ }
+
+ template <class Base, class Alloc>
+ static void deallocate_clone(const Base *object, Alloc &alloc )
+ {
+ impl::allocator<boost::is_class<Base>::value>::deallocate_clone(object, alloc);
+ }
+ };
+
+ template <class T, class Alloc>
+ T *allocate(Alloc &alloc)
+ {
+ typename Alloc::template rebind<T>::other al(alloc);
+ return al.allocate(1);
+ }
+
+ template <class T>
+ T *allocate(abstract_allocator &alloc)
+ {
+ abstract_allocator::pointer ptr = alloc.allocate_bytes(sizeof(T), aligned_storage<sizeof(T)>::alignment);
+ return reinterpret_cast<T *>(ptr);
+ }
+
+ template <class T, class Alloc>
+ T *create(Alloc &alloc)
+ {
+ typename Alloc::template rebind<T>::other al(alloc);
+ T *ptr = al.allocate(1);
+ al.construct(ptr);
+ return ptr;
+ }
+
+ template <class T>
+ T *create(abstract_allocator &alloc)
+ {
+ T *ptr = allocate<T>(alloc);
+ new (ptr) T();
+ return ptr;
+ }
+ template <class T, class A0>
+ T *create(abstract_allocator &alloc, A0 a0)
+ {
+ T *ptr = allocate<T>(alloc);
+ new (ptr) T(a0);
+ return ptr;
+ }
+ template <class T, class A0, class A1>
+ T *create(abstract_allocator &alloc, A0 a0, A1 a1)
+ {
+ T *ptr = allocate<T>(alloc);
+ new (ptr) T(a0, a1);
+ return ptr;
+ }
+
+ template <class T, class Alloc, class A0>
+ T *create(Alloc &alloc, A0 a0)
+ {
+ typename Alloc::template rebind<T>::other al(alloc);
+ T *ptr = al.allocate(1);
+ new (ptr) T(a0);
+ return ptr;
+ }
+ template <class T, class Alloc, class A0, class A1>
+ T *create(Alloc &alloc, A0 a0, A1 a1)
+ {
+ typename Alloc::template rebind<T>::other al(alloc);
+ T *ptr = al.allocate(1);
+ new (ptr) T(a0, a1);
+ return ptr;
+ }
+ template <class T, class Alloc>
+ void release(T *ptr, Alloc &alloc)
+ {
+ typename Alloc::template rebind<T>::other al(alloc);
+ al.destroy(ptr);
+ al.deallocate(ptr, 1);
+ }
 
- } // namespace cloneable
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/base.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/base.hpp (original)
+++ sandbox/cloneable/boost/cloneable/base.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -15,74 +15,74 @@
 
 namespace boost
 {
- namespace cloneable
- {
- namespace impl
- {
- using mpl::bool_;
- using mpl::if_;
- using mpl::or_;
-
- template <class Derived, class Base, class DefaultCtorTag>
- struct base
- : detail::mixin<Derived, Base>
- , virtual DefaultCtorTag
- {
- typedef Derived derived_type;
- typedef Base base_type;
- typedef DefaultCtorTag default_constructable_type, construction_tag_type;
- typedef base<derived_type, base_type, default_constructable_type> this_type;
-
- virtual this_type *create_new(abstract_allocator &alloc) const
- {
- // TODO: deal with conversion from bases with unknown_construction_tag
- return detail::create_new<Derived, DefaultCtorTag>::given(this, alloc, alignment);
- }
- };
-
- template <class T>
- struct is_nil : is_same<T,nil> { };
-
- template <class D, class A, class B>
- struct make_base
- {
- template <class T>
- struct get_base_type : if_<is_nil<T>, base_type, T> { };
-
- template <class T>
- struct get_default_construction_tag : if_<is_nil<T>, default_construction_tag, T> { };
-
- typedef is_convertible<A *, detail::tag *> a_is_tag;
- typedef is_convertible<B *, detail::tag *> b_is_tag;
-
- typedef typename if_<
- is_nil<A>
- , base<D, typename get_base_type<A>::type, typename get_default_construction_tag<B>::type>
- , base<D, typename get_base_type<B>::type, typename get_default_construction_tag<A>::type>
- >::type type1;
-
- typedef base<D, typename get_base_type<A>::type, typename get_default_construction_tag<B>::type> type;
- };
- }
-
- /// base for the given derived type, using the given base class and default construction tag
- template <class D, class A, class B>
- struct base : impl::make_base<D,A,B>::type
- {
- typedef typename impl::make_base<D,A,B>::type parent_type;
- typedef base<D,A,B> this_type;
- typedef typename parent_type::base_type base_type;
-
- BOOST_STATIC_ASSERT(is_cloneable<this_type>::value);
- };
-
- /*
- template <class Derived, class A, class B>
- struct base : impl::base<Derived,A,B>
- {
- };
- */
- } // namespace cloneable
+ namespace cloneable
+ {
+ namespace impl
+ {
+ using mpl::bool_;
+ using mpl::if_;
+ using mpl::or_;
+
+ template <class Derived, class Base, class DefaultCtorTag>
+ struct base
+ : detail::mixin<Derived, Base>
+ , virtual DefaultCtorTag
+ {
+ typedef Derived derived_type;
+ typedef Base base_type;
+ typedef DefaultCtorTag default_constructable_type, construction_tag_type;
+ typedef base<derived_type, base_type, default_constructable_type> this_type;
+
+ virtual this_type *create_new(abstract_allocator &alloc) const
+ {
+ // TODO: deal with conversion from bases with unknown_construction_tag
+ return detail::create_new<Derived, DefaultCtorTag>::given(this, alloc, alignment);
+ }
+ };
+
+ template <class T>
+ struct is_nil : is_same<T,nil> { };
+
+ template <class D, class A, class B>
+ struct make_base
+ {
+ template <class T>
+ struct get_base_type : if_<is_nil<T>, base_type, T> { };
+
+ template <class T>
+ struct get_default_construction_tag : if_<is_nil<T>, default_construction_tag, T> { };
+
+ typedef is_convertible<A *, detail::tag *> a_is_tag;
+ typedef is_convertible<B *, detail::tag *> b_is_tag;
+
+ typedef typename if_<
+ is_nil<A>
+ , base<D, typename get_base_type<A>::type, typename get_default_construction_tag<B>::type>
+ , base<D, typename get_base_type<B>::type, typename get_default_construction_tag<A>::type>
+ >::type type1;
+
+ typedef base<D, typename get_base_type<A>::type, typename get_default_construction_tag<B>::type> type;
+ };
+ }
+
+ /// base for the given derived type, using the given base class and default construction tag
+ template <class D, class A, class B>
+ struct base : impl::make_base<D,A,B>::type
+ {
+ typedef typename impl::make_base<D,A,B>::type parent_type;
+ typedef base<D,A,B> this_type;
+ typedef typename parent_type::base_type base_type;
+
+ BOOST_STATIC_ASSERT(is_cloneable<this_type>::value);
+ };
+
+ /*
+ template <class Derived, class A, class B>
+ struct base : impl::base<Derived,A,B>
+ {
+ };
+ */
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/base_type.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/base_type.hpp (original)
+++ sandbox/cloneable/boost/cloneable/base_type.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -13,48 +13,48 @@
 
 namespace boost
 {
- namespace cloneable
- {
- template <class T>
- struct abstract_object
- {
- typedef abstract_object<T> abstract_object_type;
-
- virtual std::string to_string() const { return "abstract_object<T>"; }
- virtual size_t hash_value() const { return 0; }
- virtual bool less(const abstract_object_type& other) const { return false; }
- virtual bool equiv(const abstract_object_type& other) const
- {
- return !less(other) && !other.less(static_cast<const T&>(*this));
- }
- };
-
- template <class T>
- inline bool operator<(const abstract_object<T>& left, const abstract_object<T>& right)
- {
- return left.less(right);
- }
-
- template <class T>
- inline bool operator==(const abstract_object<T>& left, const abstract_object<T>& right)
- {
- return left.equiv(right);
- }
-
- /// default base type used for object hierarchies. the user can supply their own when using
- /// cloneable<Derived, Base>.
- /// this will be used as a base by default.
- struct base_type : abstract_object<base_type>
- {
- virtual ~base_type() { }
-
- std::string to_string() const { return "base_type"; }
- size_t hash_value() const { return 0; }
- bool less(const base_type &other) const { return false; } // to_string() < other.to_string()
- bool equiv(const base_type &other) const { return true; } // to_string() == other.to_string()
- };
+ namespace cloneable
+ {
+ template <class T>
+ struct abstract_object
+ {
+ typedef abstract_object<T> abstract_object_type;
+
+ virtual std::string to_string() const { return "abstract_object<T>"; }
+ virtual size_t hash_value() const { return 0; }
+ virtual bool less(const abstract_object_type& other) const { return false; }
+ virtual bool equiv(const abstract_object_type& other) const
+ {
+ return !less(other) && !other.less(static_cast<const T&>(*this));
+ }
+ };
+
+ template <class T>
+ inline bool operator<(const abstract_object<T>& left, const abstract_object<T>& right)
+ {
+ return left.less(right);
+ }
+
+ template <class T>
+ inline bool operator==(const abstract_object<T>& left, const abstract_object<T>& right)
+ {
+ return left.equiv(right);
+ }
+
+ /// default base type used for object hierarchies. the user can supply their own when using
+ /// cloneable<Derived, Base>.
+ /// this will be used as a base by default.
+ struct base_type : abstract_object<base_type>
+ {
+ virtual ~base_type() { }
+
+ std::string to_string() const { return "base_type"; }
+ size_t hash_value() const { return 0; }
+ bool less(const base_type &other) const { return false; } // to_string() < other.to_string()
+ bool equiv(const base_type &other) const { return true; } // to_string() == other.to_string()
+ };
 
- } // namespace cloneable
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/clone.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/clone.hpp (original)
+++ sandbox/cloneable/boost/cloneable/clone.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -11,154 +11,154 @@
 
 namespace boost
 {
- namespace cloneable
- {
- namespace impl
- {
- /// implementation of cloning when using non-Cloneable types
- template <bool>
- struct clone
- {
- template <class T>
- static T *given(const T &original)
- {
- return new T(original);
- }
- template <class T, class Alloc>
- static T *given(const T &original, Alloc &alloc)
- {
- return create<T>(alloc, original);
- }
- template <class Derived, class Base, class Alloc>
- Derived *from_base(const Base &base, Alloc &alloc)
- {
- const Derived *derived = dynamic_cast<const Derived *>(&base);
- if (mixin == 0)
- throw std::bad_cast();
- return create<Derived>(alloc, *derived);
- }
- template <class Derived, class Base>
- static bool can_clone_as(const Base &base)
- {
- const Derived *derived = dynamic_cast<const Derived *>(&base);
- return derived != 0;
- }
- };
-
- /// implementation of cloneing using Cloneable types
- template <>
- struct clone<true>
- {
- template <class T>
- static T *given(const T &original)
- {
- return original.clone_as<T>();
- }
- template <class T, class Alloc>
- static T *given(const T &original, Alloc &alloc)
- {
- return original.clone_as<T>(alloc);
- }
- template <class Derived, class Base, class Alloc>
- static Derived *from_base(const Base &base, Alloc &alloc)
- {
- typedef detail::mixin<Derived,Base> mixin_type;
- const mixin_type *mixin = dynamic_cast<const mixin_type *>(&base);
- if (mixin == 0)
- throw std::bad_cast();
- return mixin->clone_as<Derived>(alloc);
- }
- template <class Derived, class Base>
- static Derived *from_base(const Base &base)
- {
- make_clone_allocator<default_allocator>::type alloc;
- return from_base<Derived>(base, alloc);
- }
-
- template <class Derived, class Base>
- static bool can_clone_as(const Base &base)
- {
- typedef is_same<Derived, Base> same;
- if (same::value)
- return true;
- if (clone<false>::can_clone_as<Derived>(base))
- return true;
- typedef detail::mixin<Derived,Base> mixin_type;
- return dynamic_cast<const mixin_type *>(&base) != 0;
- }
- template <class Derived, class Base>
- static bool can_create_as(const Base &base)
- {
- typedef is_same<Derived, Base> same;
- if (same::value)
- return true;
- if (clone<false>::can_create_as<Derived>(base))
- return true;
- return dynamic_cast<abstract_base<Base> const &>(base).can_create_as<Derived>();
- }
- };
-
- } // namespace impl
-
- /// free-function clone that works for cloneable and also default types
- template <class T>
- T *clone(const T &original)
- {
- return impl::clone<is_cloneable<T>::value>::given(original);
- }
-
- /// free-function clone that works for cloneable and also default types, given allocator
- template <class T, class Alloc>
- T *clone(const T &original, Alloc &alloc)
- {
- return impl::clone<is_cloneable<T>::value>::given(original, alloc);
- }
-
- template <class Derived, class Base>
- bool can_clone_as(const Base &base)
- {
- return impl::clone<is_cloneable<Base>::value>::can_clone_as<Derived>(base);
- }
-
- template <class Derived, class Base>
- bool can_create_as(const Base &base)
- {
- return impl::clone<is_cloneable<Base>::value>::can_create_as<Derived>(base);
- }
-
- /// clone as a specified derived type, from a base type
- template <class Derived, class Base>
- Derived *clone_as(const Base &original)
- {
- return impl::clone<true>::from_base<Derived>(original);
- }
-
- /// clone as a specified derived type, from a base type, given allocator
- template <class Derived, class Base, class Alloc>
- Derived *clone_as(const Base &original, Alloc &alloc)
- {
- return impl::clone<true>::from_base<Derived>(original, alloc);
- }
-
- template <class Base>
- Base *create_new(const Base &base)
- {
- const abstract_base<Base> *abst = dynamic_cast<const abstract_base<Base> *>(&base);
- if (abst == 0)
- throw not_cloneable();
- return abst->create();
- }
-
- template <class Base, class Alloc>
- Base *create_new(const Base &base, Alloc &alloc)
- {
- const abstract_base<Base> *abst = dynamic_cast<const abstract_base<Base> *>(&base);
- if (abst == 0)
- throw not_cloneable();
- return abst->create_new(alloc);
- }
+ namespace cloneable
+ {
+ namespace impl
+ {
+ /// implementation of cloning when using non-Cloneable types
+ template <bool>
+ struct clone
+ {
+ template <class T>
+ static T *given(const T &original)
+ {
+ return new T(original);
+ }
+ template <class T, class Alloc>
+ static T *given(const T &original, Alloc &alloc)
+ {
+ return create<T>(alloc, original);
+ }
+ template <class Derived, class Base, class Alloc>
+ Derived *from_base(const Base &base, Alloc &alloc)
+ {
+ const Derived *derived = dynamic_cast<const Derived *>(&base);
+ if (mixin == 0)
+ throw std::bad_cast();
+ return create<Derived>(alloc, *derived);
+ }
+ template <class Derived, class Base>
+ static bool can_clone_as(const Base &base)
+ {
+ const Derived *derived = dynamic_cast<const Derived *>(&base);
+ return derived != 0;
+ }
+ };
+
+ /// implementation of cloneing using Cloneable types
+ template <>
+ struct clone<true>
+ {
+ template <class T>
+ static T *given(const T &original)
+ {
+ return original.clone_as<T>();
+ }
+ template <class T, class Alloc>
+ static T *given(const T &original, Alloc &alloc)
+ {
+ return original.clone_as<T>(alloc);
+ }
+ template <class Derived, class Base, class Alloc>
+ static Derived *from_base(const Base &base, Alloc &alloc)
+ {
+ typedef detail::mixin<Derived,Base> mixin_type;
+ const mixin_type *mixin = dynamic_cast<const mixin_type *>(&base);
+ if (mixin == 0)
+ throw std::bad_cast();
+ return mixin->clone_as<Derived>(alloc);
+ }
+ template <class Derived, class Base>
+ static Derived *from_base(const Base &base)
+ {
+ make_clone_allocator<default_allocator>::type alloc;
+ return from_base<Derived>(base, alloc);
+ }
+
+ template <class Derived, class Base>
+ static bool can_clone_as(const Base &base)
+ {
+ typedef is_same<Derived, Base> same;
+ if (same::value)
+ return true;
+ if (clone<false>::can_clone_as<Derived>(base))
+ return true;
+ typedef detail::mixin<Derived,Base> mixin_type;
+ return dynamic_cast<const mixin_type *>(&base) != 0;
+ }
+ template <class Derived, class Base>
+ static bool can_create_as(const Base &base)
+ {
+ typedef is_same<Derived, Base> same;
+ if (same::value)
+ return true;
+ if (clone<false>::can_create_as<Derived>(base))
+ return true;
+ return dynamic_cast<abstract_base<Base> const &>(base).can_create_as<Derived>();
+ }
+ };
+
+ } // namespace impl
+
+ /// free-function clone that works for cloneable and also default types
+ template <class T>
+ T *clone(const T &original)
+ {
+ return impl::clone<is_cloneable<T>::value>::given(original);
+ }
+
+ /// free-function clone that works for cloneable and also default types, given allocator
+ template <class T, class Alloc>
+ T *clone(const T &original, Alloc &alloc)
+ {
+ return impl::clone<is_cloneable<T>::value>::given(original, alloc);
+ }
+
+ template <class Derived, class Base>
+ bool can_clone_as(const Base &base)
+ {
+ return impl::clone<is_cloneable<Base>::value>::can_clone_as<Derived>(base);
+ }
+
+ template <class Derived, class Base>
+ bool can_create_as(const Base &base)
+ {
+ return impl::clone<is_cloneable<Base>::value>::can_create_as<Derived>(base);
+ }
+
+ /// clone as a specified derived type, from a base type
+ template <class Derived, class Base>
+ Derived *clone_as(const Base &original)
+ {
+ return impl::clone<true>::from_base<Derived>(original);
+ }
+
+ /// clone as a specified derived type, from a base type, given allocator
+ template <class Derived, class Base, class Alloc>
+ Derived *clone_as(const Base &original, Alloc &alloc)
+ {
+ return impl::clone<true>::from_base<Derived>(original, alloc);
+ }
+
+ template <class Base>
+ Base *create_new(const Base &base)
+ {
+ const abstract_base<Base> *abst = dynamic_cast<const abstract_base<Base> *>(&base);
+ if (abst == 0)
+ throw not_cloneable();
+ return abst->create();
+ }
+
+ template <class Base, class Alloc>
+ Base *create_new(const Base &base, Alloc &alloc)
+ {
+ const abstract_base<Base> *abst = dynamic_cast<const abstract_base<Base> *>(&base);
+ if (abst == 0)
+ throw not_cloneable();
+ return abst->create_new(alloc);
+ }
 
- } // namespace cloneable
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/detail/allocation.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/detail/allocation.hpp (original)
+++ sandbox/cloneable/boost/cloneable/detail/allocation.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -12,51 +12,51 @@
 
 namespace boost
 {
- namespace cloneable
- {
- /*
- namespace detail
- {
- // TODO: use variadic template arguments, or BOOST_PP
-
- template <class U, class Base, class Alloc>
- pointer<U,Base,Alloc> construct(Alloc &al)
- {
- pointer<U,Base,Alloc> ptr(al);
- ptr.construct();
- return ptr;
- }
-
- template <class U, class Base, class Alloc, class A0>
- pointer<U,Base,Alloc> construct(Alloc &al, A0 a0)
- {
- pointer<U,Base,Alloc> ptr(al);
- new (ptr.to_derived()) U(a0);
- return ptr;
- }
-
- template <class U, class Base, class Alloc, class A0, class A1>
- pointer<U,Base,Alloc> construct(Alloc &al, A0 a0, A1 a1)
- {
- pointer<U,Base,Alloc> ptr(al);
- new (ptr.to_derived()) U(a0, a1);
- return ptr;
- }
-
- template <class U, class Base, class Alloc, class A0, class A1, class A2>
- pointer<U,Base,Alloc> construct(Alloc &al, A0 a0, A1 a1, A2 a2)
- {
- pointer<U,Base,Alloc> ptr(al);
- new (ptr.to_derived()) U(a0, a1, a2);
- return ptr;
- }
+ namespace cloneable
+ {
+ /*
+ namespace detail
+ {
+ // TODO: use variadic template arguments, or BOOST_PP
+
+ template <class U, class Base, class Alloc>
+ pointer<U,Base,Alloc> construct(Alloc &al)
+ {
+ pointer<U,Base,Alloc> ptr(al);
+ ptr.construct();
+ return ptr;
+ }
+
+ template <class U, class Base, class Alloc, class A0>
+ pointer<U,Base,Alloc> construct(Alloc &al, A0 a0)
+ {
+ pointer<U,Base,Alloc> ptr(al);
+ new (ptr.to_derived()) U(a0);
+ return ptr;
+ }
+
+ template <class U, class Base, class Alloc, class A0, class A1>
+ pointer<U,Base,Alloc> construct(Alloc &al, A0 a0, A1 a1)
+ {
+ pointer<U,Base,Alloc> ptr(al);
+ new (ptr.to_derived()) U(a0, a1);
+ return ptr;
+ }
+
+ template <class U, class Base, class Alloc, class A0, class A1, class A2>
+ pointer<U,Base,Alloc> construct(Alloc &al, A0 a0, A1 a1, A2 a2)
+ {
+ pointer<U,Base,Alloc> ptr(al);
+ new (ptr.to_derived()) U(a0, a1, a2);
+ return ptr;
+ }
 
- // etc...
+ // etc...
 
- } // namespace detail
- */
+ } // namespace detail
+ */
 
- } // namespace cloneable
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/detail/associative_container_base.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/detail/associative_container_base.hpp (original)
+++ sandbox/cloneable/boost/cloneable/detail/associative_container_base.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -12,131 +12,131 @@
 
 namespace boost
 {
- namespace cloneable
- {
- namespace detail
- {
- /// common base for associative containers
- template <class Cont, class Pred, class Base, class Alloc>
- struct associative_container_base
- : container_base<Cont,Base,Alloc>
- {
- typedef container_base<Cont,Base,Alloc> parent_type;
- typedef Pred predicate_type;
-
- using parent_type::container_type;
- using parent_type::base_type;
- using parent_type::abstract_base_type;
- using parent_type::allocator_type;
- using parent_type::validate;
- using parent_type::new_instance;
- using parent_type::instance;
-
- using parent_type::iterator;
- using parent_type::const_iterator;
- using parent_type::reference;
- using parent_type::const_reference;
- using parent_type::value_type;
-
- private:
- predicate_type predicate;
- container_type container;
-
- protected:
- const container_type &impl() const
- {
- return container;
- }
- container_type &impl()
- {
- return container;
- }
-
- public:
- associative_container_base()
- {
- }
- associative_container_base(predicate_type p)
- : predicate(p), container(p)
- {
- }
- associative_container_base(allocator_type &a)
- : parent_type(a), container(a)
- {
- }
- associative_container_base(predicate_type p, allocator_type &a)
- : parent_type(a), predicate(p), container(p,a)
- {
- }
- template <class II>
- associative_container_base(II F, II L, predicate_type pred = predicate_type())
- : predicate(pred), container(F,L)
- {
- }
-
- template <class II>
- associative_container_base(II F, II L, allocator_type &a)
- : parent_type(a), container(F,L)
- {
- }
- template <class II>
- associative_container_base(II F, II L, predicate_type pred, allocator_type &a)
- : parent_type(a), predicate(pred), container(F,L)
- {
- }
-
- size_t size() const
- {
- return impl().size();
- }
- bool empty() const
- {
- return impl().empty();
- }
-
- iterator begin()
- {
- return impl().begin();
- }
- iterator end()
- {
- return impl().end();
- }
- const_iterator begin() const
- {
- return impl().begin();
- }
- const_iterator end() const
- {
- return impl().end();
- }
-
- template <class Fun>
- Fun for_each(Fun fun)
- {
- BOOST_FOREACH(value_type &value, *this)
- {
- fun(value);
- }
- }
-
- };
-
- template <class Cont, class Pred, class Base, class Alloc>
- bool operator==(const associative_container_base<Cont,Pred,Base,Alloc> &left, const associative_container_base<Cont,Pred,Base,Alloc> &right)
- {
- return left.size() == right.size() && std::equal(left.begin(), left.end(), right.begin());
- }
-
- template <class Cont, class Pred, class Base, class Alloc>
- bool operator<(const associative_container_base<Cont,Pred,Base,Alloc> &left, const associative_container_base<Cont,Pred,Base,Alloc> &right)
- {
- return std::lexicographical_compare(left.begin(), left.end(), right.begin(), right.end());
- }
+ namespace cloneable
+ {
+ namespace detail
+ {
+ /// common base for associative containers
+ template <class Cont, class Pred, class Base, class Alloc>
+ struct associative_container_base
+ : container_base<Cont,Base,Alloc>
+ {
+ typedef container_base<Cont,Base,Alloc> parent_type;
+ typedef Pred predicate_type;
+
+ using parent_type::container_type;
+ using parent_type::base_type;
+ using parent_type::abstract_base_type;
+ using parent_type::allocator_type;
+ using parent_type::validate;
+ using parent_type::new_instance;
+ using parent_type::instance;
+
+ using parent_type::iterator;
+ using parent_type::const_iterator;
+ using parent_type::reference;
+ using parent_type::const_reference;
+ using parent_type::value_type;
+
+ private:
+ predicate_type predicate;
+ container_type container;
+
+ protected:
+ const container_type &impl() const
+ {
+ return container;
+ }
+ container_type &impl()
+ {
+ return container;
+ }
+
+ public:
+ associative_container_base()
+ {
+ }
+ associative_container_base(predicate_type p)
+ : predicate(p), container(p)
+ {
+ }
+ associative_container_base(allocator_type &a)
+ : parent_type(a), container(a)
+ {
+ }
+ associative_container_base(predicate_type p, allocator_type &a)
+ : parent_type(a), predicate(p), container(p,a)
+ {
+ }
+ template <class II>
+ associative_container_base(II F, II L, predicate_type pred = predicate_type())
+ : predicate(pred), container(F,L)
+ {
+ }
+
+ template <class II>
+ associative_container_base(II F, II L, allocator_type &a)
+ : parent_type(a), container(F,L)
+ {
+ }
+ template <class II>
+ associative_container_base(II F, II L, predicate_type pred, allocator_type &a)
+ : parent_type(a), predicate(pred), container(F,L)
+ {
+ }
+
+ size_t size() const
+ {
+ return impl().size();
+ }
+ bool empty() const
+ {
+ return impl().empty();
+ }
+
+ iterator begin()
+ {
+ return impl().begin();
+ }
+ iterator end()
+ {
+ return impl().end();
+ }
+ const_iterator begin() const
+ {
+ return impl().begin();
+ }
+ const_iterator end() const
+ {
+ return impl().end();
+ }
+
+ template <class Fun>
+ Fun for_each(Fun fun)
+ {
+ BOOST_FOREACH(value_type &value, *this)
+ {
+ fun(value);
+ }
+ }
+
+ };
+
+ template <class Cont, class Pred, class Base, class Alloc>
+ bool operator==(const associative_container_base<Cont,Pred,Base,Alloc> &left, const associative_container_base<Cont,Pred,Base,Alloc> &right)
+ {
+ return left.size() == right.size() && std::equal(left.begin(), left.end(), right.begin());
+ }
+
+ template <class Cont, class Pred, class Base, class Alloc>
+ bool operator<(const associative_container_base<Cont,Pred,Base,Alloc> &left, const associative_container_base<Cont,Pred,Base,Alloc> &right)
+ {
+ return std::lexicographical_compare(left.begin(), left.end(), right.begin(), right.end());
+ }
 
- } // namespace detail
+ } // namespace detail
 
- } // namespace cloneable
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/detail/container_base.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/detail/container_base.hpp (original)
+++ sandbox/cloneable/boost/cloneable/detail/container_base.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -11,125 +11,125 @@
 #include <boost/cloneable/instance.hpp>
 #include <boost/cloneable/traits.hpp>
 
-#define BOOST_CLONEABLE_SCOPE_EXIT(locals) \
- this_type *self = this; \
- BOOST_SCOPE_EXIT(locals(self))
+#define BOOST_CLONEABLE_SCOPE_EXIT(locals) \
+ this_type *self = this; \
+ BOOST_SCOPE_EXIT(locals(self))
 
 #define BOOST_CLONEABLE_SCOPE_EXIT_END \
- BOOST_SCOPE_EXIT_END
+ BOOST_SCOPE_EXIT_END
 
 namespace boost
 {
- namespace cloneable
- {
- namespace detail
- {
- /// common functionality for all containers using the given base and allocator types
- template <class Cont, class Base, class Alloc>
- struct container_base
- {
- typedef Cont container_type;
- typedef Base base_type;
- typedef abstract_base<base_type> abstract_base_type;
- typedef typename detail::make_clone_allocator<Alloc>::type allocator_type;
- typedef instance_base<Base, allocator_type> instance_base_type;
-
- typedef typename container_type::value_type value_type;
- typedef typename container_type::reference reference;
- typedef typename container_type::const_reference const_reference;
- typedef typename container_type::iterator iterator;
- typedef typename container_type::const_iterator const_iterator;
-
- /// ensures that the given type T is a valid type for this container.
- /// this provides better information from errors than otherwise.
- template <class T>
- struct validate
- {
- // can only add cloneable things to a heterogenous container.
- // to make a type T cloneable, derive from cloneable::base<T>,
- // or provide your own base-type Base and derive from cloneable::base<T,Base>.
- // there is no restriction on the Base type.
- BOOST_STATIC_ASSERT(is_cloneable<T>::value);
-
- // you must ensure that base-types for objects that you add to a container
- // is the same base used by the container
- typedef is_convertible<T *, base_type *> has_base_type;
- BOOST_STATIC_ASSERT(has_base_type::value);
-
- typedef T type;
- };
-
- /// an instance of the given derived type suitable for this container
- template <class Derived>
- struct instance
- : cloneable::instance<
- typename validate<Derived>::type
- , Base
- , Alloc
- , typename traits<typename validate<Derived>::type>::construction_tag>
- {
- typedef typename validate<Derived>::type derived_type;
- typedef cloneable::instance<derived_type, Base, Alloc, typename traits<derived_type>::construction_tag> parent_type;
-
- instance(allocator_type &a) : parent_type(a) { }
-
- template <class A0>
- instance(allocator_type &a, A0 a0) : parent_type(a, a0) { }
-
- template <class A0, class A1>
- instance(allocator_type &a, A0 a0, A1 a1) : parent_type(a, a0, a1) { }
-
- template <class A0, class A1, class A2>
- instance(allocator_type &a, A0 a0, A1 a1, A2 a2) : parent_type(a, a0, a1, a2) { }
- };
-
- private:
- allocator_type alloc;
-
- protected:
- template <class U>
- instance<U> new_instance()
- {
- return instance<U>(get_allocator());
- }
- template <class U, class A0>
- instance<U> new_instance(A0 a0)
- {
- return instance<U>(get_allocator(), a0);
- }
- template <class U, class A0, class A1>
- instance<U> new_instance(A0 a0, A1 a1)
- {
- return instance<U>(get_allocator(), a0, a1);
- }
- template <class U, class A0, class A1, class A2>
- instance<U> new_instance(A0 a0, A1 a1, A2 a2)
- {
- return instance<U>(get_allocator(), a0, a1, a2);
- }
-
- public:
- container_base()
- {
- }
- container_base(allocator_type &a)
- : alloc(a)
- {
- }
-
- const allocator_type &get_allocator() const
- {
- return alloc;
- }
- allocator_type &get_allocator()
- {
- return alloc;
- }
- };
+ namespace cloneable
+ {
+ namespace detail
+ {
+ /// common functionality for all containers using the given base and allocator types
+ template <class Cont, class Base, class Alloc>
+ struct container_base
+ {
+ typedef Cont container_type;
+ typedef Base base_type;
+ typedef abstract_base<base_type> abstract_base_type;
+ typedef typename detail::make_clone_allocator<Alloc>::type allocator_type;
+ typedef instance_base<Base, allocator_type> instance_base_type;
+
+ typedef typename container_type::value_type value_type;
+ typedef typename container_type::reference reference;
+ typedef typename container_type::const_reference const_reference;
+ typedef typename container_type::iterator iterator;
+ typedef typename container_type::const_iterator const_iterator;
+
+ /// ensures that the given type T is a valid type for this container.
+ /// this provides better information from errors than otherwise.
+ template <class T>
+ struct validate
+ {
+ // can only add cloneable things to a heterogenous container.
+ // to make a type T cloneable, derive from cloneable::base<T>,
+ // or provide your own base-type Base and derive from cloneable::base<T,Base>.
+ // there is no restriction on the Base type.
+ BOOST_STATIC_ASSERT(is_cloneable<T>::value);
+
+ // you must ensure that base-types for objects that you add to a container
+ // is the same base used by the container
+ typedef is_convertible<T *, base_type *> has_base_type;
+ BOOST_STATIC_ASSERT(has_base_type::value);
+
+ typedef T type;
+ };
+
+ /// an instance of the given derived type suitable for this container
+ template <class Derived>
+ struct instance
+ : cloneable::instance<
+ typename validate<Derived>::type
+ , Base
+ , allocator_type
+ , typename traits<typename validate<Derived>::type>::construction_tag>
+ {
+ typedef typename validate<Derived>::type derived_type;
+ typedef cloneable::instance<derived_type, Base, allocator_type, typename traits<derived_type>::construction_tag> parent_type;
+
+ instance(allocator_type &a) : parent_type(a) { }
+
+ template <class A0>
+ instance(allocator_type &a, A0 a0) : parent_type(a, a0) { }
+
+ template <class A0, class A1>
+ instance(allocator_type &a, A0 a0, A1 a1) : parent_type(a, a0, a1) { }
+
+ template <class A0, class A1, class A2>
+ instance(allocator_type &a, A0 a0, A1 a1, A2 a2) : parent_type(a, a0, a1, a2) { }
+ };
+
+ private:
+ allocator_type alloc;
+
+ protected:
+ template <class U>
+ instance<U> new_instance()
+ {
+ return instance<U>(get_allocator());
+ }
+ template <class U, class A0>
+ instance<U> new_instance(A0 a0)
+ {
+ return instance<U>(get_allocator(), a0);
+ }
+ template <class U, class A0, class A1>
+ instance<U> new_instance(A0 a0, A1 a1)
+ {
+ return instance<U>(get_allocator(), a0, a1);
+ }
+ template <class U, class A0, class A1, class A2>
+ instance<U> new_instance(A0 a0, A1 a1, A2 a2)
+ {
+ return instance<U>(get_allocator(), a0, a1, a2);
+ }
+
+ public:
+ container_base()
+ {
+ }
+ container_base(allocator_type &a)
+ : alloc(a)
+ {
+ }
+
+ const allocator_type &get_allocator() const
+ {
+ return alloc;
+ }
+ allocator_type &get_allocator()
+ {
+ return alloc;
+ }
+ };
 
- } // namespace detail
+ } // namespace detail
 
- } // namespace cloneable
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/detail/create_new.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/detail/create_new.hpp (original)
+++ sandbox/cloneable/boost/cloneable/detail/create_new.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -11,51 +11,51 @@
 
 namespace boost
 {
- namespace cloneable
- {
- namespace detail
- {
- template <class Derived, class HasDefaultCtor>
- struct create_new
- {
- template <class Self, class Alloc>
- static Derived *given(Self *self, Alloc &alloc, size_t alignment)
- {
- abstract_allocator::pointer bytes = alloc.allocate_bytes(sizeof(Derived), alignment);
- Derived *ptr = reinterpret_cast<Derived *>(bytes);
- ptr->Self::self_ptr = ptr;
- new (ptr->Self::self_ptr) Derived();
- return ptr;
- }
- };
- template <class Derived>
- struct create_new<Derived, no_default_construction_tag>
- {
- template <class Self, class Alloc>
- static Derived *given(Self *self, Alloc &alloc, size_t alignment)
- {
- throw no_default_construction();
- }
- };
-
- // TODO: deal with conversion from bases with unknown_construction_tag
-
- template <class Derived>
- struct create_new<Derived, unknown_construction_tag>
- {
- template <class Self, class Alloc>
- static Derived *given(Self *self, Alloc &alloc, size_t alignment)
- {
- abstract_allocator::pointer bytes = alloc.allocate_bytes(sizeof(Derived), alignment);
- Derived *ptr = reinterpret_cast<Derived *>(bytes);
- ptr->Self::self_ptr = ptr;
- new (ptr->Self::self_ptr) Derived(Derived());
- return ptr;
- }
- };
- } // namespace detail
+ namespace cloneable
+ {
+ namespace detail
+ {
+ template <class Derived, class HasDefaultCtor>
+ struct create_new
+ {
+ template <class Self, class Alloc>
+ static Derived *given(Self *self, Alloc &alloc, size_t alignment)
+ {
+ abstract_allocator::pointer bytes = alloc.allocate_bytes(sizeof(Derived), alignment);
+ Derived *ptr = reinterpret_cast<Derived *>(bytes);
+ ptr->Self::self_ptr = ptr;
+ new (ptr->Self::self_ptr) Derived();
+ return ptr;
+ }
+ };
+ template <class Derived>
+ struct create_new<Derived, no_default_construction_tag>
+ {
+ template <class Self, class Alloc>
+ static Derived *given(Self *self, Alloc &alloc, size_t alignment)
+ {
+ throw no_default_construction();
+ }
+ };
+
+ // TODO: deal with conversion from bases with unknown_construction_tag
+
+ template <class Derived>
+ struct create_new<Derived, unknown_construction_tag>
+ {
+ template <class Self, class Alloc>
+ static Derived *given(Self *self, Alloc &alloc, size_t alignment)
+ {
+ abstract_allocator::pointer bytes = alloc.allocate_bytes(sizeof(Derived), alignment);
+ Derived *ptr = reinterpret_cast<Derived *>(bytes);
+ ptr->Self::self_ptr = ptr;
+ new (ptr->Self::self_ptr) Derived(Derived());
+ return ptr;
+ }
+ };
+ } // namespace detail
 
- } // namespace cloneable
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/detail/make_clone_allocator.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/detail/make_clone_allocator.hpp (original)
+++ sandbox/cloneable/boost/cloneable/detail/make_clone_allocator.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -12,88 +12,128 @@
 
 namespace boost
 {
- namespace cloneable
- {
- namespace detail
- {
- namespace impl
- {
- /// 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
- {
- typedef typename Alloc::template rebind<char>::other CharAlloc;
-
- clone_allocator() { }
- clone_allocator(Alloc &a) : Alloc(a) { }
-
- struct header
- {
- abstract_allocator::pointer allocated_ptr;
- size_t num_bytes;
- };
-
- abstract_allocator::pointer allocate_bytes(size_t num_bytes, size_t /*alignment*/)
- {
- CharAlloc alloc(*this);
- return alloc.allocate(num_bytes);
-
- // TODO: do correct alignment, store padding information so dealloc
- // can retrieve the originally allocated pointer
-
- //CharAlloc alloc(*this);
- //header head;
- //head.num_bytes = sizeof(header) + num_bytes + alignment; // don't need this much, but will do for now
- //abstract_allocator::pointer char_ptr = alloc.allocate(head.num_bytes);
- //head.allocated_ptr = (header *)char_ptr;
- //*head.allocated_ptr = head;
- //abstract_allocator::pointer base = char_ptr + sizeof(header);
- //base += calc_padding(base, alignment);
- //return base;
- }
-
- void deallocate_bytes(abstract_allocator::pointer ptr, size_t /*alignment*/)
- {
- CharAlloc alloc(*this);
- alloc.deallocate(ptr, 1);
-
- // TODO: retreive the originally allocated pointer
-
- //header *head = reinterpret_cast<header *>(ptr - sizeof(head));
- //alloc.deallocate(head->allocated_ptr, head->num_bytes);
- }
-
- };
-
- template <class Alloc, bool>
- struct make_clone_allocator
- {
- typedef clone_allocator<Alloc> type;
- };
-
- template <class Alloc>
- struct make_clone_allocator<Alloc, true>
- {
- typedef Alloc type;
- };
- }
-
- template <class Alloc>
- struct make_clone_allocator
- {
- typedef boost::is_convertible<Alloc *, abstract_allocator *> is_convertible;
- BOOST_STATIC_CONSTANT(bool, is_clone_alloc = is_convertible::value);
- typedef typename impl::make_clone_allocator<Alloc, is_clone_alloc>::type type;
- };
+ namespace cloneable
+ {
+ namespace detail
+ {
+ namespace impl
+ {
+ /// adapts a given Alloc type, modelling the v1 std::allocator concept, to provide
+ /// services required by abstract_allocator
+ template <class Alloc>
+ struct clone_allocator : abstract_allocator
+ {
+ template <class Ty>
+ struct rebind
+ {
+ typedef typename Alloc::template rebind<Ty>::other other_alloc;
+ typedef clone_allocator<other_alloc> other;
+ };
+
+ typedef typename Alloc::template rebind<char>::other CharAlloc;
+
+ typedef typename Alloc::size_type size_type;
+ typedef typename Alloc::difference_type difference_type;
+ typedef typename Alloc::pointer pointer;
+ typedef typename Alloc::const_pointer const_pointer;
+ typedef typename Alloc::reference reference;
+ typedef typename Alloc::const_reference const_reference;
+ typedef typename Alloc::value_type value_type;
+
+ Alloc alloc;
+ clone_allocator() { }
+ template <class Other>
+ clone_allocator(const clone_allocator<Other> &other) : alloc(other.alloc) { }
+ clone_allocator(Alloc a) : alloc(a) { }
+
+ struct header
+ {
+ abstract_allocator::pointer allocated_ptr;
+ size_t num_bytes;
+ };
+
+ void destroy(pointer p, size_t = 1)
+ {
+ alloc.destroy(p);
+ }
+ void deallocate(pointer p, size_t n = 1)
+ {
+ alloc.deallocate(p, n);
+ }
+ pointer allocate(size_t n)
+ {
+ return alloc.allocate(n);
+ }
+ //template <class Init>
+ void construct(pointer p, const_reference init)
+ {
+ new (p) value_type(init);
+ }
+ size_t max_size() const
+ {
+ return alloc.max_size();
+ }
+
+ abstract_allocator::pointer allocate_bytes(size_t num_bytes, size_t /*alignment*/)
+ {
+ CharAlloc alloc;//(*this);
+ return alloc.allocate(num_bytes);
+
+ // TODO: do correct alignment, store padding information so dealloc
+ // can retrieve the originally allocated pointer
+
+ //CharAlloc alloc(*this);
+ //header head;
+ //head.num_bytes = sizeof(header) + num_bytes + alignment; // don't need this much, but will do for now
+ //abstract_allocator::pointer char_ptr = alloc.allocate(head.num_bytes);
+ //head.allocated_ptr = (header *)char_ptr;
+ //*head.allocated_ptr = head;
+ //abstract_allocator::pointer base = char_ptr + sizeof(header);
+ //base += calc_padding(base, alignment);
+ //return base;
+ }
+
+ void deallocate_bytes(abstract_allocator::pointer ptr, size_t /*alignment*/)
+ {
+ CharAlloc alloc;//(*this);
+ alloc.deallocate(ptr, 1);
+
+ // TODO: retreive the originally allocated pointer
+
+ //header *head = reinterpret_cast<header *>(ptr - sizeof(head));
+ //alloc.deallocate(head->allocated_ptr, head->num_bytes);
+ }
+
+ };
+
+ template <class Alloc, bool>
+ struct make_clone_allocator
+ {
+ typedef clone_allocator<Alloc> type;
+ };
+
+ template <class Alloc>
+ struct make_clone_allocator<Alloc, true>
+ {
+ typedef Alloc type;
+ };
+ }
+
+ template <class Alloc>
+ struct make_clone_allocator
+ {
+ typedef boost::is_convertible<Alloc *, abstract_allocator *> is_convertible;
+ BOOST_STATIC_CONSTANT(bool, is_clone_alloc = is_convertible::value);
+ typedef typename impl::make_clone_allocator<Alloc, is_clone_alloc>::type type;
+ };
 
- } // namespace detail
+ } // namespace detail
 
- using detail::make_clone_allocator;
+ using detail::make_clone_allocator;
 
- typedef make_clone_allocator<default_allocator> default_clone_allocator;
+ typedef make_clone_allocator<default_allocator> default_clone_allocator;
 
- } // namespace cloneable
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/detail/mixin.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/detail/mixin.hpp (original)
+++ sandbox/cloneable/boost/cloneable/detail/mixin.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -12,157 +12,157 @@
 
 namespace boost
 {
- namespace cloneable
- {
- namespace detail
- {
- // mixin structure between base<> and abstract_base<> that supplies
- // an interface to allow casting, cloning and creation of sub-objects
- // of different types and default-constructableness
- template <class Derived, class Base>
- struct mixin
- : abstract_base<Base>
- {
- typedef Derived derived_type;
- typedef Base base_type;
- typedef abstract_base<base_type> abstract_base_type;
- typedef mixin<derived_type, base_type> this_type;
-
- mutable Derived *self_ptr; ///< pointer to derived object in this
- static const size_t alignment; ///< required alignment for allocation
-
- mixin()
- {
- self_ptr = static_cast<derived_type *>(this);
- }
-
- const std::type_info &get_type() const
- {
- return typeid(derived_type);
- }
-
- template <class T>
- bool can_clone_as() const
- {
- return dynamic_cast<const mixin<T, Base> *>(this) != 0;
- }
-
- virtual this_type *allocate(abstract_allocator &alloc) const
- {
- abstract_allocator::pointer bytes = alloc.allocate_bytes(sizeof(derived_type), alignment);
- Derived *ptr = reinterpret_cast<Derived *>(bytes);
- ptr->this_type::self_ptr = ptr;
- return ptr;
- }
-
- void deallocate(abstract_allocator &alloc)
- {
- Derived *ptr = self_ptr;
- alloc.deallocate_bytes(reinterpret_cast<abstract_allocator::pointer>(ptr), alignment);
- }
-
- virtual this_type *copy_construct(abstract_allocator &alloc) const
- {
- abstract_allocator::pointer bytes = alloc.allocate_bytes(sizeof(derived_type), alignment);
- Derived *ptr = reinterpret_cast<Derived *>(bytes);
- ptr->this_type::self_ptr = ptr;
- new (ptr->this_type::self_ptr) Derived(static_cast<const Derived &>(*this));
- return ptr;
- }
- /// for use with types that use multiple inheritance - select which sub-object to clone.
- /// can also be used when there is just one cloneable sub-object to avoid having to
- /// dynamic cast the result.
- template <class Ty>
- Ty *clone_as(abstract_allocator &alloc) const
- {
- const mixin<Ty,Base> *ptr = dynamic_cast<const mixin<Ty,Base> *>(this);
- if (ptr == 0)
- throw std::bad_cast();
- abstract_base_type *cloned = ptr->clone(alloc);
- return dynamic_cast<Ty *>(cloned);
- }
-
- /// make a copy of this instance using default allocator,
- /// selecting sub-object to clone
- template <class Ty>
- Ty *clone_as() const
- {
- make_clone_allocator<default_allocator>::type alloc;
- return clone_as<Ty>(alloc);
- }
-
- template <class Ty>
- Ty *create_as(abstract_allocator &alloc) const
- {
- typedef mixin<Ty, Base> Embedded;
- const Embedded *cross_cast = dynamic_cast<const Embedded *>(this);
- if (cross_cast == 0)
- throw std::bad_cast();
- abstract_base_type *base = cross_cast->create_new(alloc);
- return static_cast<Ty *>(static_cast<Embedded *>(base));
- }
-
- template <class Ty>
- Ty *create_as() const
- {
- make_clone_allocator<default_allocator>::type alloc;
- return create_as<Ty>(alloc);
- }
- };
-
- /// ensure correct alignment when allocating derived instances
- template <class Derived, class Base>
- const size_t mixin<Derived, Base>::alignment = aligned_storage<sizeof(Derived)>::alignment;
-
- } // namespace detail
-
- /// now that we have the mixin<D,B> definition, define the abstract_base<B>::method<D>() implementations
- template <class Base>
- template <class Derived>
- bool abstract_base<Base>::can_clone_as() const
- {
- typedef detail::mixin<Derived,Base> mixin_type;
- return dynamic_cast<const mixin_type *>(this) != 0;
- }
-
- template <class Base>
- template <class Derived>
- bool abstract_base<Base>::can_create_as() const
- {
- typedef detail::mixin<Derived,Base> mixin_type;
- return dynamic_cast<const mixin_type *>(this) != 0;
- }
-
- template <class Base>
- template <class Derived>
- bool abstract_base<Base>::can_default_create_as() const
- {
- return traits<Derived>::has_default_ctor && can_create_as<Derived>();
- }
-
- template <class Base>
- template <class Derived>
- Derived *abstract_base<Base>::clone_as(abstract_allocator &alloc) const
- {
- typedef detail::mixin<Derived,Base> mixin_type;
- const mixin_type *mixin = dynamic_cast<const mixin_type *>(this);
- if (mixin == 0)
- throw std::bad_cast();
- return mixin->clone_as<Derived>(alloc);
- }
-
- template <class Base>
- template <class Derived>
- Derived *abstract_base<Base>::clone_as() const
- {
- typedef detail::mixin<Derived,Base> mixin_type;
- const mixin_type *mixin = dynamic_cast<const mixin_type *>(this);
- if (mixin == 0)
- throw std::bad_cast();
- return mixin->clone_as<Derived>();
- }
+ namespace cloneable
+ {
+ namespace detail
+ {
+ // mixin structure between base<> and abstract_base<> that supplies
+ // an interface to allow casting, cloning and creation of sub-objects
+ // of different types and default-constructableness
+ template <class Derived, class Base>
+ struct mixin
+ : abstract_base<Base>
+ {
+ typedef Derived derived_type;
+ typedef Base base_type;
+ typedef abstract_base<base_type> abstract_base_type;
+ typedef mixin<derived_type, base_type> this_type;
+
+ mutable Derived *self_ptr; ///< pointer to derived object in this
+ static const size_t alignment; ///< required alignment for allocation
+
+ mixin()
+ {
+ self_ptr = static_cast<derived_type *>(this);
+ }
+
+ const std::type_info &get_type() const
+ {
+ return typeid(derived_type);
+ }
+
+ template <class T>
+ bool can_clone_as() const
+ {
+ return dynamic_cast<const mixin<T, Base> *>(this) != 0;
+ }
+
+ virtual this_type *allocate(abstract_allocator &alloc) const
+ {
+ abstract_allocator::pointer bytes = alloc.allocate_bytes(sizeof(derived_type), alignment);
+ Derived *ptr = reinterpret_cast<Derived *>(bytes);
+ ptr->this_type::self_ptr = ptr;
+ return ptr;
+ }
+
+ void deallocate(abstract_allocator &alloc)
+ {
+ Derived *ptr = self_ptr;
+ alloc.deallocate_bytes(reinterpret_cast<abstract_allocator::pointer>(ptr), alignment);
+ }
+
+ virtual this_type *copy_construct(abstract_allocator &alloc) const
+ {
+ abstract_allocator::pointer bytes = alloc.allocate_bytes(sizeof(derived_type), alignment);
+ Derived *ptr = reinterpret_cast<Derived *>(bytes);
+ ptr->this_type::self_ptr = ptr;
+ new (ptr->this_type::self_ptr) Derived(static_cast<const Derived &>(*this));
+ return ptr;
+ }
+ /// for use with types that use multiple inheritance - select which sub-object to clone.
+ /// can also be used when there is just one cloneable sub-object to avoid having to
+ /// dynamic cast the result.
+ template <class Ty>
+ Ty *clone_as(abstract_allocator &alloc) const
+ {
+ const mixin<Ty,Base> *ptr = dynamic_cast<const mixin<Ty,Base> *>(this);
+ if (ptr == 0)
+ throw std::bad_cast();
+ abstract_base_type *cloned = ptr->clone(alloc);
+ return dynamic_cast<Ty *>(cloned);
+ }
+
+ /// make a copy of this instance using default allocator,
+ /// selecting sub-object to clone
+ template <class Ty>
+ Ty *clone_as() const
+ {
+ make_clone_allocator<default_allocator>::type alloc;
+ return clone_as<Ty>(alloc);
+ }
+
+ template <class Ty>
+ Ty *create_as(abstract_allocator &alloc) const
+ {
+ typedef mixin<Ty, Base> Embedded;
+ const Embedded *cross_cast = dynamic_cast<const Embedded *>(this);
+ if (cross_cast == 0)
+ throw std::bad_cast();
+ abstract_base_type *base = cross_cast->create_new(alloc);
+ return static_cast<Ty *>(static_cast<Embedded *>(base));
+ }
+
+ template <class Ty>
+ Ty *create_as() const
+ {
+ make_clone_allocator<default_allocator>::type alloc;
+ return create_as<Ty>(alloc);
+ }
+ };
+
+ /// ensure correct alignment when allocating derived instances
+ template <class Derived, class Base>
+ const size_t mixin<Derived, Base>::alignment = aligned_storage<sizeof(Derived)>::alignment;
+
+ } // namespace detail
+
+ /// now that we have the mixin<D,B> definition, define the abstract_base<B>::method<D>() implementations
+ template <class Base>
+ template <class Derived>
+ bool abstract_base<Base>::can_clone_as() const
+ {
+ typedef detail::mixin<Derived,Base> mixin_type;
+ return dynamic_cast<const mixin_type *>(this) != 0;
+ }
+
+ template <class Base>
+ template <class Derived>
+ bool abstract_base<Base>::can_create_as() const
+ {
+ typedef detail::mixin<Derived,Base> mixin_type;
+ return dynamic_cast<const mixin_type *>(this) != 0;
+ }
+
+ template <class Base>
+ template <class Derived>
+ bool abstract_base<Base>::can_default_create_as() const
+ {
+ return traits<Derived>::has_default_ctor && can_create_as<Derived>();
+ }
+
+ template <class Base>
+ template <class Derived>
+ Derived *abstract_base<Base>::clone_as(abstract_allocator &alloc) const
+ {
+ typedef detail::mixin<Derived,Base> mixin_type;
+ const mixin_type *mixin = dynamic_cast<const mixin_type *>(this);
+ if (mixin == 0)
+ throw std::bad_cast();
+ return mixin->clone_as<Derived>(alloc);
+ }
+
+ template <class Base>
+ template <class Derived>
+ Derived *abstract_base<Base>::clone_as() const
+ {
+ typedef detail::mixin<Derived,Base> mixin_type;
+ const mixin_type *mixin = dynamic_cast<const mixin_type *>(this);
+ if (mixin == 0)
+ throw std::bad_cast();
+ return mixin->clone_as<Derived>();
+ }
 
- } // namespace cloneable
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/detail/prefix.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/detail/prefix.hpp (original)
+++ sandbox/cloneable/boost/cloneable/detail/prefix.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -4,32 +4,32 @@
 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
 #ifndef BOOST_CONFIG_HPP
-# include <boost/config.hpp>
-# include <boost/detail/workaround.hpp>
+# include <boost/config.hpp>
+# include <boost/detail/workaround.hpp>
 #endif
 
 
 #if defined(BOOST_MSVC)
-# pragma warning(push)
-# pragma warning(disable:4127) // Conditional expression is constant.
-# pragma warning(disable:4130) // Logical operation on address of string constant.
-# pragma warning(disable:4224) // Parameter previously defined as type.
-# pragma warning(disable:4244) // Conversion: possible loss of data.
-# pragma warning(disable:4512) // Assignment operator could not be generated.
-# pragma warning(disable:4706) // Assignment within conditional expression.
-# pragma warning(disable:4996) // Function call with parameters that may be unsafe
+# pragma warning(push)
+# pragma warning(disable:4127) // Conditional expression is constant.
+# pragma warning(disable:4130) // Logical operation on address of string constant.
+# pragma warning(disable:4224) // Parameter previously defined as type.
+# pragma warning(disable:4244) // Conversion: possible loss of data.
+# pragma warning(disable:4512) // Assignment operator could not be generated.
+# pragma warning(disable:4706) // Assignment within conditional expression.
+# pragma warning(disable:4996) // Function call with parameters that may be unsafe
 #else
-# if BOOST_WORKAROUND(__BORLANDC__, < 0x600)
-# pragma warn -8008 // Condition always true/false.
-# pragma warn -8066 // Unreachable code.
-# pragma warn -8071 // Conversion may lose significant digits.
-# pragma warn -8072 // Suspicious pointer arithmetic.
-# pragma warn -8080 // identifier declared but never used.
-# endif
+# if BOOST_WORKAROUND(__BORLANDC__, < 0x600)
+# pragma warn -8008 // Condition always true/false.
+# pragma warn -8066 // Unreachable code.
+# pragma warn -8071 // Conversion may lose significant digits.
+# pragma warn -8072 // Suspicious pointer arithmetic.
+# pragma warn -8080 // identifier declared but never used.
+# endif
 #endif
 
 #ifndef BOOST_CLONEABLE_FORWARD_DECLARATIONS_HPP
-# include <boost/cloneable/forward_declarations.hpp>
+# include <boost/cloneable/forward_declarations.hpp>
 #endif
 
 //EOF

Modified: sandbox/cloneable/boost/cloneable/detail/sequence_container_base.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/detail/sequence_container_base.hpp (original)
+++ sandbox/cloneable/boost/cloneable/detail/sequence_container_base.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -12,200 +12,201 @@
 
 namespace boost
 {
- namespace cloneable
- {
- namespace detail
- {
- /// common base for sequence containers
- template <class Cont, class Base, class Alloc>
- struct sequence_container_base : container_base<Cont,Base,Alloc>
- {
- typedef Cont container_type;
- typedef container_base<Cont,Base,Alloc> parent_type;
- using parent_type::base_type;
- using parent_type::abstract_base_type;
- using parent_type::allocator_type;
- using parent_type::validate;
- using parent_type::new_instance;
- using parent_type::instance;
-
- using parent_type::iterator;
- using parent_type::const_iterator;
- using parent_type::reference;
- using parent_type::const_reference;
- using parent_type::value_type;
-
- private:
- container_type container;
-
- protected:
- const container_type &impl() const
- {
- return container;
- }
- container_type &impl()
- {
- return container;
- }
-
- public:
- sequence_container_base()
- {
- }
- sequence_container_base(allocator_type &a)
- : container(a)
- {
- }
-
- template <class Ty, class Fun>
- Fun for_each(Fun fun)
- {
- BOOST_FOREACH(base_type &b, *this)
- {
- if (Ty *ptr = dynamic_cast<Ty *>(&b))
- {
- fun(*ptr);
- }
- }
- return fun;
- }
-
- template <class Ty, class Fun>
- Fun for_each(Fun fun) const
- {
- BOOST_FOREACH(const base_type &base, *this)
- {
- if (Ty *ptr = dynamic_cast<Ty *>(&base))
- {
- fun(*ptr);
- }
- }
- return fun;
- }
-
- size_t size() const
- {
- return container.size();
- }
-
- bool empty() const
- {
- return impl().empty();
- }
-
- iterator begin()
- {
- return impl().begin();
- }
- iterator end()
- {
- return impl().end();
- }
- const_iterator begin() const
- {
- return impl().begin();
- }
- const_iterator end() const
- {
- return impl().end();
- }
-
- reference back()
- {
- return impl().back();
- }
- const_reference back() const
- {
- return impl().back();
- }
- reference front()
- {
- return impl().front();
- }
- const_reference front() const
- {
- return impl().front();
- }
-
- template <class Other>
- Other &back_as()
- {
- BOOST_STATIC_ASSERT(is_cloneable<Other>::value);
- Other *ptr = dynamic_cast<Other *>(back());
- if (ptr == 0)
- throw std::bad_cast();
- return *ptr;
- }
- template <class Other>
- Other &front_as()
- {
- BOOST_STATIC_ASSERT(is_cloneable<Other>::value);
- Other *ptr = dynamic_cast<Other *>(front());
- if (ptr == 0)
- throw std::bad_cast();
- return *ptr;
- }
-
- // TODO: use variadic arguments or BOOST_PP to pass ctor args
- template <class U>
- void push_back()
- {
- impl().push_back(new_instance<typename validate<U>::type>().to_abstract());
- }
- template <class U, class A0>
- void push_back(A0 a0)
- {
- impl().push_back(new_instance<typename validate<U>::type>(a0).to_abstract());
- }
- template <class U, class A0, class A1>
- void push_back(A0 a0, A1 a1)
- {
- impl().push_back(new_instance<typename validate<U>::type>(a0,a1).to_abstract());
- }
- template <class U, class A0, class A1, class A2>
- void push_back(A0 a0, A1 a1, A2 a2)
- {
- impl().push_back(new_instance<typename validate<U>::type>(a0,a1,a2).to_abstract());
- }
-
-
- template <class U>
- void push_front()
- {
- impl().push_front(new_instance<typename validate<U>::type>().to_abstract());
- }
- template <class U, class A0>
- void push_front(A0 a0)
- {
- impl().push_front(new_instance<typename validate<U>::type>(a0).to_abstract());
- }
- template <class U, class A0, class A1>
- void push_front(A0 a0, A1 a1)
- {
- impl().push_front(new_instance<typename validate<U>::type>(a0,a1).to_abstract());
- }
- template <class U, class A0, class A1, class A2>
- void push_front(A0 a0, A1 a1, A2 a2)
- {
- impl().push_front(new_instance<typename validate<U>::type>(a0,a1,a2).to_abstract());
- }
- };
-
- template <class Cont, class Base, class Alloc>
- bool operator==(const sequence_container_base<Cont,Base,Alloc> &left, const sequence_container_base<Cont,Base,Alloc> &right)
- {
- return left.size() == right.size() && std::equal(left.begin(), left.end(), right.begin());
- }
-
- template <class Cont, class Base, class Alloc>
- bool operator<(const sequence_container_base<Cont,Base,Alloc> &left, const sequence_container_base<Cont,Base,Alloc> &right)
- {
- return std::lexicographical_compare(left.begin(), left.end(), right.begin(), right.end());
- }
+ namespace cloneable
+ {
+ namespace detail
+ {
+ /// common base for sequence containers
+ template <class Cont, class Base, class Alloc>
+ struct sequence_container_base
+ : container_base<Cont,Base,Alloc>
+ {
+ typedef Cont container_type;
+ typedef container_base<Cont,Base,Alloc> parent_type;
+ using parent_type::base_type;
+ using parent_type::abstract_base_type;
+ using parent_type::allocator_type;
+ using parent_type::validate;
+ using parent_type::new_instance;
+ using parent_type::instance;
+
+ using parent_type::iterator;
+ using parent_type::const_iterator;
+ using parent_type::reference;
+ using parent_type::const_reference;
+ using parent_type::value_type;
+
+ private:
+ container_type container;
+
+ protected:
+ const container_type &impl() const
+ {
+ return container;
+ }
+ container_type &impl()
+ {
+ return container;
+ }
+
+ public:
+ sequence_container_base()
+ {
+ }
+ sequence_container_base(allocator_type &a)
+ : container(a)
+ {
+ }
+
+ template <class Ty, class Fun>
+ Fun for_each(Fun fun)
+ {
+ BOOST_FOREACH(base_type &b, *this)
+ {
+ if (Ty *ptr = dynamic_cast<Ty *>(&b))
+ {
+ fun(*ptr);
+ }
+ }
+ return fun;
+ }
+
+ template <class Ty, class Fun>
+ Fun for_each(Fun fun) const
+ {
+ BOOST_FOREACH(const base_type &base, *this)
+ {
+ if (Ty *ptr = dynamic_cast<Ty *>(&base))
+ {
+ fun(*ptr);
+ }
+ }
+ return fun;
+ }
+
+ size_t size() const
+ {
+ return container.size();
+ }
+
+ bool empty() const
+ {
+ return impl().empty();
+ }
+
+ iterator begin()
+ {
+ return impl().begin();
+ }
+ iterator end()
+ {
+ return impl().end();
+ }
+ const_iterator begin() const
+ {
+ return impl().begin();
+ }
+ const_iterator end() const
+ {
+ return impl().end();
+ }
+
+ reference back()
+ {
+ return impl().back();
+ }
+ const_reference back() const
+ {
+ return impl().back();
+ }
+ reference front()
+ {
+ return impl().front();
+ }
+ const_reference front() const
+ {
+ return impl().front();
+ }
+
+ template <class Other>
+ Other &back_as()
+ {
+ BOOST_STATIC_ASSERT(is_cloneable<Other>::value);
+ Other *ptr = dynamic_cast<Other *>(back());
+ if (ptr == 0)
+ throw std::bad_cast();
+ return *ptr;
+ }
+ template <class Other>
+ Other &front_as()
+ {
+ BOOST_STATIC_ASSERT(is_cloneable<Other>::value);
+ Other *ptr = dynamic_cast<Other *>(front());
+ if (ptr == 0)
+ throw std::bad_cast();
+ return *ptr;
+ }
+
+ // TODO: use variadic arguments or BOOST_PP to pass ctor args
+ template <class U>
+ void push_back()
+ {
+ impl().push_back(new_instance<U>().to_abstract());
+ }
+ template <class U, class A0>
+ void push_back(A0 a0)
+ {
+ impl().push_back(new_instance<U>(a0).to_abstract());
+ }
+ template <class U, class A0, class A1>
+ void push_back(A0 a0, A1 a1)
+ {
+ impl().push_back(new_instance<U>(a0,a1).to_abstract());
+ }
+ template <class U, class A0, class A1, class A2>
+ void push_back(A0 a0, A1 a1, A2 a2)
+ {
+ impl().push_back(new_instance<U>(a0,a1,a2).to_abstract());
+ }
+
+
+ template <class U>
+ void push_front()
+ {
+ impl().push_front(new_instance<U>().to_abstract());
+ }
+ template <class U, class A0>
+ void push_front(A0 a0)
+ {
+ impl().push_front(new_instance<U>(a0).to_abstract());
+ }
+ template <class U, class A0, class A1>
+ void push_front(A0 a0, A1 a1)
+ {
+ impl().push_front(new_instance<U>(a0,a1).to_abstract());
+ }
+ template <class U, class A0, class A1, class A2>
+ void push_front(A0 a0, A1 a1, A2 a2)
+ {
+ impl().push_front(new_instance<U>(a0,a1,a2).to_abstract());
+ }
+ };
+
+ template <class Cont, class Base, class Alloc>
+ bool operator==(const sequence_container_base<Cont,Base,Alloc> &left, const sequence_container_base<Cont,Base,Alloc> &right)
+ {
+ return left.size() == right.size() && std::equal(left.begin(), left.end(), right.begin());
+ }
+
+ template <class Cont, class Base, class Alloc>
+ bool operator<(const sequence_container_base<Cont,Base,Alloc> &left, const sequence_container_base<Cont,Base,Alloc> &right)
+ {
+ return std::lexicographical_compare(left.begin(), left.end(), right.begin(), right.end());
+ }
 
- } // namespace detail
+ } // namespace detail
 
- } // namespace cloneable
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/exception.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/exception.hpp (original)
+++ sandbox/cloneable/boost/cloneable/exception.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -10,23 +10,23 @@
 #include <boost/cloneable/detail/prefix.hpp>
 
 #define BOOST_CLONEABLE_EXCEPTION_0(name) \
- class name : public std::exception \
- { \
- public: \
- name( const char* what = BOOST_PP_STRINGIZE(name) ) : std::exception( what ) \
- { } \
- }
+ class name : public std::exception \
+ { \
+ public: \
+ name( const char* what = BOOST_PP_STRINGIZE(name) ) : std::exception( what ) \
+ { } \
+ }
 
 namespace boost
 {
- namespace cloneable
- {
- BOOST_CLONEABLE_EXCEPTION_0(empty_object);
- BOOST_CLONEABLE_EXCEPTION_0(empty_allocator);
- BOOST_CLONEABLE_EXCEPTION_0(no_default_construction);
- BOOST_CLONEABLE_EXCEPTION_0(not_cloneable);
+ namespace cloneable
+ {
+ BOOST_CLONEABLE_EXCEPTION_0(empty_object);
+ BOOST_CLONEABLE_EXCEPTION_0(empty_allocator);
+ BOOST_CLONEABLE_EXCEPTION_0(no_default_construction);
+ BOOST_CLONEABLE_EXCEPTION_0(not_cloneable);
 
- }
+ }
 }
 
 #include <boost/cloneable/detail/suffix.hpp>

Modified: sandbox/cloneable/boost/cloneable/forward_declarations.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/forward_declarations.hpp (original)
+++ sandbox/cloneable/boost/cloneable/forward_declarations.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -16,143 +16,143 @@
 
 namespace boost
 {
- namespace cloneable
- {
- /// allocator to use for clone or create operations when no allocator is provided
- typedef std::allocator<char> default_allocator;
-
- /// an abstract interface for an allocator that can allocate and de-allocate
- /// byte sequences
- struct abstract_allocator;
-
- /// empty structure with a virtual destructor used if the user does not
- /// wish to use a custom base type
- struct base_type;
-
- typedef base_type default_base_type;
-
- namespace detail
- {
- struct tag { };
-
- template <size_t N>
- struct bit_tag : tag
- {
- BOOST_STATIC_CONSTANT(size_t, bit = (1<<N));
- };
- }
-
- struct any_derived_tag : detail::bit_tag<0> { };
- struct any_base_tag : detail::bit_tag<1> { };
-
- /// {@ tags to inform about default-constructability
- struct default_construction_tag : detail::bit_tag<2> {};
- struct no_default_construction_tag : detail::bit_tag<3> {};
- struct unknown_construction_tag : detail::bit_tag<4> {};
- /// @}
-
- /// provides a set of pure-virtual methods for allocation, de-allocation, and cloning
- template <class Base = base_type>
- struct abstract_base;
-
- struct is_cloneable_tag { };
-
- struct nil { };
-
- /// a structure derived from this, with type Derived, is correctly
- /// cloneable from a base pointer, given an abstract_allocator.
- /// TODO: allow Ctor and Base to be given in any order
- template <
- class Derived
- , class Base = base_type
- , class DefaultConstructionTag = default_construction_tag
- //, class Base = nil//base_type
- //, class DefaultConstructionTag = nil//default_construction
- >
- struct base;
-
- template <
- class Derived = any_derived_tag
- , class Base = typename Derived::base_type
- , class Alloc = default_allocator
- , class Ctor = typename Derived::construction_tag_type
- >
- struct instance;
-
-
- /// an adaptor for an existing class.
- ///
- /// this is a type that can be used correctly in an homogenous container,
- /// of effective type T, where T does not inherit from heterogenous::base.
- template <
- class T
- , class Base = base_type>
- struct adaptor;
-
- // TODO: move to boost/heterogenous/foward
- /// a heterogenous vector of objects
- template
- <
- class Base = base_type
- , class Alloc = monotonic::allocator<int>
- >
- struct vector;
-
- /// a heterogenous list of objects
- template
- <
- class Base = base_type
- , class Alloc = monotonic::allocator<int>
- >
- struct list;
-
- // TODO: use ptr_container::detail::indirect_fun<>
- template <class Fun>
- struct indirect
- {
- Fun fun;
-
- indirect() { }
- indirect(Fun F) : fun(F) { }
-
- template <class Left, class Right>
- //typename result_of< Fun(typename pointee<Left>::type, typename pointee<Right>::type) >::type
- bool
- operator()(const Left &left, const Right &right) const
- {
- return fun(*left, *right);
- }
- };
-
- /// a mapping of Key to heterogenous object
- template
- <
- class Key
- , class Base = base_type
- , class Pred = std::less<Key>
- , class Alloc = monotonic::allocator<int>
- >
- struct map;
-
- /// a mapping of heterogenous object to heterogenous object
- template
- <
- class Base = base_type
- , class Pred = indirect<std::less<Base> >
- , class Alloc = monotonic::allocator<int>
- >
- struct heterogenous_map;
-
- /// a set of heterogenous objects
- template
- <
- class Base = base_type
- , class Pred = std::less<Base>
- , class Alloc = monotonic::allocator<int>
- >
- struct set;
+ namespace cloneable
+ {
+ /// allocator to use for clone or create operations when no allocator is provided
+ typedef std::allocator<char> default_allocator;
+
+ /// an abstract interface for an allocator that can allocate and de-allocate
+ /// byte sequences
+ struct abstract_allocator;
+
+ /// empty structure with a virtual destructor used if the user does not
+ /// wish to use a custom base type
+ struct base_type;
+
+ typedef base_type default_base_type;
+
+ namespace detail
+ {
+ struct tag { };
+
+ template <size_t N>
+ struct bit_tag : tag
+ {
+ BOOST_STATIC_CONSTANT(size_t, bit = (1<<N));
+ };
+ }
+
+ struct any_derived_tag : detail::bit_tag<0> { };
+ struct any_base_tag : detail::bit_tag<1> { };
+
+ /// {@ tags to inform about default-constructability
+ struct default_construction_tag : detail::bit_tag<2> {};
+ struct no_default_construction_tag : detail::bit_tag<3> {};
+ struct unknown_construction_tag : detail::bit_tag<4> {};
+ /// @}
+
+ /// provides a set of pure-virtual methods for allocation, de-allocation, and cloning
+ template <class Base = base_type>
+ struct abstract_base;
+
+ struct is_cloneable_tag { };
+
+ struct nil { };
+
+ /// a structure derived from this, with type Derived, is correctly
+ /// cloneable from a base pointer, given an abstract_allocator.
+ /// TODO: allow Ctor and Base to be given in any order
+ template <
+ class Derived
+ , class Base = base_type
+ , class DefaultConstructionTag = default_construction_tag
+ //, class Base = nil//base_type
+ //, class DefaultConstructionTag = nil//default_construction
+ >
+ struct base;
+
+ template <
+ class Derived = any_derived_tag
+ , class Base = typename Derived::base_type
+ , class Alloc = default_allocator
+ , class Ctor = typename Derived::construction_tag_type
+ >
+ struct instance;
+
+
+ /// an adaptor for an existing class.
+ ///
+ /// this is a type that can be used correctly in an homogenous container,
+ /// of effective type T, where T does not inherit from heterogenous::base.
+ template <
+ class T
+ , class Base = base_type>
+ struct adaptor;
+
+ // TODO: move to boost/heterogenous/foward
+ /// a heterogenous vector of objects
+ template
+ <
+ class Base = base_type
+ , class Alloc = default_allocator
+ >
+ struct vector;
+
+ /// a heterogenous list of objects
+ template
+ <
+ class Base = base_type
+ , class Alloc = default_allocator
+ >
+ struct list;
+
+ // TODO: use ptr_container::detail::indirect_fun<>
+ template <class Fun>
+ struct indirect
+ {
+ Fun fun;
+
+ indirect() { }
+ indirect(Fun F) : fun(F) { }
+
+ template <class Left, class Right>
+ //typename result_of< Fun(typename pointee<Left>::type, typename pointee<Right>::type) >::type
+ bool
+ operator()(const Left &left, const Right &right) const
+ {
+ return fun(*left, *right);
+ }
+ };
+
+ /// a mapping of Key to heterogenous object
+ template
+ <
+ class Key
+ , class Base = base_type
+ , class Pred = std::less<Key>
+ , class Alloc = default_allocator
+ >
+ struct map;
+
+ /// a mapping of heterogenous object to heterogenous object
+ template
+ <
+ class Base = base_type
+ , class Pred = indirect<std::less<Base> >
+ , class Alloc = default_allocator
+ >
+ struct heterogenous_map;
+
+ /// a set of heterogenous objects
+ template
+ <
+ class Base = base_type
+ , class Pred = std::less<Base>
+ , class Alloc = default_allocator
+ >
+ struct set;
 
- } // namespace cloneable
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/heterogenous_map.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/heterogenous_map.hpp (original)
+++ sandbox/cloneable/boost/cloneable/heterogenous_map.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -14,228 +14,228 @@
 
 namespace boost
 {
- namespace cloneable
- {
- //namespace heterogenous
- //{
- /// a map of heterogenous object to heterogenous object
- // TODO: move to boost/heterogenous/map
- template <class Base, class Pred, class Alloc>
- struct heterogenous_map
- : detail::associative_container_base<
- std::map<
- abstract_base<Base> *
- , abstract_base<Base> *
- , Pred
- //, allocator
- , typename detail::make_clone_allocator<Alloc>::type>
- , Pred
- , Base
- , Alloc>
- {
- typedef detail::associative_container_base<
- std::map<
- abstract_base<Base> *
- , abstract_base<Base> *
- , Pred
- //, allocator
- , typename detail::make_clone_allocator<Alloc>::type>
- , Pred
- , Base
- , Alloc>
- parent_type;
-
- typedef typename parent_type::container_type container_type;
- typedef typename parent_type::base_type base_type;
- typedef typename parent_type::abstract_base_type abstract_base_type;
- typedef typename parent_type::allocator_type allocator_type;
- typedef typename parent_type::value_type value_type;
- typedef typename parent_type::reference reference;
- typedef typename parent_type::const_reference const_reference;
- typedef typename parent_type::iterator iterator;
- typedef typename parent_type::const_iterator const_iterator;
-
- using parent_type::new_instance;
- using parent_type::validate;
-
- typedef typename container_type::key_type key_type;
- typedef typename container_type::mapped_type mapped_type;
-
- typedef map<Base, Pred, Alloc> this_type;
-
- public:
- heterogenous_map()
- {
- }
- heterogenous_map(allocator_type &a)
- : parent_type(a)
- {
- }
-
- //template <class II>
- //map(II F, II L)
- // : impl(F,L, get_allocator())
- //{
- //}
- //template <class II>
- //map(II F, II L, allocator_type &a)
- // : parent_type(a), impl(F,L, get_allocator())
- //{
- //}
-
- private:
- typedef std::pair<iterator, bool> map_insert_result;
-
- template <class K, class V>
- struct insert_result
- {
- //TODO: typedef const_instance<K> key_type;
- typedef instance<K> key_type;
- typedef instance<V> value_type;
-
- key_type key;
- value_type value;
- iterator where;
- bool inserted;
-
- insert_result() : inserted(false) { }
- insert_result(const key_type &K, const value_type &V, const map_insert_result &R)
- : key(K), value(V), where(R.first), inserted(R.second) { }
- };
-
- template <class K>
- struct value_adder
- {
- private:
- typedef instance<K> key_type;
- this_type *parent;
- key_type key;
-
- public:
- value_adder(this_type &P, const key_type &K)
- : parent(&P), key(K) { }
-
- template <class V>
- insert_result<K,V> value()
- {
- return insert(parent->new_instance<V>());
- }
-
- template <class V, class A0>
- insert_result<K,V> value(A0 a0)
- {
- return insert(parent->new_instance<V>(a0));
- }
- template <class V, class A0, class A1>
- insert_result<K,V> value(A0 a0, A1 a1)
- {
- return insert(parent->new_instance<V>(a0,a1));
- }
-
- private:
- template <class V>
- insert_result<K,V> insert(instance<V> &value)
- {
- map_insert_result result = parent->insert(*key.to_abstract(), *value.to_abstract());
- if (!result.second)
- {
- key.release();
- value.release();
- }
- return insert_result<K,V>(key, value, result);
- }
- };
-
- // TODO: make this private
- map_insert_result insert(abstract_base_type &a, abstract_base_type &b)
- {
- impl().insert(std::make_pair(&a, &b));
- return map_insert_result();
- }
- void insert(value_type x)
- {
- impl().insert(x);
- }
-
- public:
- template <class K>
- value_adder<K> key()
- {
- return value_adder<K>(*this, new_instance<K>());
- }
-
- // TODO: use variadic arguments or BOOST_PP to pass ctor args
- template <class K, class A0>
- value_adder<K> key(A0 a0)
- {
- return value_adder<K>(*this, new_instance<K>(a0));
- }
- template <class K, class A0, class A1>
- value_adder<K> key(A0 a0, A1 a1)
- {
- return value_adder<K>(*this, new_instance<K>(a0,a1));
- }
- template <class K, class A0, class A1, class A2>
- value_adder<K> key(A0 a0, A1 a1, A2 a2)
- {
- return value_adder<K>(*this, new_instance<K>(a0,a1,a2));
- }
-
- template <class Ty, class Fun>
- Fun for_each_key(Fun fun)
- {
- //BOOST_FOREACH(base_type &b, *this)
- //{
- // if (Ty *ptr = dynamic_cast<Ty *>(&b))
- // {
- // fun(*ptr);
- // }
- //}
- return fun;
- }
-
- template <class Ty, class Fun>
- Fun for_each_mapped(Fun fun) const
- {
- //BOOST_FOREACH(const common_base &base, *this)
- //{
- // if (Ty *ptr = dynamic_cast<Ty *>(&base))
- // {
- // fun(*ptr);
- // }
- //}
- return fun;
- }
-
- template <class K>
- iterator find()
- {
- instance<K> k(get_allocator());
- BOOST_SCOPE_EXIT((k))
- {
- k.release();
- }
- BOOST_SCOPE_EXIT_END
- return impl().find(k.to_abstract());
- }
-
- template <class K, class A0>
- iterator find(A0 a0)
- {
- instance<K> k(get_allocator(), a0);
- BOOST_SCOPE_EXIT((k))
- {
- k.release();
- }
- BOOST_SCOPE_EXIT_END
- return impl().find(k.to_abstract());
- }
-
- };
-
- //} // namespace heterogenous
+ namespace cloneable
+ {
+ //namespace heterogenous
+ //{
+ /// a map of heterogenous object to heterogenous object
+ // TODO: move to boost/heterogenous/map
+ template <class Base, class Pred, class Alloc>
+ struct heterogenous_map
+ : detail::associative_container_base<
+ std::map<
+ abstract_base<Base> *
+ , abstract_base<Base> *
+ , Pred
+ //, allocator
+ , typename detail::make_clone_allocator<Alloc>::type>
+ , Pred
+ , Base
+ , Alloc>
+ {
+ typedef detail::associative_container_base<
+ std::map<
+ abstract_base<Base> *
+ , abstract_base<Base> *
+ , Pred
+ //, allocator
+ , typename detail::make_clone_allocator<Alloc>::type>
+ , Pred
+ , Base
+ , Alloc>
+ parent_type;
+
+ typedef typename parent_type::container_type container_type;
+ typedef typename parent_type::base_type base_type;
+ typedef typename parent_type::abstract_base_type abstract_base_type;
+ typedef typename parent_type::allocator_type allocator_type;
+ typedef typename parent_type::value_type value_type;
+ typedef typename parent_type::reference reference;
+ typedef typename parent_type::const_reference const_reference;
+ typedef typename parent_type::iterator iterator;
+ typedef typename parent_type::const_iterator const_iterator;
+
+ using parent_type::new_instance;
+ using parent_type::validate;
+
+ typedef typename container_type::key_type key_type;
+ typedef typename container_type::mapped_type mapped_type;
+
+ typedef heterogenous_map<Base, Pred, Alloc> this_type;
+
+ public:
+ heterogenous_map()
+ {
+ }
+ heterogenous_map(allocator_type &a)
+ : parent_type(a)
+ {
+ }
+
+ //template <class II>
+ //map(II F, II L)
+ // : impl(F,L, get_allocator())
+ //{
+ //}
+ //template <class II>
+ //map(II F, II L, allocator_type &a)
+ // : parent_type(a), impl(F,L, get_allocator())
+ //{
+ //}
+
+ private:
+ typedef std::pair<iterator, bool> map_insert_result;
+
+ template <class K, class V>
+ struct insert_result
+ {
+ //TODO: typedef const_instance<K> key_type;
+ typedef instance<K> key_type;
+ typedef instance<V> value_type;
+
+ key_type key;
+ value_type value;
+ iterator where;
+ bool inserted;
+
+ insert_result() : inserted(false) { }
+ insert_result(const key_type &K, const value_type &V, const map_insert_result &R)
+ : key(K), value(V), where(R.first), inserted(R.second) { }
+ };
+
+ template <class K>
+ struct value_adder
+ {
+ private:
+ typedef instance<K> key_type;
+ this_type *parent;
+ key_type key;
+
+ public:
+ value_adder(this_type &P, const key_type &K)
+ : parent(&P), key(K) { }
+
+ template <class V>
+ insert_result<K,V> value()
+ {
+ return insert(parent->new_instance<V>());
+ }
+
+ template <class V, class A0>
+ insert_result<K,V> value(A0 a0)
+ {
+ return insert(parent->new_instance<V>(a0));
+ }
+ template <class V, class A0, class A1>
+ insert_result<K,V> value(A0 a0, A1 a1)
+ {
+ return insert(parent->new_instance<V>(a0,a1));
+ }
+
+ private:
+ template <class V>
+ insert_result<K,V> insert(instance<V> &value)
+ {
+ map_insert_result result = parent->insert(*key.to_abstract(), *value.to_abstract());
+ if (!result.second)
+ {
+ key.release();
+ value.release();
+ }
+ return insert_result<K,V>(key, value, result);
+ }
+ };
+
+ // TODO: make this private
+ map_insert_result insert(abstract_base_type &a, abstract_base_type &b)
+ {
+ impl().insert(std::make_pair(&a, &b));
+ return map_insert_result();
+ }
+ void insert(value_type x)
+ {
+ impl().insert(x);
+ }
+
+ public:
+ template <class K>
+ value_adder<K> key()
+ {
+ return value_adder<K>(*this, new_instance<K>());
+ }
+
+ // TODO: use variadic arguments or BOOST_PP to pass ctor args
+ template <class K, class A0>
+ value_adder<K> key(A0 a0)
+ {
+ return value_adder<K>(*this, new_instance<K>(a0));
+ }
+ template <class K, class A0, class A1>
+ value_adder<K> key(A0 a0, A1 a1)
+ {
+ return value_adder<K>(*this, new_instance<K>(a0,a1));
+ }
+ template <class K, class A0, class A1, class A2>
+ value_adder<K> key(A0 a0, A1 a1, A2 a2)
+ {
+ return value_adder<K>(*this, new_instance<K>(a0,a1,a2));
+ }
+
+ template <class Ty, class Fun>
+ Fun for_each_key(Fun fun)
+ {
+ //BOOST_FOREACH(base_type &b, *this)
+ //{
+ // if (Ty *ptr = dynamic_cast<Ty *>(&b))
+ // {
+ // fun(*ptr);
+ // }
+ //}
+ return fun;
+ }
+
+ template <class Ty, class Fun>
+ Fun for_each_mapped(Fun fun) const
+ {
+ //BOOST_FOREACH(const common_base &base, *this)
+ //{
+ // if (Ty *ptr = dynamic_cast<Ty *>(&base))
+ // {
+ // fun(*ptr);
+ // }
+ //}
+ return fun;
+ }
+
+ template <class K>
+ iterator find()
+ {
+ instance<K> k(get_allocator());
+ BOOST_SCOPE_EXIT((k))
+ {
+ k.release();
+ }
+ BOOST_SCOPE_EXIT_END
+ return impl().find(k.to_abstract());
+ }
+
+ template <class K, class A0>
+ iterator find(A0 a0)
+ {
+ instance<K> k(get_allocator(), a0);
+ BOOST_SCOPE_EXIT((k))
+ {
+ k.release();
+ }
+ BOOST_SCOPE_EXIT_END
+ return impl().find(k.to_abstract());
+ }
+
+ };
+
+ //} // namespace heterogenous
 
- } // namespace cloneable
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/instance.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/instance.hpp (original)
+++ sandbox/cloneable/boost/cloneable/instance.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -12,229 +12,229 @@
 
 namespace boost
 {
- namespace cloneable
- {
- /// common for all instances of the given base and allocator type
- template <class Base, class Alloc>
- struct instance_base
- {
- typedef Base base_type;
- typedef Alloc allocator_type;
- typedef instance_base<Base,Alloc> this_type;
-
- private:
- allocator_type *alloc;
-
- public:
- instance_base(allocator_type *al = 0)
- : alloc(al) { }
-
- bool has_allocator() const
- {
- return alloc != 0;
- }
- allocator_type &get_allocator() const
- {
- if (!alloc)
- throw empty_allocator(typeid(this_type).name());
- return *alloc;
- }
- void set_allocator(allocator_type &al)
- {
- alloc = &al;
- }
-
- virtual const std::type_info &get_type() const = 0;
- virtual void allocate() = 0;
- virtual bool exists() const = 0;
- virtual base_type *to_base() const = 0;
- virtual void release() = 0;
- };
-
- /// common for all instances
- template <class Abstract, class Derived, class Base, class Alloc>
- struct instance_common : instance_base<Base,Alloc>
- {
- typedef instance_base<Base,Alloc> parent_type;
- using parent_type::base_type;
- using parent_type::allocator_type;
- using parent_type::set_allocator;
-
- typedef Abstract abstract_type;
- typedef Derived derived_type;
- typedef detail::mixin<derived_type, base_type> is_derived_type;
- typedef instance_common<Abstract, Derived, Base, Alloc> this_type;
-
- protected:
- derived_type *ptr;
-
- public:
- instance_common(derived_type *p = 0) : ptr(p) { }
- instance_common(allocator_type &a, derived_type *p = 0) : parent_type(&a), ptr(p) { }
-
- this_type clone() const
- {
- if (empty())
- return this_type(get_allocator());
- return this_type(get_allocator(), to_abstract()->clone_as<derived_type>(get_allocator()));
- }
-
- template <class Ty>
- instance_common<base<Ty,Base, unknown_construction_tag>, Derived, Base, Alloc> clone() const
- {
- typedef instance_common<base<Ty,Base, unknown_construction_tag>, Derived, Base, Alloc> that_type;
- if (empty())
- return that_type(get_allocator());
- return that_type(get_allocator(), to_abstract()->clone_as<Ty>(get_allocator()));
- }
-
- void allocate()
- {
- if (!has_allocator())
- return;
- if (exists())
- release();
- derived_type *derived = cloneable::allocate<derived_type>(get_allocator());
- derived->is_derived_type::self_ptr = derived;
- ptr = derived;
- }
- void release()
- {
- if (!has_allocator())
- return;
- cloneable::release(ptr, get_allocator());
- ptr = 0;
- }
- template <class A0>
- void construct(A0 a0)
- {
- allocate();
- new (to_derived()) derived_type(a0);
- }
- template <class A0, class A1>
- void construct(A0 a0, A1 a1)
- {
- allocate();
- new (to_derived()) derived_type(a0, a1);
- }
- template <class A0, class A1, class A2>
- void construct(A0 a0, A1 a1, A2 a2)
- {
- allocate();
- new (to_derived()) derived_type(a0, a1, a2);
- }
-
- const std::type_info &get_type() const
- {
- return typeid(derived_type);
- }
-
- bool exists() const
- {
- return ptr != 0;
- }
-
- bool empty() const
- {
- return ptr == 0;
- }
-
- base_type *to_base() const
- {
- return ptr;
- }
- abstract_type *to_abstract() const
- {
- return ptr;
- }
- derived_type *to_derived() const
- {
- return ptr;
- }
-
- derived_type &derived_ref()
- {
- ptr = to_derived();
- if (ptr == 0)
- throw empty_object();
- return *ptr;
- }
-
- derived_type *operator->()
- {
- return &derived_ref();
- }
- derived_type &operator*()
- {
- return derived_ref();
- }
- };
-
- /// a pointer to a general instance
- template <class Derived, class Base, class Alloc, class Ctor>
- struct instance : instance_common<base<Derived,Base,Ctor>, Derived, Base, Alloc>
- {
- typedef abstract_base<Base> abstract_base_type;
- typedef base<Derived,Base,Ctor> base_type;
- typedef instance_common<abstract_type, Derived, Base, Alloc> parent_type;
- typedef instance<Derived, Base, Alloc, Ctor> this_type;
-
- public:
- instance() { }
-
- instance(allocator_type &al)
- : parent_type(al
- , detail::create_new<Derived, Ctor>::given(to_abstract(), al, abstract_type::alignment))
- {
- }
-
- template <class Other, class Ctor2>
- instance(const instance<Other,Base,Alloc,Ctor2> &other)
- : parent_type(dynamic_cast<derived_type *>(other.to_base()))
- {
- if (other.has_allocator())
- parent_type::set_allocator(other.get_allocator());
- }
-
- instance(base_type *ptr)
- : parent_type(dynamic_cast<derived_type *>(ptr))
- {
- }
- instance(abstract_base_type *ptr)
- : parent_type(dynamic_cast<derived_type *>(ptr))
- {
- }
- instance(abstract_base_type *abst, allocator_type &al)
- : parent_type(al, dynamic_cast<derived_type *>(abst))
- {
- }
- template <class A0>
- instance(allocator_type &al, A0 a0) : parent_type(al)
- {
- allocate();
- new (to_derived()) derived_type(a0);
- }
- template <class A0, class A1>
- instance(allocator_type &al, A0 a0, A1 a1) : parent_type(al)
- {
- allocate();
- new (to_derived()) derived_type(a0, a1);
- }
- template <class A0, class A1, class A2>
- instance(allocator_type &al, A0 a0, A1 a1, A2 a2) : parent_type(al)
- {
- allocate();
- new (to_derived()) derived_type(a0, a1, a2);
- }
- this_type clone() const
- {
- if (empty())
- return this_type(get_allocator());
- return this_type(get_allocator(), to_abstract()->clone_as<derived_type>(get_allocator()));
- }
- };
+ namespace cloneable
+ {
+ /// common for all instances of the given base and allocator type
+ template <class Base, class Alloc>
+ struct instance_base
+ {
+ typedef Base base_type;
+ typedef Alloc allocator_type;
+ typedef instance_base<Base,Alloc> this_type;
+
+ private:
+ allocator_type *alloc;
+
+ public:
+ instance_base(allocator_type *al = 0)
+ : alloc(al) { }
+
+ bool has_allocator() const
+ {
+ return alloc != 0;
+ }
+ allocator_type &get_allocator() const
+ {
+ if (!alloc)
+ throw empty_allocator(typeid(this_type).name());
+ return *alloc;
+ }
+ void set_allocator(allocator_type &al)
+ {
+ alloc = &al;
+ }
+
+ virtual const std::type_info &get_type() const = 0;
+ virtual void allocate() = 0;
+ virtual bool exists() const = 0;
+ virtual base_type *to_base() const = 0;
+ virtual void release() = 0;
+ };
+
+ /// common for all instances
+ template <class Abstract, class Derived, class Base, class Alloc>
+ struct instance_common : instance_base<Base,Alloc>
+ {
+ typedef instance_base<Base,Alloc> parent_type;
+ using parent_type::base_type;
+ using parent_type::allocator_type;
+ using parent_type::set_allocator;
+
+ typedef Abstract abstract_type;
+ typedef Derived derived_type;
+ typedef detail::mixin<derived_type, base_type> is_derived_type;
+ typedef instance_common<Abstract, Derived, Base, Alloc> this_type;
+
+ protected:
+ derived_type *ptr;
+
+ public:
+ instance_common(derived_type *p = 0) : ptr(p) { }
+ instance_common(allocator_type &a, derived_type *p = 0) : parent_type(&a), ptr(p) { }
+
+ this_type clone() const
+ {
+ if (empty())
+ return this_type(get_allocator());
+ return this_type(get_allocator(), to_abstract()->clone_as<derived_type>(get_allocator()));
+ }
+
+ template <class Ty>
+ instance_common<base<Ty,Base, unknown_construction_tag>, Derived, Base, Alloc> clone() const
+ {
+ typedef instance_common<base<Ty,Base, unknown_construction_tag>, Derived, Base, Alloc> that_type;
+ if (empty())
+ return that_type(get_allocator());
+ return that_type(get_allocator(), to_abstract()->clone_as<Ty>(get_allocator()));
+ }
+
+ void allocate()
+ {
+ if (!has_allocator())
+ return;
+ if (exists())
+ release();
+ derived_type *derived = cloneable::allocate<derived_type>(get_allocator());
+ derived->is_derived_type::self_ptr = derived;
+ ptr = derived;
+ }
+ void release()
+ {
+ if (!has_allocator())
+ return;
+ cloneable::release(ptr, get_allocator());
+ ptr = 0;
+ }
+ template <class A0>
+ void construct(A0 a0)
+ {
+ allocate();
+ new (to_derived()) derived_type(a0);
+ }
+ template <class A0, class A1>
+ void construct(A0 a0, A1 a1)
+ {
+ allocate();
+ new (to_derived()) derived_type(a0, a1);
+ }
+ template <class A0, class A1, class A2>
+ void construct(A0 a0, A1 a1, A2 a2)
+ {
+ allocate();
+ new (to_derived()) derived_type(a0, a1, a2);
+ }
+
+ const std::type_info &get_type() const
+ {
+ return typeid(derived_type);
+ }
+
+ bool exists() const
+ {
+ return ptr != 0;
+ }
+
+ bool empty() const
+ {
+ return ptr == 0;
+ }
+
+ base_type *to_base() const
+ {
+ return ptr;
+ }
+ abstract_type *to_abstract() const
+ {
+ return ptr;
+ }
+ derived_type *to_derived() const
+ {
+ return ptr;
+ }
+
+ derived_type &derived_ref()
+ {
+ ptr = to_derived();
+ if (ptr == 0)
+ throw empty_object();
+ return *ptr;
+ }
+
+ derived_type *operator->()
+ {
+ return &derived_ref();
+ }
+ derived_type &operator*()
+ {
+ return derived_ref();
+ }
+ };
+
+ /// a pointer to a general instance
+ template <class Derived, class Base, class Alloc, class Ctor>
+ struct instance : instance_common<base<Derived,Base,Ctor>, Derived, Base, Alloc>
+ {
+ typedef abstract_base<Base> abstract_base_type;
+ typedef base<Derived,Base,Ctor> base_type;
+ typedef instance_common<abstract_type, Derived, Base, Alloc> parent_type;
+ typedef instance<Derived, Base, Alloc, Ctor> this_type;
+
+ public:
+ instance() { }
+
+ instance(allocator_type &al)
+ : parent_type(al
+ , detail::create_new<Derived, Ctor>::given(to_abstract(), al, abstract_type::alignment))
+ {
+ }
+
+ template <class Other, class Ctor2>
+ instance(const instance<Other,Base,Alloc,Ctor2> &other)
+ : parent_type(dynamic_cast<derived_type *>(other.to_base()))
+ {
+ if (other.has_allocator())
+ parent_type::set_allocator(other.get_allocator());
+ }
+
+ instance(base_type *ptr)
+ : parent_type(dynamic_cast<derived_type *>(ptr))
+ {
+ }
+ instance(abstract_base_type *ptr)
+ : parent_type(dynamic_cast<derived_type *>(ptr))
+ {
+ }
+ instance(abstract_base_type *abst, allocator_type &al)
+ : parent_type(al, dynamic_cast<derived_type *>(abst))
+ {
+ }
+ template <class A0>
+ instance(allocator_type &al, A0 a0) : parent_type(al)
+ {
+ allocate();
+ new (to_derived()) derived_type(a0);
+ }
+ template <class A0, class A1>
+ instance(allocator_type &al, A0 a0, A1 a1) : parent_type(al)
+ {
+ allocate();
+ new (to_derived()) derived_type(a0, a1);
+ }
+ template <class A0, class A1, class A2>
+ instance(allocator_type &al, A0 a0, A1 a1, A2 a2) : parent_type(al)
+ {
+ allocate();
+ new (to_derived()) derived_type(a0, a1, a2);
+ }
+ this_type clone() const
+ {
+ if (empty())
+ return this_type(get_allocator());
+ return this_type(get_allocator(), to_abstract()->clone_as<derived_type>(get_allocator()));
+ }
+ };
 
- } // namespace cloneable
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/list.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/list.hpp (original)
+++ sandbox/cloneable/boost/cloneable/list.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -14,52 +14,52 @@
 
 namespace boost
 {
- namespace cloneable
- {
- /// a list of heterogenous objects
- // TODO: derive from sequence<ptr_list>
- // TODO: move to boost/heterogenous/list
- template <class Base, class Alloc>
- struct list
- : detail::sequence_container_base<
- ptr_list<
- abstract_base<Base>
- , allocator
- , typename detail::make_clone_allocator<Alloc>::type >
- , Base
- , Alloc>
- {
- typedef detail::sequence_container_base<
- ptr_list<abstract_base<Base>
- , allocator
- , typename detail::make_clone_allocator<Alloc>::type >
- , Base
- , Alloc>
- parent_type;
-
- using parent_type::base_type;
- using parent_type::abstract_base_type;
- using parent_type::allocator_type;
- using parent_type::validate;
- using parent_type::new_instance;
- using parent_type::value_type;
- using parent_type::reference;
- using parent_type::const_reference;
- using parent_type::iterator;
- using parent_type::const_iterator;
-
- public:
- list()
- {
- }
-
- list(allocator_type &a)
- : parent_type(a)
- {
- }
- };
-
- } // namespace cloneable
+ namespace cloneable
+ {
+ /// a list of heterogenous objects
+ // TODO: derive from sequence<ptr_list>
+ // TODO: move to boost/heterogenous/list
+ template <class Base, class Alloc>
+ struct list
+ : detail::sequence_container_base<
+ ptr_list<
+ abstract_base<Base>
+ , allocator
+ , typename detail::make_clone_allocator<Alloc>::type >
+ , Base
+ , Alloc>
+ {
+ typedef detail::sequence_container_base<
+ ptr_list<abstract_base<Base>
+ , allocator
+ , typename detail::make_clone_allocator<Alloc>::type >
+ , Base
+ , Alloc>
+ parent_type;
+
+ using parent_type::base_type;
+ using parent_type::abstract_base_type;
+ using parent_type::allocator_type;
+ using parent_type::validate;
+ using parent_type::new_instance;
+ using parent_type::value_type;
+ using parent_type::reference;
+ using parent_type::const_reference;
+ using parent_type::iterator;
+ using parent_type::const_iterator;
+
+ public:
+ list()
+ {
+ }
+
+ list(allocator_type &a)
+ : parent_type(a)
+ {
+ }
+ };
+
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/map.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/map.hpp (original)
+++ sandbox/cloneable/boost/cloneable/map.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -14,137 +14,137 @@
 
 namespace boost
 {
- namespace cloneable
- {
- //namespace heterogenous
- //{
- /// a vector of heterogenous objects
- // TODO: move to boost/heterogenous/map
- template <class Key, class Base, class Pred, class Alloc>
- struct map
- : detail::associative_container_base<
- ptr_map<
- Key
- , abstract_base<Base>
- , Pred
- , allocator
- , typename detail::make_clone_allocator<Alloc>::type>
- , Pred
- , Base
- , Alloc>
- {
- typedef detail::associative_container_base<
- ptr_map<
- Key
- , abstract_base<Base>
- , Pred
- , allocator
- , typename detail::make_clone_allocator<Alloc>::type>
- , Pred
- , Base
- , Alloc>
- parent_type;
-
- typedef typename parent_type::container_type container_type;
- typedef typename parent_type::base_type base_type;
- typedef typename parent_type::abstract_base_type abstract_base_type;
- typedef typename parent_type::allocator_type allocator_type;
- typedef typename parent_type::value_type value_type;
- typedef typename parent_type::reference reference;
- typedef typename parent_type::const_reference const_reference;
- typedef typename parent_type::iterator iterator;
- typedef typename parent_type::const_iterator const_iterator;
-
- using parent_type::new_instance;
- using parent_type::validate;
-
- typedef typename container_type::key_type key_type;
- typedef typename container_type::mapped_type mapped_type;
-
- typedef map<Base, Pred, Alloc> this_type;
-
- public:
- map()
- {
- }
- map(allocator_type &a)
- : parent_type(a)
- {
- }
-
- //template <class II>
- //map(II F, II L)
- // : impl(F,L, get_allocator())
- //{
- //}
- //template <class II>
- //map(II F, II L, allocator_type &a)
- // : parent_type(a), impl(F,L, get_allocator())
- //{
- //}
-
-
- public:
- typedef std::pair<iterator, bool> map_insert_result;
-
- template <class V>
- map_insert_result insert(key_type key)
- {
- return impl().insert(key, new_instance<V>().to_abstract());
- }
- template <class V, class A0>
- map_insert_result insert(key_type key, A0 a0)
- {
- return impl().insert(key, new_instance<V>(a0).to_abstract());
- }
- template <class K, class A0, class A1>
- map_insert_result insert(key_type key, A0 a0, A1 a1)
- {
- return impl().insert(key, new_instance<V>(a0,a1).to_abstract());
- }
- template <class K, class A0, class A1, class A2>
- map_insert_result insert(key_type key, A0 a0, A1 a1, A2 a2)
- {
- return impl().insert(key, new_instance<V>(a0,a1,a2).to_abstract());
- }
-
- template <class Fun>
- Fun for_each_key(Fun fun)
- {
- BOOST_FOREACH(value_type &val, *this)
- {
- fun(val.first);
- }
- return fun;
- }
-
- template <class Ty, class Fun>
- Fun for_each_mapped(Fun fun) const
- {
- BOOST_FOREACH(value_type const &value, *this)
- {
- if (Ty *ptr = dynamic_cast<Ty *>(&val.second))
- {
- fun(*ptr);
- }
- }
- return fun;
- }
-
- iterator find(key_type const &key)
- {
- return impl().find(key);
- }
-
- const_iterator find(key_type const &key) const
- {
- return impl().find(key);
- }
- };
-
- //} // namespace heterogenous
+ namespace cloneable
+ {
+ //namespace heterogenous
+ //{
+ /// a vector of heterogenous objects
+ // TODO: move to boost/heterogenous/map
+ template <class Key, class Base, class Pred, class Alloc>
+ struct map
+ : detail::associative_container_base<
+ ptr_map<
+ Key
+ , abstract_base<Base>
+ , Pred
+ , allocator
+ , typename detail::make_clone_allocator<Alloc>::type>
+ , Pred
+ , Base
+ , Alloc>
+ {
+ typedef detail::associative_container_base<
+ ptr_map<
+ Key
+ , abstract_base<Base>
+ , Pred
+ , allocator
+ , typename detail::make_clone_allocator<Alloc>::type>
+ , Pred
+ , Base
+ , Alloc>
+ parent_type;
+
+ typedef typename parent_type::container_type container_type;
+ typedef typename parent_type::base_type base_type;
+ typedef typename parent_type::abstract_base_type abstract_base_type;
+ typedef typename parent_type::allocator_type allocator_type;
+ typedef typename parent_type::value_type value_type;
+ typedef typename parent_type::reference reference;
+ typedef typename parent_type::const_reference const_reference;
+ typedef typename parent_type::iterator iterator;
+ typedef typename parent_type::const_iterator const_iterator;
+
+ using parent_type::new_instance;
+ using parent_type::validate;
+
+ typedef typename container_type::key_type key_type;
+ typedef typename container_type::mapped_type mapped_type;
+
+ typedef map<Key, Base, Pred, Alloc> this_type;
+
+ public:
+ map()
+ {
+ }
+ map(allocator_type &a)
+ : parent_type(a)
+ {
+ }
+
+ //template <class II>
+ //map(II F, II L)
+ // : impl(F,L, get_allocator())
+ //{
+ //}
+ //template <class II>
+ //map(II F, II L, allocator_type &a)
+ // : parent_type(a), impl(F,L, get_allocator())
+ //{
+ //}
+
+
+ public:
+ typedef std::pair<iterator, bool> map_insert_result;
+
+ template <class V>
+ map_insert_result insert(key_type key)
+ {
+ return impl().insert(key, new_instance<V>().to_abstract());
+ }
+ template <class V, class A0>
+ map_insert_result insert(key_type key, A0 a0)
+ {
+ return impl().insert(key, new_instance<V>(a0).to_abstract());
+ }
+ template <class K, class A0, class A1>
+ map_insert_result insert(key_type key, A0 a0, A1 a1)
+ {
+ return impl().insert(key, new_instance<V>(a0,a1).to_abstract());
+ }
+ template <class K, class A0, class A1, class A2>
+ map_insert_result insert(key_type key, A0 a0, A1 a1, A2 a2)
+ {
+ return impl().insert(key, new_instance<V>(a0,a1,a2).to_abstract());
+ }
+
+ template <class Fun>
+ Fun for_each_key(Fun fun)
+ {
+ BOOST_FOREACH(value_type &val, *this)
+ {
+ fun(val.first);
+ }
+ return fun;
+ }
+
+ template <class Ty, class Fun>
+ Fun for_each_mapped(Fun fun) const
+ {
+ BOOST_FOREACH(value_type const &value, *this)
+ {
+ if (Ty *ptr = dynamic_cast<Ty *>(&val.second))
+ {
+ fun(*ptr);
+ }
+ }
+ return fun;
+ }
+
+ iterator find(key_type const &key)
+ {
+ return impl().find(key);
+ }
+
+ const_iterator find(key_type const &key) const
+ {
+ return impl().find(key);
+ }
+ };
+
+ //} // namespace heterogenous
 
- } // namespace cloneable
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/set.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/set.hpp (original)
+++ sandbox/cloneable/boost/cloneable/set.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -15,205 +15,205 @@
 
 namespace boost
 {
- namespace cloneable
- {
- /// a vector of heterogenous objects
- // TODO: move to boost/heterogenous/set.hpp, or boost/cloneable/containers/set.hpp
- template <class Base, class Pred, class Alloc>
- struct set
- : detail::associative_container_base<
- ptr_set<
- abstract_base<Base>
- , Pred
- , allocator
- , typename detail::make_clone_allocator<Alloc>::type>
- , Pred
- , Base
- , Alloc>
- {
- typedef detail::associative_container_base<
- ptr_set<
- abstract_base<Base>
- , Pred
- , allocator
- , typename detail::make_clone_allocator<Alloc>::type>
- , Pred
- , Base
- , Alloc>
- parent_type;
-
- typedef typename parent_type::container_type container_type;
- typedef typename parent_type::base_type base_type;
- typedef typename parent_type::abstract_base_type abstract_base_type;
- typedef typename parent_type::allocator_type allocator_type;
- typedef typename parent_type::value_type value_type;
- typedef typename parent_type::reference reference;
- typedef typename parent_type::const_reference const_reference;
- typedef typename parent_type::iterator iterator;
- typedef typename parent_type::const_iterator const_iterator;
-
- using parent_type::new_instance;
- using parent_type::validate;
-
- typedef set<Base, Pred, Alloc> this_type;
-
- public:
- set()
- {
- }
- set(allocator_type &a)
- : parent_type(a)
- {
- }
-
- set(predicate_type pred)
- : parnet_type(pred)
- {
- }
- set(predicate_type pred, allocator_type &a)
- : parent_type(pred, a)
- {
- }
-
- template <class II>
- set(II F, II L, predicate_type pred = predicate_type())
- : parent_type(F, L, pred)
- {
- }
-
- template <class II>
- set(II F, II L, allocator_type &a)
- : parent_type(F, L, a)
- {
- }
- template <class II>
- set(II F, II L, predicate_type pred, allocator_type &a)
- : parent_type(F, L, pred, a)
- {
- }
-
- public:
- typedef std::pair<iterator, bool> insert_result;
-
- template <class U>
- struct emplace_result
- {
- typedef instance<U> instance_type;
- instance_type value;
- bool inserted;
- iterator where;
- emplace_result() : inserted(false) { }
- emplace_result(instance_type ins, const insert_result &result)
- : value(ins), inserted(result.second), where(result.first) { }
- };
-
- template <class U>
- emplace_result<U> emplace(instance<U> value)
- {
- insert_result result = impl().insert(value.to_abstract());
- if (!result.second)
- value.release();
- return emplace_result<U>(value, result);
- }
-
- template <class U>
- emplace_result<U> emplace()
- {
- return emplace(new_instance<U>());
- }
-
- template <class U, class A0>
- emplace_result<U> emplace(A0 a0)
- {
- return emplace(new_instance<U>(a0));
- }
- template <class U, class A0, class A1>
- emplace_result<U> emplace(A0 a0, A1 a1)
- {
- return emplace(new_instance<U>(a0, a1));
- }
- template <class U, class A0, class A1, class A2>
- emplace_result<U> emplace(A0 a0, A1 a1, A2 a2)
- {
- return emplace(new_instance<U>(a0, a1, a2));
- }
-
- struct detail
- {
- template <class U>
- struct find
- {
- template <class Instance>
- static iterator search(this_type *cont, Instance &value)
- {
- BOOST_SCOPE_EXIT((&value))
- {
- value.release();
- }
- BOOST_SCOPE_EXIT_END
- return cont->find_instance<U>(value);
- }
-
- static iterator given(this_type *cont)
- {
- return search(cont, cont->new_instance<U>());
- }
-
- template <class A0>
- static iterator given(this_type *cont, A0 a0)
- {
- return search(cont, cont->new_instance<U>(a0));
- }
- template <class A0, class A1>
- static iterator given(this_type *cont, A0 a0, A1 a1)
- {
- return search(cont, cont->new_instance<U>(a0, a1));
- }
- };
- struct default_key : base<default_key, base_type>
- {
- default_key() { }
- default_key(base_type const &X) : base<default_key, base_type>::base_type(X) { }
- };
-
- template <>
- struct find<base_type>
- {
- template <class A0>
- static iterator given(this_type *cont, A0 a0)
- {
- return cont->impl().find(default_key(base_type(a0)));
- }
- template <class A0, class A1>
- static iterator given(this_type *cont, A0 a0, A1 a1)
- {
- return cont->impl().find(default_key(base_type(a0, a1)));
- }
- };
- };
- template <class U>
- iterator find_instance(instance<U> value)
- {
- if (!value.exists())
- return end();
- iterator found = impl().find(*value.to_abstract());
- if (found == impl().end())
- return found;
- std::type_info const &found_type = found->get_type();
- if (found_type == typeid(U))
- return found;
- return impl().end();
- }
-
- template <class U, class A0>
- iterator find(A0 a0)
- {
- return detail::find<U>::given(this, a0);
- }
-
- };
-
- } // namespace heterogenous
+ namespace cloneable
+ {
+ /// a vector of heterogenous objects
+ // TODO: move to boost/heterogenous/set.hpp, or boost/cloneable/containers/set.hpp
+ template <class Base, class Pred, class Alloc>
+ struct set
+ : detail::associative_container_base<
+ ptr_set<
+ abstract_base<Base>
+ , Pred
+ , allocator
+ , typename detail::make_clone_allocator<Alloc>::type>
+ , Pred
+ , Base
+ , Alloc>
+ {
+ typedef detail::associative_container_base<
+ ptr_set<
+ abstract_base<Base>
+ , Pred
+ , allocator
+ , typename detail::make_clone_allocator<Alloc>::type>
+ , Pred
+ , Base
+ , Alloc>
+ parent_type;
+
+ typedef typename parent_type::container_type container_type;
+ typedef typename parent_type::base_type base_type;
+ typedef typename parent_type::abstract_base_type abstract_base_type;
+ typedef typename parent_type::allocator_type allocator_type;
+ typedef typename parent_type::value_type value_type;
+ typedef typename parent_type::reference reference;
+ typedef typename parent_type::const_reference const_reference;
+ typedef typename parent_type::iterator iterator;
+ typedef typename parent_type::const_iterator const_iterator;
+
+ using parent_type::new_instance;
+ using parent_type::validate;
+
+ typedef set<Base, Pred, Alloc> this_type;
+
+ public:
+ set()
+ {
+ }
+ set(allocator_type &a)
+ : parent_type(a)
+ {
+ }
+
+ set(predicate_type pred)
+ : parnet_type(pred)
+ {
+ }
+ set(predicate_type pred, allocator_type &a)
+ : parent_type(pred, a)
+ {
+ }
+
+ template <class II>
+ set(II F, II L, predicate_type pred = predicate_type())
+ : parent_type(F, L, pred)
+ {
+ }
+
+ template <class II>
+ set(II F, II L, allocator_type &a)
+ : parent_type(F, L, a)
+ {
+ }
+ template <class II>
+ set(II F, II L, predicate_type pred, allocator_type &a)
+ : parent_type(F, L, pred, a)
+ {
+ }
+
+ public:
+ typedef std::pair<iterator, bool> insert_result;
+
+ template <class U>
+ struct emplace_result
+ {
+ typedef instance<U> instance_type;
+ instance_type value;
+ bool inserted;
+ iterator where;
+ emplace_result() : inserted(false) { }
+ emplace_result(instance_type ins, const insert_result &result)
+ : value(ins), inserted(result.second), where(result.first) { }
+ };
+
+ template <class U>
+ emplace_result<U> emplace(instance<U> value)
+ {
+ insert_result result = impl().insert(value.to_abstract());
+ if (!result.second)
+ value.release();
+ return emplace_result<U>(value, result);
+ }
+
+ template <class U>
+ emplace_result<U> emplace()
+ {
+ return emplace(new_instance<U>());
+ }
+
+ template <class U, class A0>
+ emplace_result<U> emplace(A0 a0)
+ {
+ return emplace(new_instance<U>(a0));
+ }
+ template <class U, class A0, class A1>
+ emplace_result<U> emplace(A0 a0, A1 a1)
+ {
+ return emplace(new_instance<U>(a0, a1));
+ }
+ template <class U, class A0, class A1, class A2>
+ emplace_result<U> emplace(A0 a0, A1 a1, A2 a2)
+ {
+ return emplace(new_instance<U>(a0, a1, a2));
+ }
+
+ struct detail
+ {
+ template <class U>
+ struct find
+ {
+ template <class Instance>
+ static iterator search(this_type *cont, Instance &value)
+ {
+ BOOST_SCOPE_EXIT((&value))
+ {
+ value.release();
+ }
+ BOOST_SCOPE_EXIT_END
+ return cont->find_instance<U>(value);
+ }
+
+ static iterator given(this_type *cont)
+ {
+ return search(cont, cont->new_instance<U>());
+ }
+
+ template <class A0>
+ static iterator given(this_type *cont, A0 a0)
+ {
+ return search(cont, cont->new_instance<U>(a0));
+ }
+ template <class A0, class A1>
+ static iterator given(this_type *cont, A0 a0, A1 a1)
+ {
+ return search(cont, cont->new_instance<U>(a0, a1));
+ }
+ };
+ struct default_key : base<default_key, base_type>
+ {
+ default_key() { }
+ default_key(base_type const &X) : base<default_key, base_type>::base_type(X) { }
+ };
+
+ template <>
+ struct find<base_type>
+ {
+ template <class A0>
+ static iterator given(this_type *cont, A0 a0)
+ {
+ return cont->impl().find(default_key(base_type(a0)));
+ }
+ template <class A0, class A1>
+ static iterator given(this_type *cont, A0 a0, A1 a1)
+ {
+ return cont->impl().find(default_key(base_type(a0, a1)));
+ }
+ };
+ };
+ template <class U>
+ iterator find_instance(instance<U> value)
+ {
+ if (!value.exists())
+ return end();
+ iterator found = impl().find(*value.to_abstract());
+ if (found == impl().end())
+ return found;
+ std::type_info const &found_type = found->get_type();
+ if (found_type == typeid(U))
+ return found;
+ return impl().end();
+ }
+
+ template <class U, class A0>
+ iterator find(A0 a0)
+ {
+ return detail::find<U>::given(this, a0);
+ }
+
+ };
+
+ } // namespace heterogenous
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/traits.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/traits.hpp (original)
+++ sandbox/cloneable/boost/cloneable/traits.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -12,50 +12,50 @@
 
 namespace boost
 {
- namespace cloneable
- {
- namespace impl
- {
- template <class T, bool>
- struct traits
- {
- BOOST_STATIC_CONSTANT(bool, is_cloneable = false);
- BOOST_STATIC_CONSTANT(bool, has_default_ctor = false); // this really should be ternary: yes, no or unknown
- typedef void construction_tag_type;
- };
-
- template <class T>
- struct traits<T, true>
- {
- BOOST_STATIC_CONSTANT(bool, is_cloneable = true);
- typedef is_convertible<T *, default_construction_tag *> has_default_ctor_type;
- typedef is_convertible<T *, no_default_construction_tag *> has_no_default_ctor_type;
- /// T is default constructable only if it is convertibel to def_constr and
- /// it is also not convertible to no_def_constr. This ensures that a type
- /// that inherits from a type that is not default constructible, is also not
- /// default constructible no matter what.
- BOOST_STATIC_CONSTANT(bool, has_default_ctor = has_default_ctor_type::value || !has_no_default_ctor_type::value);
- typedef typename mpl::if_<mpl::bool_<has_default_ctor>
- , default_construction_tag
- , no_default_construction_tag>
- ::type construction_tag;
- };
-
- template <class T>
- struct get_traits : traits<T, is_convertible<T *, is_cloneable_tag *>::value> { };
-
- } // namespace impl
-
- template <class T>
- struct traits : impl::get_traits<T> { };
+ namespace cloneable
+ {
+ namespace impl
+ {
+ template <class T, bool>
+ struct traits
+ {
+ BOOST_STATIC_CONSTANT(bool, is_cloneable = false);
+ BOOST_STATIC_CONSTANT(bool, has_default_ctor = false); // this really should be ternary: yes, no or unknown
+ typedef void construction_tag_type;
+ };
+
+ template <class T>
+ struct traits<T, true>
+ {
+ BOOST_STATIC_CONSTANT(bool, is_cloneable = true);
+ typedef is_convertible<T *, default_construction_tag *> has_default_ctor_type;
+ typedef is_convertible<T *, no_default_construction_tag *> has_no_default_ctor_type;
+ /// T is default constructable only if it is convertibel to def_constr and
+ /// it is also not convertible to no_def_constr. This ensures that a type
+ /// that inherits from a type that is not default constructible, is also not
+ /// default constructible no matter what.
+ BOOST_STATIC_CONSTANT(bool, has_default_ctor = has_default_ctor_type::value || !has_no_default_ctor_type::value);
+ typedef typename mpl::if_<mpl::bool_<has_default_ctor>
+ , default_construction_tag
+ , no_default_construction_tag>
+ ::type construction_tag;
+ };
+
+ template <class T>
+ struct get_traits : traits<T, is_convertible<T *, is_cloneable_tag *>::value> { };
+
+ } // namespace impl
+
+ template <class T>
+ struct traits : impl::get_traits<T> { };
 
- template <class T>
- struct is_cloneable : mpl::bool_<traits<T>::is_cloneable> { };
+ template <class T>
+ struct is_cloneable : mpl::bool_<traits<T>::is_cloneable> { };
 
- template <class T>
- struct is_default_constructable : mpl::bool_<traits<T>::has_default_ctor> { };
+ template <class T>
+ struct is_default_constructable : mpl::bool_<traits<T>::has_default_ctor> { };
 
- } // namespace cloneable
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/cloneable/vector.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/vector.hpp (original)
+++ sandbox/cloneable/boost/cloneable/vector.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -14,101 +14,101 @@
 
 namespace boost
 {
- namespace cloneable
- {
- template <class Base, class Alloc>
- struct vector
- : detail::sequence_container_base<
- ptr_vector<
- abstract_base<Base>
- , allocator
- , typename detail::make_clone_allocator<Alloc>::type >
- , Base
- , Alloc>
- {
- typedef detail::sequence_container_base<
- ptr_vector<abstract_base<Base>
- , allocator
- , typename detail::make_clone_allocator<Alloc>::type >
- , Base
- , Alloc>
- parent_type;
- using parent_type::base_type;
- using parent_type::abstract_base_type;
- using parent_type::allocator_type;
- using parent_type::validate;
- using parent_type::new_instance;
- using parent_type::value_type;
- using parent_type::reference;
- using parent_type::const_reference;
- using parent_type::iterator;
- using parent_type::const_iterator;
-
- public:
-
- vector()
- {
- }
-
- vector(allocator_type &a)
- : parent_type(a)
- {
- }
-
- reference at(size_t n)
- {
- return impl().at(n);
- }
- const_reference at(size_t n) const
- {
- return impl().at(n);
- }
- reference operator[](size_t n)
- {
- return impl()[n];
- }
- const_reference operator[](size_t n) const
- {
- return impl()[n];
- }
-
- template <class Other>
- bool is_type_at(size_t n) const
- {
- return ptr_at<Other>(n) != 0;
- }
-
- template <class Other>
- Other &as(size_t n)
- {
- Other *ptr = pointer<Other>(n);
- if (ptr == 0)
- throw std::bad_cast();
- return *ptr;
- }
- template <class Other>
- const Other &as(size_t n) const
- {
- const Other *ptr = pointer<const Other>(n);
- if (ptr == 0)
- throw std::bad_cast();
- return *ptr;
- }
-
- template <class Other>
- Other *pointer(size_t n)
- {
- return dynamic_cast<Other *>(&at(n));
- }
- template <class Other>
- const Other *pointer(size_t n) const
- {
- return dynamic_cast<const Other *>(&at(n));
- }
-
- };
-
- } // namespace cloneable
+ namespace cloneable
+ {
+ template <class Base, class Alloc>
+ struct vector
+ : detail::sequence_container_base<
+ ptr_vector<
+ abstract_base<Base>
+ , allocator
+ , typename detail::make_clone_allocator<Alloc>::type >
+ , Base
+ , Alloc>
+ {
+ typedef detail::sequence_container_base<
+ ptr_vector<abstract_base<Base>
+ , allocator
+ , typename detail::make_clone_allocator<Alloc>::type >
+ , Base
+ , Alloc>
+ parent_type;
+ using parent_type::base_type;
+ using parent_type::abstract_base_type;
+ using parent_type::allocator_type;
+ using parent_type::validate;
+ using parent_type::new_instance;
+ using parent_type::value_type;
+ using parent_type::reference;
+ using parent_type::const_reference;
+ using parent_type::iterator;
+ using parent_type::const_iterator;
+
+ public:
+
+ vector()
+ {
+ }
+
+ vector(allocator_type &a)
+ : parent_type(a)
+ {
+ }
+
+ reference at(size_t n)
+ {
+ return impl().at(n);
+ }
+ const_reference at(size_t n) const
+ {
+ return impl().at(n);
+ }
+ reference operator[](size_t n)
+ {
+ return impl()[n];
+ }
+ const_reference operator[](size_t n) const
+ {
+ return impl()[n];
+ }
+
+ template <class Other>
+ bool is_type_at(size_t n) const
+ {
+ return ptr_at<Other>(n) != 0;
+ }
+
+ template <class Other>
+ Other &as(size_t n)
+ {
+ Other *ptr = pointer<Other>(n);
+ if (ptr == 0)
+ throw std::bad_cast();
+ return *ptr;
+ }
+ template <class Other>
+ const Other &as(size_t n) const
+ {
+ const Other *ptr = pointer<const Other>(n);
+ if (ptr == 0)
+ throw std::bad_cast();
+ return *ptr;
+ }
+
+ template <class Other>
+ Other *pointer(size_t n)
+ {
+ return dynamic_cast<Other *>(&at(n));
+ }
+ template <class Other>
+ const Other *pointer(size_t n) const
+ {
+ return dynamic_cast<const Other *>(&at(n));
+ }
+
+ };
+
+ } // namespace cloneable
 
 } // namespace boost
 

Modified: sandbox/cloneable/boost/ptr_container/detail/reversible_ptr_container.hpp
==============================================================================
--- sandbox/cloneable/boost/ptr_container/detail/reversible_ptr_container.hpp (original)
+++ sandbox/cloneable/boost/ptr_container/detail/reversible_ptr_container.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -51,8 +51,8 @@
     template< class CloneAllocator, class Alloc >
     struct clone_deleter
     {
- Alloc &alloc;
- clone_deleter(Alloc &a) : alloc(a) { }
+ Alloc &alloc;
+ clone_deleter(Alloc &a) : alloc(a) { }
         template< class T >
         void operator()( const T* p ) const
         {
@@ -117,35 +117,35 @@
                 return res;
             }
             
- template< class Iter, class Alloc >
- static Ty_* allocate_clone_from_iterator( Iter i, Alloc &alloc )
- {
- return allocate_clone( Config::get_const_pointer( i ), alloc );
- }
-
- template <class Alloc>
- static Ty_* allocate_clone( const Ty_* x, Alloc &alloc )
- {
- if( allow_null_values )
- {
- if( x == 0 )
- return 0;
- }
- else
- {
- BOOST_ASSERT( x != 0 && "Cannot insert clone of null!" );
- }
-
- Ty_* res = CloneAllocator::allocate_clone( *x, alloc );
- BOOST_ASSERT( typeid(*res) == typeid(*x) &&
- "CloneAllocator::allocate_clone() does not clone the "
- "object properly. Check that new_clone() is implemented"
- " correctly" );
- return res;
- }
+ template< class Iter, class Alloc >
+ static Ty_* allocate_clone_from_iterator( Iter i, Alloc &alloc )
+ {
+ return allocate_clone( Config::get_const_pointer( i ), alloc );
+ }
+
+ template <class Alloc>
+ static Ty_* allocate_clone( const Ty_* x, Alloc &alloc )
+ {
+ if( allow_null_values )
+ {
+ if( x == 0 )
+ return 0;
+ }
+ else
+ {
+ BOOST_ASSERT( x != 0 && "Cannot insert clone of null!" );
+ }
+
+ Ty_* res = CloneAllocator::allocate_clone( *x, alloc );
+ BOOST_ASSERT( typeid(*res) == typeid(*x) &&
+ "CloneAllocator::allocate_clone() does not clone the "
+ "object properly. Check that new_clone() is implemented"
+ " correctly" );
+ return res;
+ }
 
- template <class Alloc>
- static void deallocate_clone( const Ty_* x, Alloc &alloc )
+ template <class Alloc>
+ static void deallocate_clone( const Ty_* x, Alloc &alloc )
             {
                 if( allow_null_values )
                 {
@@ -164,7 +164,7 @@
 #else
         typedef null_clone_allocator<allow_null> null_cloner_type;
 #endif
- typedef clone_deleter<null_cloner_type, typename Config::allocator_type> Deleter;
+ typedef clone_deleter<null_cloner_type, typename Config::allocator_type> Deleter;
 
         Cont c_;
 
@@ -293,13 +293,13 @@
 
         static Ty_* null_policy_allocate_clone( const Ty_* x )
         {
- allocator_type alloc;
+ allocator_type alloc;
             return null_cloner_type::allocate_clone( x, alloc);
         }
 
         static void null_policy_deallocate_clone( const Ty_* x )
         {
- allocator_type alloc;
+ allocator_type alloc;
             null_cloner_type::deallocate_clone( x, alloc );
         }
 

Modified: sandbox/cloneable/boost/ptr_container/detail/scoped_deleter.hpp
==============================================================================
--- sandbox/cloneable/boost/ptr_container/detail/scoped_deleter.hpp (original)
+++ sandbox/cloneable/boost/ptr_container/detail/scoped_deleter.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -32,7 +32,7 @@
             scoped_array<T*> ptrs_;
             size_type stored_;
             bool released_;
- Alloc &alloc;
+ Alloc &alloc;
             
         public:
             scoped_deleter( T** a, size_type size, Alloc &al )

Modified: sandbox/cloneable/boost/ptr_container/indirect_fun.hpp
==============================================================================
--- sandbox/cloneable/boost/ptr_container/indirect_fun.hpp (original)
+++ sandbox/cloneable/boost/ptr_container/indirect_fun.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -33,7 +33,7 @@
 {
 
 
- // CJS: why does this take one or two arguments?
+ // CJS: why does this take one or two arguments?
     template
     <
               class Fun

Modified: sandbox/cloneable/boost/ptr_container/ptr_map.hpp
==============================================================================
--- sandbox/cloneable/boost/ptr_container/ptr_map.hpp (original)
+++ sandbox/cloneable/boost/ptr_container/ptr_map.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -63,8 +63,8 @@
         BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_map, base_type,
                                                       this_type )
 
- template< class U >
- ptr_map( const ptr_map<Key,U>& r ) : base_type( r )
+ template< class U, class P2, class Cal2, class Al2 >
+ ptr_map( const ptr_map<Key,U,P2,Cal2,Al2>& r ) : base_type( r )
         { }
 
         ptr_map& operator=( ptr_map r )
@@ -118,8 +118,8 @@
                                                       base_type,
                                                       this_type )
 
- template< class U >
- ptr_multimap( const ptr_multimap<Key,U>& r ) : base_type( r )
+ template< class U,class P2,class Cal2, class Al2 >
+ ptr_multimap( const ptr_multimap<Key,U,P2,Cal2,Al2>& r ) : base_type( r )
         { }
 
         ptr_multimap& operator=( ptr_multimap r )

Modified: sandbox/cloneable/boost/ptr_container/ptr_map_adapter.hpp
==============================================================================
--- sandbox/cloneable/boost/ptr_container/ptr_map_adapter.hpp (original)
+++ sandbox/cloneable/boost/ptr_container/ptr_map_adapter.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -210,7 +210,7 @@
             else
             {
                 eraser e(&this->base(),key); // nothrow
- // CJS: why oh use `new T()` !!
+ // CJS: why oh use `new T()` !!
                 mapped_type res = new T(); // strong
                 ref = res; // nothrow
                 e.release(); // nothrow

Modified: sandbox/cloneable/boost/ptr_container/ptr_vector.hpp
==============================================================================
--- sandbox/cloneable/boost/ptr_container/ptr_vector.hpp (original)
+++ sandbox/cloneable/boost/ptr_container/ptr_vector.hpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -23,12 +23,12 @@
 {
 
 
- //template
- //<
- // class T,
- // class Allocator = std::allocator<void*>,
- // class CloneAllocator = cloneable::make_cloneable_allocator<Al>
- //>
+ //template
+ //<
+ // class T,
+ // class Allocator = std::allocator<void*>,
+ // class CloneAllocator = cloneable::make_cloneable_allocator<Al>
+ //>
 
     template
     <
@@ -61,7 +61,7 @@
             this->base().reserve( n );
         }
 
- };
+ };
 
     //////////////////////////////////////////////////////////////////////////////
     // clonability

Modified: sandbox/cloneable/libs/cloneable/test/tests.cpp
==============================================================================
--- sandbox/cloneable/libs/cloneable/test/tests.cpp (original)
+++ sandbox/cloneable/libs/cloneable/test/tests.cpp 2009-07-07 19:04:46 EDT (Tue, 07 Jul 2009)
@@ -23,7 +23,7 @@
 
 #include <boost/cloneable/clone.hpp>
 #include <boost/cloneable/vector.hpp>
-#include <boost/cloneable/list.hpp>
+#include <boost/cloneable/list.hpp>`
 #include <boost/cloneable/map.hpp>
 #include <boost/cloneable/set.hpp>
 #include <boost/cloneable/heterogenous_map.hpp>
@@ -34,172 +34,182 @@
 #include <boost/test/unit_test.hpp>
 #include <boost/timer.hpp>
 
+//#include "/temp/tree.hh"
+
 using namespace std;
 using namespace boost;
 using namespace cloneable;
 
-
+/*
+BOOST_AUTO_TEST_CASE(test_tree)
+{
+ typedef tree<int, monotonic::allocator<int> > Tree;
+ Tree t;
+ Tree::pre_order_iterator head = t.set_head(42);
+ t.append_child(head, 12);
+}
+*/
 
 namespace basic_test
 {
- struct my_base { virtual ~my_base() { } };
- struct T0 : cloneable::base<T0, my_base> {};
- struct T1 : cloneable::base<T1, my_base> {};
- struct T2 : cloneable::base<T2, my_base> {};
- struct T3 : cloneable::base<T3, my_base> {};
-
- template <class T>
- T *clone(const my_base &base)
- {
- return dynamic_cast<T *>(dynamic_cast<const abstract_base<my_base> &>(base).clone());
- }
+ struct my_base { virtual ~my_base() { } };
+ struct T0 : cloneable::base<T0, my_base> {};
+ struct T1 : cloneable::base<T1, my_base> {};
+ struct T2 : cloneable::base<T2, my_base> {};
+ struct T3 : cloneable::base<T3, my_base> {};
+
+ template <class T>
+ T *clone(const my_base &base)
+ {
+ return dynamic_cast<T *>(dynamic_cast<const abstract_base<my_base> &>(base).clone());
+ }
 }
 
 template <class T, class Base>
 T *clone(const cloneable::abstract_base<Base> &base)
 {
- return base.clone_as<T>();
+ return base.clone_as<T>();
 }
 
 BOOST_AUTO_TEST_CASE(test_basic)
 {
- using namespace basic_test;
+ using namespace basic_test;
 
- // basic cloning
- T0 *t0 = new T0();
- T0 *t0_clone = dynamic_cast<T0 *>(t0->clone());
- BOOST_ASSERT(typeid(*t0_clone) == typeid(T0));
-
- // cloning from a raw base type
- my_base *t0_base = new T0();
- T0 *t0_base_clone = cloneable::clone_as<T0>(*t0_base);
- BOOST_ASSERT(t0_base_clone != 0);
-
- // make a new object from an existing base
- my_base *t0_new = cloneable::create_new(*t0_base);
- BOOST_ASSERT(t0_new && typeid(*t0_new) == typeid(T0));
-
- delete t0_base;
- delete t0_base_clone;
- delete t0_new;
-
- // cloning from an abstract_base_type
- BOOST_STATIC_ASSERT((is_same<my_base, T1::base_type>::value));
- BOOST_STATIC_ASSERT((is_same<cloneable::abstract_base<my_base>, T1::abstract_base_type>::value));
- T1::abstract_base_type *t1_base = new T1();
-
- // query for supported clone types
- BOOST_ASSERT(t1_base->can_clone_as<T1>());
- BOOST_ASSERT(!t1_base->can_clone_as<T2>());
-
- T1 *t1_clone = t1_base->clone_as<T1>();
- BOOST_ASSERT(t1_clone != 0);
-
- // use a free-function from a generalised abstract_base
- T2 *t2 = new T2;
- T2 *t2_clone = clone<T2>(*t2);
- BOOST_ASSERT(typeid(*t2_clone) == typeid(T2));
-
- // use a free-function from a specific base
- my_base *t3 = new T3;
- T3 *t3_clone = basic_test::clone<T3>(*t3);
- BOOST_ASSERT(typeid(*t3_clone) == typeid(T3));
-
- delete t0;
- delete t0_clone;
- delete t1_base;
- delete t1_clone;
- delete t2;
- delete t2_clone;
- delete t3;
- delete t3_clone;
+ // basic cloning
+ T0 *t0 = new T0();
+ T0 *t0_clone = dynamic_cast<T0 *>(t0->clone());
+ BOOST_ASSERT(typeid(*t0_clone) == typeid(T0));
+
+ // cloning from a raw base type
+ my_base *t0_base = new T0();
+ T0 *t0_base_clone = cloneable::clone_as<T0>(*t0_base);
+ BOOST_ASSERT(t0_base_clone != 0);
+
+ // make a new object from an existing base
+ my_base *t0_new = cloneable::create_new(*t0_base);
+ BOOST_ASSERT(t0_new && typeid(*t0_new) == typeid(T0));
+
+ delete t0_base;
+ delete t0_base_clone;
+ delete t0_new;
+
+ // cloning from an abstract_base_type
+ BOOST_STATIC_ASSERT((is_same<my_base, T1::base_type>::value));
+ BOOST_STATIC_ASSERT((is_same<cloneable::abstract_base<my_base>, T1::abstract_base_type>::value));
+ T1::abstract_base_type *t1_base = new T1();
+
+ // query for supported clone types
+ BOOST_ASSERT(t1_base->can_clone_as<T1>());
+ BOOST_ASSERT(!t1_base->can_clone_as<T2>());
+
+ T1 *t1_clone = t1_base->clone_as<T1>();
+ BOOST_ASSERT(t1_clone != 0);
+
+ // use a free-function from a generalised abstract_base
+ T2 *t2 = new T2;
+ T2 *t2_clone = clone<T2>(*t2);
+ BOOST_ASSERT(typeid(*t2_clone) == typeid(T2));
+
+ // use a free-function from a specific base
+ my_base *t3 = new T3;
+ T3 *t3_clone = basic_test::clone<T3>(*t3);
+ BOOST_ASSERT(typeid(*t3_clone) == typeid(T3));
+
+ delete t0;
+ delete t0_clone;
+ delete t1_base;
+ delete t1_clone;
+ delete t2;
+ delete t2_clone;
+ delete t3;
+ delete t3_clone;
 }
 
 namespace mulitple_inheritance_test
 {
- struct Q0 : base<Q0>
- {
- int num;
- Q0(int n = 0) : num(n) { }
- };
-
- /// derive from Q0, which is also cloneable<>
- struct Q1 : Q0, base<Q1>
- {
- string str;
- Q1() { }
- Q1(const char * t) : str(t) { }
- };
-
- struct W : base<W> { };
-
- struct Q2 : W, Q1, base<Q2>
- {
- };
+ struct Q0 : base<Q0>
+ {
+ int num;
+ Q0(int n = 0) : num(n) { }
+ };
+
+ /// derive from Q0, which is also cloneable<>
+ struct Q1 : Q0, base<Q1>
+ {
+ string str;
+ Q1() { }
+ Q1(const char * t) : str(t) { }
+ };
+
+ struct W : base<W> { };
+
+ struct Q2 : W, Q1, base<Q2>
+ {
+ };
 
- struct my_region { };
+ struct my_region { };
 }
 
 BOOST_AUTO_TEST_CASE(test_multiple_inheritance)
 {
- using namespace mulitple_inheritance_test;
+ using namespace mulitple_inheritance_test;
 
- // just for spice, use a regionalised monotonic allocator for creating
- // originals, and producing clones.
- // at least this way we don't have to free anything...
- monotonic::local<my_region> local;
- monotonic::allocator<int,my_region> alloc = local.make_allocator<int>();
-
- Q0 *q0 = create<Q0>(alloc);
- BOOST_ASSERT(typeid(*q0) == typeid(Q0));
-
- Q0 *q0_c = q0->clone_as<Q0>(alloc);
- BOOST_ASSERT(typeid(*q0_c) == typeid(Q0));
-
- Q1 *q1 = create<Q1>(alloc);
- BOOST_ASSERT(typeid(*q1) == typeid(Q1));
-
- Q0 *q1_c0 = q1->clone_as<Q0>(alloc);
- BOOST_ASSERT(typeid(*q1_c0) == typeid(Q0));
-
- Q1 *q1_c1 = q1->clone_as<Q1>(alloc);
- BOOST_ASSERT(typeid(*q1_c1) == typeid(Q1));
-
- // create new sub-objects
- Q2 *q2 = create<Q2>(alloc);
- Q0 *q2_0 = q2->create_as<Q0>(alloc);
- Q1 *q2_1 = q2->create_as<Q1>(alloc);
- W *q2_w = q2->create_as<W>(alloc);
- BOOST_ASSERT(q2_0 && q2_1 && q2_w);
-}
+ // just for spice, use a regionalised monotonic allocator for creating
+ // originals, and producing clones.
+ // at least this way we don't have to free anything...
+ monotonic::local<my_region> local;
+ monotonic::allocator<int,my_region> alloc = local.make_allocator<int>();
+
+ Q0 *q0 = create<Q0>(alloc);
+ BOOST_ASSERT(typeid(*q0) == typeid(Q0));
+
+ Q0 *q0_c = q0->clone_as<Q0>(alloc);
+ BOOST_ASSERT(typeid(*q0_c) == typeid(Q0));
+
+ Q1 *q1 = create<Q1>(alloc);
+ BOOST_ASSERT(typeid(*q1) == typeid(Q1));
+
+ Q0 *q1_c0 = q1->clone_as<Q0>(alloc);
+ BOOST_ASSERT(typeid(*q1_c0) == typeid(Q0));
+
+ Q1 *q1_c1 = q1->clone_as<Q1>(alloc);
+ BOOST_ASSERT(typeid(*q1_c1) == typeid(Q1));
+
+ // create new sub-objects
+ Q2 *q2 = create<Q2>(alloc);
+ Q0 *q2_0 = q2->create_as<Q0>(alloc);
+ Q1 *q2_1 = q2->create_as<Q1>(alloc);
+ W *q2_w = q2->create_as<W>(alloc);
+ BOOST_ASSERT(q2_0 && q2_1 && q2_w);
+}
 
 namespace mi_test_2
 {
- struct Base { virtual ~Base() { } };
- struct T0 : base<T0, Base> { };
- struct T1 : T0, base<T1, Base> { };
- struct W : base<W, Base> { };
- struct T2 : W, T1, base<T2, Base> { };
+ struct Base { virtual ~Base() { } };
+ struct T0 : base<T0, Base> { };
+ struct T1 : T0, base<T1, Base> { };
+ struct W : base<W, Base> { };
+ struct T2 : W, T1, base<T2, Base> { };
 }
 
 BOOST_AUTO_TEST_CASE(test_mi_2)
 {
- using namespace mi_test_2;
- using namespace cloneable;
+ using namespace mi_test_2;
+ using namespace cloneable;
 
     T2 *t2 = new T2();
 
- assert(t2->can_clone_as<T0>());
- assert(t2->can_clone_as<T1>());
- assert(t2->can_clone_as<T2>());
- assert(t2->can_clone_as<W>());
+ assert(t2->can_clone_as<T0>());
+ assert(t2->can_clone_as<T1>());
+ assert(t2->can_clone_as<T2>());
+ assert(t2->can_clone_as<W>());
     
- assert(t2->can_create_as<T0>());
- assert(t2->can_create_as<T1>());
- assert(t2->can_create_as<T2>());
- assert(t2->can_create_as<W>());
+ assert(t2->can_create_as<T0>());
+ assert(t2->can_create_as<T1>());
+ assert(t2->can_create_as<T2>());
+ assert(t2->can_create_as<W>());
 
- // these free-functions currently do not work...
+ // these free-functions currently do not work...
    /* assert(can_clone_as<W>(*t2));
     assert(can_clone_as<T0>(*t2));
     assert(can_clone_as<T1>(*t2));
@@ -222,133 +232,133 @@
     T1 *t2_t1_new = t2->create_as<T1>();
     T2 *t2_t2_new = t2->create_as<T2>();
 
- delete t2;
- delete t2_w;
- delete t2_t0;
- delete t2_t1;
- delete t2_t2;
- delete t2_w_new;
- delete t2_t0_new;
- delete t2_t1_new;
- delete t2_t2_new;
+ delete t2;
+ delete t2_w;
+ delete t2_t0;
+ delete t2_t1;
+ delete t2_t2;
+ delete t2_w_new;
+ delete t2_t0_new;
+ delete t2_t1_new;
+ delete t2_t2_new;
 }
 
 
 BOOST_AUTO_TEST_CASE(test_multiple_inheritance_vector)
 {
- using namespace mulitple_inheritance_test;
- typedef cloneable::vector<> vec;
-
- vec v;
- v.push_back<Q0>(42);
- v.push_back<Q1>("foo");
-
- Q0 &q0 = v.as<Q0>(0);
- Q1 &q1 = v.as<Q1>(1);
-
- // ensure duplication of types with multiple cloneable sub-objects works correctly
- vec v2 = v;
-
- BOOST_ASSERT(v2.as<Q0>(0).num == 42);
- BOOST_ASSERT(v2.as<Q1>(1).str == "foo");
+ using namespace mulitple_inheritance_test;
+ typedef cloneable::vector<> vec;
+
+ vec v;
+ v.push_back<Q0>(42);
+ v.push_back<Q1>("foo");
+
+ Q0 &q0 = v.as<Q0>(0);
+ Q1 &q1 = v.as<Q1>(1);
+
+ // ensure duplication of types with multiple cloneable sub-objects works correctly
+ vec v2 = v;
+
+ BOOST_ASSERT(v2.as<Q0>(0).num == 42);
+ BOOST_ASSERT(v2.as<Q1>(1).str == "foo");
 }
 
 namespace custom_clone_test
 {
- struct T0 : base<T0>
- {
- bool custom_cloned;
- T0() : custom_cloned(false) { }
-
- /// override the means to create a copy of this
- T0 *make_copy(abstract_allocator &alloc) const
- {
- T0 *ptr = cloneable::create<T0>(alloc);
- ptr->custom_cloned = true;
- return ptr;
- }
- };
+ struct T0 : base<T0>
+ {
+ bool custom_cloned;
+ T0() : custom_cloned(false) { }
+
+ /// override the means to create a copy of this
+ T0 *make_copy(abstract_allocator &alloc) const
+ {
+ T0 *ptr = cloneable::create<T0>(alloc);
+ ptr->custom_cloned = true;
+ return ptr;
+ }
+ };
 }
 
 BOOST_AUTO_TEST_CASE(test_custom_clone)
 {
- using namespace custom_clone_test;
- abstract_base<> *p = new T0();
- T0 *q = dynamic_cast<T0 *>(p->clone());
- BOOST_ASSERT(q && q->custom_cloned);
- delete p;
- delete q;
+ using namespace custom_clone_test;
+ abstract_base<> *p = new T0();
+ T0 *q = dynamic_cast<T0 *>(p->clone());
+ BOOST_ASSERT(q && q->custom_cloned);
+ delete p;
+ delete q;
 }
 
 namespace no_default_ctor_test
 {
- struct T0 : base<T0, base_type, no_default_construction_tag>
- {
- T0(int) { }
- };
- struct T1 : T0, base<T1>
- {
- T1() : T0(4) { }
- };
+ struct T0 : base<T0, base_type, no_default_construction_tag>
+ {
+ T0(int) { }
+ };
+ struct T1 : T0, base<T1>
+ {
+ T1() : T0(4) { }
+ };
 }
 
 BOOST_AUTO_TEST_CASE(test_no_default_ctor)
 {
- using namespace no_default_ctor_test;
- T0 *p = new T0(10);
+ using namespace no_default_ctor_test;
+ T0 *p = new T0(10);
 
- // ensure we can clone, even without a default ctor
- T0 *q = p->clone_as<T0>();
- BOOST_ASSERT(q && typeid(*q) == typeid(T0));
-
- // ensure we fail to make a default-constructed new object
- delete q;
- bool caught = false;
- try
- {
- base_type *r = p->create();
- }
- catch (no_default_construction)
- {
- caught = true;
- }
- BOOST_ASSERT(caught);
-
- T1 *p1 = new T1();
- // ensure we can clone a type that is derived from a type that is not
- // default constructable
- T1 *p1_clone = p1->clone_as<T1>();
- BOOST_ASSERT(p1_clone);
-
- // ensure that if we try to make a new sub-object that is not
- // default-constructable, we throw
- caught = false;
- try
- {
- p1_clone->create_as<T0>();
- }
- catch (no_default_construction)
- {
- caught = true;
- }
- BOOST_ASSERT(caught);
-
- delete p;
- delete p1;
- delete p1_clone;
+ // ensure we can clone, even without a default ctor
+ T0 *q = p->clone_as<T0>();
+ BOOST_ASSERT(q && typeid(*q) == typeid(T0));
+
+ // ensure we fail to make a default-constructed new object
+ delete q;
+ bool caught = false;
+ try
+ {
+ base_type *r = p->create();
+ }
+ catch (no_default_construction)
+ {
+ caught = true;
+ }
+ BOOST_ASSERT(caught);
+
+ T1 *p1 = new T1();
+ // ensure we can clone a type that is derived from a type that is not
+ // default constructable
+ T1 *p1_clone = p1->clone_as<T1>();
+ BOOST_ASSERT(p1_clone);
+
+ // ensure that if we try to make a new sub-object that is not
+ // default-constructable, we throw
+ caught = false;
+ try
+ {
+ p1_clone->create_as<T0>();
+ }
+ catch (no_default_construction)
+ {
+ caught = true;
+ }
+ BOOST_ASSERT(caught);
+
+ delete p;
+ delete p1;
+ delete p1_clone;
 }
 
 struct my_base
 {
- virtual ~my_base() { }
+ virtual ~my_base() { }
 };
 
 /// some external type that we cannot change
 struct external_type
 {
- std::string text;
- external_type() { }
- external_type(const char *T) : text(T) { }
+ std::string text;
+ external_type() { }
+ external_type(const char *T) : text(T) { }
 };
 
 /// make an adaptor type, which makes `external_type` cloneable
@@ -356,438 +366,437 @@
 
 BOOST_AUTO_TEST_CASE(test_external_types)
 {
- // for spice, use stack for storage
- monotonic::storage<> storage;
- monotonic::allocator<int> alloc(storage);
+ // for spice, use stack for storage
+ monotonic::storage<> storage;
+ monotonic::allocator<int> alloc(storage);
 
- cloneable_external_type *ext = create<cloneable_external_type>(alloc);
- BOOST_ASSERT(typeid(*ext) == typeid(cloneable_external_type));
+ cloneable_external_type *ext = create<cloneable_external_type>(alloc);
+ BOOST_ASSERT(typeid(*ext) == typeid(cloneable_external_type));
 
- cloneable_external_type *clone = ext->clone_as<cloneable_external_type>(alloc);
- BOOST_ASSERT(typeid(*clone) == typeid(cloneable_external_type));
+ cloneable_external_type *clone = ext->clone_as<cloneable_external_type>(alloc);
+ BOOST_ASSERT(typeid(*clone) == typeid(cloneable_external_type));
 }
 
 namespace traits_test
 {
- struct T0 : base<T0> { };
- struct T1 : base<T1, base_type, no_default_construction_tag> { };
- struct T2 { };
+ struct T0 : base<T0> { };
+ struct T1 : base<T1, base_type, no_default_construction_tag> { };
+ struct T2 { };
 }
 
 BOOST_AUTO_TEST_CASE(test_traits)
 {
- using namespace traits_test;
- typedef traits<T0> t0_traits;
+ using namespace traits_test;
+ typedef traits<T0> t0_traits;
 
- BOOST_STATIC_ASSERT(is_cloneable<T0>::value);
- BOOST_STATIC_ASSERT(is_default_constructable<T0>::value);
+ BOOST_STATIC_ASSERT(is_cloneable<T0>::value);
+ BOOST_STATIC_ASSERT(is_default_constructable<T0>::value);
 
- BOOST_STATIC_ASSERT(is_cloneable<T1>::value);
- BOOST_STATIC_ASSERT(!is_default_constructable<T1>::value);
-
- BOOST_STATIC_ASSERT(!is_cloneable<T2>::value);
- BOOST_STATIC_ASSERT(!is_default_constructable<T2>::value);
+ BOOST_STATIC_ASSERT(is_cloneable<T1>::value);
+ BOOST_STATIC_ASSERT(!is_default_constructable<T1>::value);
+
+ BOOST_STATIC_ASSERT(!is_cloneable<T2>::value);
+ BOOST_STATIC_ASSERT(!is_default_constructable<T2>::value);
 }
 
 namespace free_clone_test
 {
- struct T0 { };
- struct T1 : base<T1>
- {
- bool copy_constructed;
- T1() : copy_constructed(false) { }
- T1(T1 const &) : copy_constructed(true) { }
- };
+ struct T0 { };
+ struct T1 : base<T1>
+ {
+ bool copy_constructed;
+ T1() : copy_constructed(false) { }
+ T1(T1 const &) : copy_constructed(true) { }
+ };
 }
 
 BOOST_AUTO_TEST_CASE(test_free_clone)
 {
- using namespace free_clone_test;
- T0 *t0 = new T0();
- T1 *t1 = new T1();
-
- // test cloning on a type that does not derive from cloneable::base<>
- // this will use new T0(orig);
- T0 *t0_clone = clone(*t0);
-
- // clone using cloneable system
- T1 *t1_clone = clone(*t1);
-
- BOOST_ASSERT(t0_clone);
- BOOST_ASSERT(t1_clone);
- BOOST_ASSERT(t1_clone->copy_constructed);
-
- delete t0;
- delete t1;
- delete t0_clone;
- delete t1_clone;
+ using namespace free_clone_test;
+ T0 *t0 = new T0();
+ T1 *t1 = new T1();
+
+ // test cloning on a type that does not derive from cloneable::base<>
+ // this will use new T0(orig);
+ T0 *t0_clone = clone(*t0);
+
+ // clone using cloneable system
+ T1 *t1_clone = clone(*t1);
+
+ BOOST_ASSERT(t0_clone);
+ BOOST_ASSERT(t1_clone);
+ BOOST_ASSERT(t1_clone->copy_constructed);
+
+ delete t0;
+ delete t1;
+ delete t0_clone;
+ delete t1_clone;
 }
 
 //struct custom_external_cloneable : adaptor<external_type, my_base>
 //{
-// custom_external_cloneable *clone(abstract_allocator &alloc) const
-// {
-// custom_external_cloneable *ptr = create<custom_external_cloneable>(alloc);
-// ptr->text = "custom_cloned";
-// return ptr;
-// }
+// custom_external_cloneable *clone(abstract_allocator &alloc) const
+// {
+// custom_external_cloneable *ptr = create<custom_external_cloneable>(alloc);
+// ptr->text = "custom_cloned";
+// return ptr;
+// }
 //};
 //
 //BOOST_AUTO_TEST_CASE(test_custom_external_clone)
 //{
-// custom_external_cloneable *p = new custom_external_cloneable;
-// custom_external_cloneable *q = p->clone_as<custom_external_cloneable>();
-// BOOST_ASSERT(typeid(*q) == typeid(custom_external_cloneable));
+// custom_external_cloneable *p = new custom_external_cloneable;
+// custom_external_cloneable *q = p->clone_as<custom_external_cloneable>();
+// BOOST_ASSERT(typeid(*q) == typeid(custom_external_cloneable));
 //}
 
 struct T0 : base<T0, my_base>
 {
- int num;
- T0() : num(0) { }
- T0(int n) : num(n) { }
+ int num;
+ T0() : num(0) { }
+ T0(int n) : num(n) { }
 
 };
 
 struct T1 : base<T1, my_base>
 {
- std::string str;
+ std::string str;
 
- T1() { }
- T1(std::string const &n) : str(n) { }
+ T1() { }
+ T1(std::string const &n) : str(n) { }
 };
 
 struct T2 : base<T2, my_base>
 {
- float real;
- int num;
- std::string str;
-
- T2() { }
- T2(float f, int n, std::string const &s) : real(f), num(n), str(s) { }
-
- void print() const
- {
- cout << "derived3: " << real << ", " << num << ", " << str << endl;
- }
+ float real;
+ int num;
+ std::string str;
+
+ T2() { }
+ T2(float f, int n, std::string const &s) : real(f), num(n), str(s) { }
+
+ void print() const
+ {
+ cout << "derived3: " << real << ", " << num << ", " << str << endl;
+ }
 };
 
 BOOST_AUTO_TEST_CASE(test_instance)
 {
- //make_clone_allocator<std::allocator<char> > alloc;
- //instance<T2> ins(alloc, 3.14f, 42, "spam");
- //instance<T2> copy = ins.clone();
- //BOOST_ASSERT(ins.exists() && ins->str == "spam");
- //BOOST_ASSERT(copy.exists() && copy->str == "spam");
+ //make_clone_allocator<std::allocator<char> > alloc;
+ //instance<T2> ins(alloc, 3.14f, 42, "spam");
+ //instance<T2> copy = ins.clone();
+ //BOOST_ASSERT(ins.exists() && ins->str == "spam");
+ //BOOST_ASSERT(copy.exists() && copy->str == "spam");
 }
 
 BOOST_AUTO_TEST_CASE(test_vector)
 {
- // this uses the base type for the contained elements as a region tag for a monotonic allocator.
- // totally unnecessary, could just use a std::allocator, but this way gives more control
- typedef cloneable::vector<my_base, monotonic::allocator<my_base, my_base> > vec;
-
- // use a local scoped object to automatically release resources used by the my_base monotonic
- // storage region on function exit.
- monotonic::local<my_base> local;
- {
- vec bases;
-
- // type of thing to insert must be passed explicitly, and must derive from common_base.
- // arguments to push_back are passed directly to ctor
- bases.push_back<T0>(42);
- bases.push_back<T1>("foo");
- bases.push_back<T2>(3.14f, -123, "spam");
- bases.push_back<cloneable_external_type>("external");
-
- // perform functor on each contained object of the given type
- bases.for_each<T2>(boost::bind(&T2::print, _1));
-
- // does a deep copy, preserving concrete types
- vec copy = bases;
-
- // each object in the container can be retrieved generically as a 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
- T0 &p1 = copy.as<T0>(0);
-
- // get a pointer; returns null on type mismatch
- T1 *p2 = copy.pointer<T1>(1);
- T2 *p3 = copy.pointer<T2>(2);
-
- BOOST_ASSERT(p2);
- BOOST_ASSERT(p3);
-
- BOOST_ASSERT(p1.num == 42);
- BOOST_ASSERT(p2->str == "foo");
- BOOST_ASSERT(p3->real == 3.14f);
- BOOST_ASSERT(p3->num == -123);
- BOOST_ASSERT(p3->str == "spam");
- BOOST_ASSERT(copy.as<cloneable_external_type>(3).text == "external");
-
- bool caught = false;
- try
- {
- my_base &base = copy.as<T1>(0);
- }
- catch (std::bad_cast)
- {
- caught = true;
- }
- BOOST_ASSERT(caught);
+ // this uses the base type for the contained elements as a region tag for a monotonic allocator.
+ // totally unnecessary, could just use a std::allocator, but this way gives more control
+ typedef cloneable::vector<my_base, monotonic::allocator<my_base, my_base> > vec;
+
+ // use a local scoped object to automatically release resources used by the my_base monotonic
+ // storage region on function exit.
+ monotonic::local<my_base> local;
+ {
+ vec bases;
+
+ // type of thing to insert must be passed explicitly, and must derive from common_base.
+ // arguments to push_back are passed directly to ctor
+ bases.push_back<T0>(42);
+ bases.push_back<T1>("foo");
+ bases.push_back<T2>(3.14f, -123, "spam");
+ bases.push_back<cloneable_external_type>("external");
+
+ // perform functor on each contained object of the given type
+ bases.for_each<T2>(boost::bind(&T2::print, _1));
+
+ // does a deep copy, preserving concrete types
+ vec copy = bases;
+
+ // each object in the container can be retrieved generically as a 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
+ T0 &p1 = copy.as<T0>(0);
+
+ // get a pointer; returns null on type mismatch
+ T1 *p2 = copy.pointer<T1>(1);
+ T2 *p3 = copy.pointer<T2>(2);
+
+ BOOST_ASSERT(p2);
+ BOOST_ASSERT(p3);
+
+ BOOST_ASSERT(p1.num == 42);
+ BOOST_ASSERT(p2->str == "foo");
+ BOOST_ASSERT(p3->real == 3.14f);
+ BOOST_ASSERT(p3->num == -123);
+ BOOST_ASSERT(p3->str == "spam");
+ BOOST_ASSERT(copy.as<cloneable_external_type>(3).text == "external");
+
+ bool caught = false;
+ try
+ {
+ my_base &base = copy.as<T1>(0);
+ }
+ catch (std::bad_cast)
+ {
+ caught = true;
+ }
+ BOOST_ASSERT(caught);
 
- }
+ }
 }
 
 namespace list_test
 {
- struct list_test_base
- {
- int num;
- list_test_base(int n = 0) : num(n) { }
- friend bool operator<(list_test::list_test_base const &left, list_test::list_test_base const &right)
- {
- return left.num < right.num;
- }
- friend bool operator==(list_test::list_test_base const &left, list_test::list_test_base const &right)
- {
- return left.num == right.num;
- }
- };
-
- struct L0 : base<L0, list_test_base, no_default_construction_tag>
- {
- L0(int n) : list_test_base(n) { }
- };
- struct L1 : base<L1, list_test_base, no_default_construction_tag>
- {
- L1(string s, int n) : list_test_base(n) { }
- };
- struct L2 : base<L2, list_test_base, no_default_construction_tag>
- {
- L2(float f, int n, string s) : list_test_base(n) { }
- };
+ struct list_test_base
+ {
+ int num;
+ list_test_base(int n = 0) : num(n) { }
+ friend bool operator<(list_test::list_test_base const &left, list_test::list_test_base const &right)
+ {
+ return left.num < right.num;
+ }
+ friend bool operator==(list_test::list_test_base const &left, list_test::list_test_base const &right)
+ {
+ return left.num == right.num;
+ }
+ };
+
+ struct L0 : base<L0, list_test_base, no_default_construction_tag>
+ {
+ L0(int n) : list_test_base(n) { }
+ };
+ struct L1 : base<L1, list_test_base, no_default_construction_tag>
+ {
+ L1(string s, int n) : list_test_base(n) { }
+ };
+ struct L2 : base<L2, list_test_base, no_default_construction_tag>
+ {
+ L2(float f, int n, string s) : list_test_base(n) { }
+ };
 }
 
 
 BOOST_AUTO_TEST_CASE(test_list)
 {
- using namespace list_test;
- typedef cloneable::list<list_test_base> list;
- list l0;
- l0.push_back<L0>(42);
- l0.push_back<L1>("foo", 123);
- l0.push_back<L2>(3.14f, -123, "spam");
-
- list l1 = l0;
- bool b = l0.front() == l0.back();
- BOOST_ASSERT(l0 == l1);
- BOOST_ASSERT(!(l0 < l1));
- BOOST_ASSERT(!(l1 < l0));
- list::reference e = l1.front();
- e.num = 41;
- BOOST_ASSERT(l1 < l0);
-
- list::iterator iter = l1.begin();
- BOOST_ASSERT(typeid(*iter++) == typeid(L0));
- BOOST_ASSERT(typeid(*iter++) == typeid(L1));
- BOOST_ASSERT(typeid(*iter++) == typeid(L2));
+ using namespace list_test;
+ typedef cloneable::list<list_test_base> list;
+ list l0;
+ l0.push_back<L0>(42);
+ l0.push_back<L1>("foo", 123);
+ l0.push_back<L2>(3.14f, -123, "spam");
+
+ list l1 = l0;
+ bool b = l0.front() == l0.back();
+ BOOST_ASSERT(l0 == l1);
+ BOOST_ASSERT(!(l0 < l1));
+ BOOST_ASSERT(!(l1 < l0));
+ list::reference e = l1.front();
+ e.num = 41;
+ BOOST_ASSERT(l1 < l0);
+
+ list::iterator iter = l1.begin();
+ BOOST_ASSERT(typeid(*iter++) == typeid(L0));
+ BOOST_ASSERT(typeid(*iter++) == typeid(L1));
+ BOOST_ASSERT(typeid(*iter++) == typeid(L2));
 }
 
 namespace map_test
 {
- struct my_base
- {
- int number;
- my_base(int n = 0) : number(n) { }
- virtual ~my_base() { }
- bool operator==(my_base const &other) const
- {
- return number == other.number;
- }
- bool operator!=(my_base const &other) const
- {
- return number != other.number;
- }
- bool operator<(my_base const &other) const
- {
- return number < other.number;
- }
- };
-
- struct M0 : base<M0, my_base>
- {
- M0(int n = 0) : my_base(n) {}
- };
-
- struct M1 : base<M1, my_base>
- {
- string str;
- M1(int n = 1) : my_base(n) { }
- M1(const char *s, int n = 1) : my_base(n), str(s) { }
- };
-
- struct M2 : base<M2, my_base>
- {
- M2(int n = 2) : my_base(n) { }
- };
-
- struct M3 : base<M3, my_base>
- {
- M3(int n = 3) : my_base(n) { }
- };
+ struct my_base
+ {
+ int number;
+ my_base(int n = 0) : number(n) { }
+ virtual ~my_base() { }
+ bool operator==(my_base const &other) const
+ {
+ return number == other.number;
+ }
+ bool operator!=(my_base const &other) const
+ {
+ return number != other.number;
+ }
+ bool operator<(my_base const &other) const
+ {
+ return number < other.number;
+ }
+ };
+
+ struct M0 : base<M0, my_base>
+ {
+ M0(int n = 0) : my_base(n) {}
+ };
+
+ struct M1 : base<M1, my_base>
+ {
+ string str;
+ M1(int n = 1) : my_base(n) { }
+ M1(const char *s, int n = 1) : my_base(n), str(s) { }
+ };
+
+ struct M2 : base<M2, my_base>
+ {
+ M2(int n = 2) : my_base(n) { }
+ };
+
+ struct M3 : base<M3, my_base>
+ {
+ M3(int n = 3) : my_base(n) { }
+ };
 }
 
 BOOST_AUTO_TEST_CASE(test_map)
 {
- using namespace map_test;
- typedef cloneable::map<int, map_test::my_base> Map;
- Map map;
- map.insert<M0>(1);
- map.insert<M1>(2, "foo");
- map.insert<M3>(3, 42);
-
- // the preacher - prior to bill hicks?
-
- // deep copy
- Map copy = map;
- BOOST_ASSERT(copy == map);
-
- Map::iterator i3 = copy.find(3);
- BOOST_ASSERT(i3 != copy.end());
- BOOST_ASSERT(typeid(*i3->second) == typeid(M3));
- M3 *m3_clone = i3->second->clone_as<M3>();
- BOOST_ASSERT(m3_clone != 0);
+ using namespace map_test;
+ typedef cloneable::map<int, map_test::my_base> Map;
+ Map map;
+ map.insert<M0>(1);
+ map.insert<M1>(2, "foo");
+ map.insert<M3>(3, 42);
+
+ // deep copy
+ // TODO: deep copy doesnt work for maps?
+ Map &copy = map;
+ BOOST_ASSERT(copy == map);
+
+ Map::iterator i3 = copy.find(3);
+ BOOST_ASSERT(i3 != copy.end());
+ BOOST_ASSERT(typeid(*i3->second) == typeid(M3));
+ M3 *m3_clone = i3->second->clone_as<M3>();
+ BOOST_ASSERT(m3_clone != 0);
 
- delete m3_clone;
+ delete m3_clone;
 }
 
 BOOST_AUTO_TEST_CASE(test_heterogenous_map)
 {
- //using namespace map_test;
- //typedef cloneable::heterogenous_map<map_test::my_base> Map;
- //Map map;
- //map.key<M2>().value<M3>();
- //BOOST_ASSERT(map.size() == 1);
- //Map::iterator a = map.find<M2>();
- //BOOST_ASSERT(a != map.end());
-
- //map.key<M0>(42).value<M1>("foo");
- //BOOST_ASSERT(map.size() == 2);
+ //using namespace map_test;
+ //typedef cloneable::heterogenous_map<map_test::my_base> Map;
+ //Map map;
+ //map.key<M2>().value<M3>();
+ //BOOST_ASSERT(map.size() == 1);
+ //Map::iterator a = map.find<M2>();
+ //BOOST_ASSERT(a != map.end());
+
+ //map.key<M0>(42).value<M1>("foo");
+ //BOOST_ASSERT(map.size() == 2);
 
- //Map::iterator iter = map.find<M0>(42);
- //BOOST_ASSERT(iter!= map.end());
+ //Map::iterator iter = map.find<M0>(42);
+ //BOOST_ASSERT(iter!= map.end());
 
- //map.key<M2>().value<M3>();
+ //map.key<M2>().value<M3>();
 
-// Map copy = map;
+// Map copy = map;
 }
 
 BOOST_AUTO_TEST_CASE(test_hash)
 {
- using namespace map_test;
- M0 a, b;
- //BOOST_ASSERT(a.hash() != b.hash());
+ using namespace map_test;
+ M0 a, b;
+ //BOOST_ASSERT(a.hash() != b.hash());
 }
 
 
 BOOST_AUTO_TEST_CASE(test_any)
 {
- // this works, after changing boost::any<> to take an allocator type argument
- typedef any<monotonic::allocator<char> > any_type;
- typedef std::vector<any_type, monotonic::allocator<any_type> > vec;
- vec v;
-
- // an issue here is that instances are copy-constructed into the container.
- // another issue is that this is effectively typeless.
- // but, types added do not have to derive from anything in order for duplication to work.
- v.push_back(T0(42));
- v.push_back(T1("foo"));
+ // this works, after changing boost::any<> to take an allocator type argument
+ typedef any<monotonic::allocator<char> > any_type;
+ typedef std::vector<any_type, monotonic::allocator<any_type> > vec;
+ vec v;
+
+ // an issue here is that instances are copy-constructed into the container.
+ // another issue is that this is effectively typeless.
+ // but, types added do not have to derive from anything in order for duplication to work.
+ v.push_back(T0(42));
+ v.push_back(T1("foo"));
 
- vec v2 = v;
+ vec v2 = v;
 
- BOOST_ASSERT(any_cast<T1 &>(v2[1]).str == "foo");
+ BOOST_ASSERT(any_cast<T1 &>(v2[1]).str == "foo");
 }
 
 BOOST_AUTO_TEST_CASE(test_variant)
 {
- // need to declare all the possible types that could be used at the point of declaration
- typedef variant<T0, T1, T2> var;
- typedef std::vector<var, monotonic::allocator<var> > vec;
- vec v0;
- v0.push_back(T0(42));
- v0.push_back(T1("foo"));
- vec v1 = v0;
- BOOST_ASSERT(boost::get<T1>(v1[1]).str == "foo");
+ // need to declare all the possible types that could be used at the point of declaration
+ typedef variant<T0, T1, T2> var;
+ typedef std::vector<var, monotonic::allocator<var> > vec;
+ vec v0;
+ v0.push_back(T0(42));
+ v0.push_back(T1("foo"));
+ vec v1 = v0;
+ BOOST_ASSERT(boost::get<T1>(v1[1]).str == "foo");
 }
 
 namespace set_test
 {
- struct set_base
- {
- int number;
- set_base(int n = 0) : number(n) { }
- friend bool operator==(const set_base &left, const set_base &right)
- {
- return left.number == right.number;
- }
- friend bool operator<(const set_base &left, const set_base &right)
- {
- return left.number < right.number;
- }
- };
- struct S0 : base<S0, set_base>
- {
- S0(int n = 0) : set_base(n) { }
- };
- struct S1 : base<S1, set_base>
- {
- S1(int n = 0) : set_base(n) { }
- };
-
- struct S2 : base<S2, set_base>
- {
- S2(int n = 0) : set_base(n) { }
- };
+ struct set_base
+ {
+ int number;
+ set_base(int n = 0) : number(n) { }
+ friend bool operator==(const set_base &left, const set_base &right)
+ {
+ return left.number == right.number;
+ }
+ friend bool operator<(const set_base &left, const set_base &right)
+ {
+ return left.number < right.number;
+ }
+ };
+ struct S0 : base<S0, set_base>
+ {
+ S0(int n = 0) : set_base(n) { }
+ };
+ struct S1 : base<S1, set_base>
+ {
+ S1(int n = 0) : set_base(n) { }
+ };
+
+ struct S2 : base<S2, set_base>
+ {
+ S2(int n = 0) : set_base(n) { }
+ };
 }
 
 BOOST_AUTO_TEST_CASE(test_set)
 {
- using namespace set_test;
- typedef cloneable::set<set_base> Set;
- Set set;
- const S0 *s0 = set.emplace<S0>(1).value.to_derived();
- set.emplace<S1>(2);
- set.emplace<S2>(3);
- set.emplace<S2>(4);
-
- Set::const_iterator A = set.begin(), B = set.end();
- for (; A != B; ++A)
- {
- const set_base *base = &*A;
- BOOST_ASSERT(base);
- }
-
- BOOST_ASSERT(set.size() == 4);
- BOOST_ASSERT(set.find<S0>(1) != set.end());
- BOOST_ASSERT(&*set.find<S0>(1) == s0);
- BOOST_ASSERT(set.find<set_base>(2) != set.end());
- BOOST_ASSERT(set.find<S1>(1) == set.end());
- BOOST_ASSERT(set.find<set_base>(1) != set.end());
-
- Set copy = set;
- BOOST_ASSERT(copy == set);
-
- BOOST_ASSERT(copy.size() == 4);
- BOOST_ASSERT(copy.find<S0>(1) != copy.end());
- BOOST_ASSERT(copy.find<set_base>(2) != copy.end());
-
- Set::iterator found;
- found = set.find<set_base>(1);
- BOOST_ASSERT(found != set.end());
- BOOST_ASSERT(&*found == s0);
+ using namespace set_test;
+ typedef cloneable::set<set_base> Set;
+ Set set;
+ const S0 *s0 = set.emplace<S0>(1).value.to_derived();
+ set.emplace<S1>(2);
+ set.emplace<S2>(3);
+ set.emplace<S2>(4);
+
+ Set::const_iterator A = set.begin(), B = set.end();
+ for (; A != B; ++A)
+ {
+ const set_base *base = &*A;
+ BOOST_ASSERT(base);
+ }
+
+ BOOST_ASSERT(set.size() == 4);
+ BOOST_ASSERT(set.find<S0>(1) != set.end());
+ BOOST_ASSERT(&*set.find<S0>(1) == s0);
+ BOOST_ASSERT(set.find<set_base>(2) != set.end());
+ BOOST_ASSERT(set.find<S1>(1) == set.end());
+ BOOST_ASSERT(set.find<set_base>(1) != set.end());
+
+ Set copy = set;
+ BOOST_ASSERT(copy == set);
+
+ BOOST_ASSERT(copy.size() == 4);
+ BOOST_ASSERT(copy.find<S0>(1) != copy.end());
+ BOOST_ASSERT(copy.find<set_base>(2) != copy.end());
+
+ Set::iterator found;
+ found = set.find<set_base>(1);
+ BOOST_ASSERT(found != set.end());
+ BOOST_ASSERT(&*found == s0);
 }
 
 //EOF


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