Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54544 - in sandbox/cloneable: . boost boost/cloneable boost/cloneable/detail libs libs/cloneable libs/cloneable/doc libs/cloneable/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-30 16:54:34


Author: cschladetsch
Date: 2009-06-30 16:54:32 EDT (Tue, 30 Jun 2009)
New Revision: 54544
URL: http://svn.boost.org/trac/boost/changeset/54544

Log:
moved from monotonic/cloneable

Added:
   sandbox/cloneable/
   sandbox/cloneable/boost/
   sandbox/cloneable/boost/cloneable/
   sandbox/cloneable/boost/cloneable/abstract_allocator.hpp (contents, props changed)
   sandbox/cloneable/boost/cloneable/abstract_base.hpp (contents, props changed)
   sandbox/cloneable/boost/cloneable/adaptor.hpp (contents, props changed)
   sandbox/cloneable/boost/cloneable/allocator.hpp (contents, props changed)
   sandbox/cloneable/boost/cloneable/base.hpp (contents, props changed)
   sandbox/cloneable/boost/cloneable/detail/
   sandbox/cloneable/boost/cloneable/detail/allocation.hpp (contents, props changed)
   sandbox/cloneable/boost/cloneable/detail/make_clone_allocator.hpp (contents, props changed)
   sandbox/cloneable/boost/cloneable/detail/pointer.hpp (contents, props changed)
   sandbox/cloneable/boost/cloneable/detail/prefix.hpp (contents, props changed)
   sandbox/cloneable/boost/cloneable/detail/suffix.hpp (contents, props changed)
   sandbox/cloneable/boost/cloneable/forward_declarations.hpp (contents, props changed)
   sandbox/cloneable/libs/
   sandbox/cloneable/libs/cloneable/
   sandbox/cloneable/libs/cloneable/doc/
   sandbox/cloneable/libs/cloneable/test/
   sandbox/cloneable/libs/cloneable/test/cloneable.vcproj (contents, props changed)
   sandbox/cloneable/libs/cloneable/test/tests.cpp (contents, props changed)

Added: sandbox/cloneable/boost/cloneable/abstract_allocator.hpp
==============================================================================
--- (empty file)
+++ sandbox/cloneable/boost/cloneable/abstract_allocator.hpp 2009-06-30 16:54:32 EDT (Tue, 30 Jun 2009)
@@ -0,0 +1,44 @@
+// Copyright (C) 2009 Christian Schladetsch
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_CLONEABLE_ABSTRACT_ALLOCATOR_HPP
+#define BOOST_CLONEABLE_ABSTRACT_ALLOCATOR_HPP
+
+#include <boost/cloneable/detail/prefix.hpp>
+#include <boost/cloneable/forward_declarations.hpp>
+
+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;
+ }
+ };
+
+ } // namespace cloneable
+
+} // namespace boost
+
+#include <boost/cloneable/detail/suffix.hpp>
+
+#endif // BOOST_CLONEABLE_ABSTRACT_ALLOCATOR_HPP
+
+//EOF

Added: sandbox/cloneable/boost/cloneable/abstract_base.hpp
==============================================================================
--- (empty file)
+++ sandbox/cloneable/boost/cloneable/abstract_base.hpp 2009-06-30 16:54:32 EDT (Tue, 30 Jun 2009)
@@ -0,0 +1,109 @@
+// Copyright (C) 2009 Christian Schladetsch
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_CLONEABLE_COMMON_BASE_HPP
+#define BOOST_CLONEABLE_COMMON_BASE_HPP
+
+#include <string>
+#include <boost/functional/hash_fwd.hpp>
+#include <boost/cloneable/detail/prefix.hpp>
+#include <boost/cloneable/abstract_allocator.hpp>
+
+namespace boost
+{
+ namespace cloneable
+ {
+ /// default base type used for object hierarchies to be stored in a given
+ /// container or containers. the user can supply their own when using
+ /// cloneable<Derived, Base> this will be used by default.
+ struct default_base_type
+ {
+ virtual ~default_base_type() { }
+ };
+
+ /// root structure for the cloneable object system
+ template <class Base>
+ struct abstract_base : virtual Base
+ {
+ typedef Base base_type;
+ typedef abstract_base<Base> this_type;
+
+ /// make storage for a new instance, but do not invoke any constructor
+ virtual this_type *allocate(abstract_allocator &) const = 0;
+
+ /// free memory associated with the given instance
+ 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);
+ }
+
+ /// for use with types that use multiple inheritance - select which sub-object to clone
+ template <class Ty>
+ this_type *clone_as(abstract_allocator &alloc) const
+ {
+ const base<Ty, Base> *ptr = dynamic_cast<const base<Ty, Base> *>(this);
+ if (ptr == 0)
+ throw std::bad_cast();
+ return ptr->clone(alloc);
+ }
+
+ /// make a copy of the given instance using the heap. caller should call delete
+ this_type *clone() const
+ {
+ return 0;
+ //if (this_type *copy = clone(original, alloc))
+ // return copy;
+ //return copy_construct(original, alloc);
+ }
+
+ /// overridable hash function
+ virtual size_t hash_value() const { return 0; }
+
+ /// return a hash value for the object. try the virtual method first, otherwise just use pointer value
+ size_t hash() const
+ {
+ if (size_t value = hash_value())
+ return value;
+ return ptrdiff_t(reinterpret_cast<const char *>(this) - 0);
+ }
+
+ virtual std::string to_string() const { return "cloneable"; }
+ };
+
+ } // 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
+
+#include <boost/cloneable/detail/suffix.hpp>
+
+#endif // BOOST_CLONEABLE_COMMON_BASE_HPP
+
+//EOF

Added: sandbox/cloneable/boost/cloneable/adaptor.hpp
==============================================================================
--- (empty file)
+++ sandbox/cloneable/boost/cloneable/adaptor.hpp 2009-06-30 16:54:32 EDT (Tue, 30 Jun 2009)
@@ -0,0 +1,48 @@
+// Copyright (C) 2009 Christian Schladetsch
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_CLONEABLE_ADAPTOR_HPP
+#define BOOST_CLONEABLE_ADAPTOR_HPP
+
+#include <boost/cloneable/detail/prefix.hpp>
+#include <boost/cloneable/base.hpp>
+
+namespace boost
+{
+ namespace cloneable
+ {
+ /// an adaptor for an existing class
+ ///
+ /// this is a type that can be used in an homogenous container
+ ///
+ /// ...this may or may not be a good idea...
+ template <class T, class Base>//, class AbstractBase>
+ struct adaptor : T, base<adaptor<T, Base/*, AbstractBase*/>, Base/*, AbstractBase*/>
+ {
+ adaptor() { }
+
+ 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)
+ {
+ }
+ };
+
+ } // namespace cloneable
+
+} // namespace boost
+
+#include <boost/cloneable/detail/suffix.hpp>
+
+#endif // BOOST_CLONEABLE_ADAPTOR_HPP
+
+//EOF

Added: sandbox/cloneable/boost/cloneable/allocator.hpp
==============================================================================
--- (empty file)
+++ sandbox/cloneable/boost/cloneable/allocator.hpp 2009-06-30 16:54:32 EDT (Tue, 30 Jun 2009)
@@ -0,0 +1,80 @@
+// Copyright (C) 2009 Christian Schladetsch
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_CLONEABLE_ALLOCATOR_HPP
+#define BOOST_CLONEABLE_ALLOCATOR_HPP
+
+#include <boost/cloneable/detail/prefix.hpp>
+#include <boost/cloneable/detail/allocation.hpp>
+
+namespace boost
+{
+ namespace cloneable
+ {
+ /// a cloning allocator
+ struct allocator
+ {
+ template <class Base>
+ static Base* allocate_clone( const Base& object )
+ {
+ throw;
+ }
+
+ template <class Base>
+ static void deallocate_clone( const Base* clone )
+ {
+ throw;
+ }
+
+ template <class Base, class Alloc>
+ static Base* allocate_clone(const Base& object, Alloc &alloc )
+ {
+ return object.clone(alloc);
+ }
+
+ template <class Base, class Alloc>
+ static void deallocate_clone(const Base *object, Alloc &alloc )
+ {
+ if (!object)
+ return;
+ const_cast<Base &>(*object).deallocate(alloc);
+ }
+ };
+
+ 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, 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>
+ void release(T *ptr, Alloc &alloc)
+ {
+ typename Alloc::template rebind<T>::other al(alloc);
+ al.destroy(ptr);
+ al.deallocate(ptr, 1);
+ return ptr;
+ }
+
+ } // namespace cloneable
+
+} // namespace boost
+
+#include <boost/cloneable/detail/suffix.hpp>
+
+#endif // BOOST_CLONEABLE_ALLOCATOR_HPP
+
+//EOF

Added: sandbox/cloneable/boost/cloneable/base.hpp
==============================================================================
--- (empty file)
+++ sandbox/cloneable/boost/cloneable/base.hpp 2009-06-30 16:54:32 EDT (Tue, 30 Jun 2009)
@@ -0,0 +1,78 @@
+// Copyright (C) 2009 Christian Schladetsch
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_CLONEABLE_BASE_HPP
+#define BOOST_CLONEABLE_BASE_HPP
+
+#include <boost/aligned_storage.hpp>
+#include <boost/cloneable/detail/prefix.hpp>
+#include <boost/cloneable/abstract_base.hpp>
+
+namespace boost
+{
+ namespace cloneable
+ {
+ /// base for the given derived type, using the given base class
+ template <class Derived, class Base>//, class AbstractBase>
+ struct base : abstract_base<Base>
+ {
+ typedef Derived derived_type;
+ typedef Base base_type;
+ //typedef AbstractBase abstract_base_type;
+ typedef abstract_base<Base> abstract_base_type;
+ typedef base<Derived, Base/*, AbstractBase*/> this_type;
+
+ static const size_t alignment; ///< required alignment for allocation
+ mutable derived_type *self_ptr; ///< pointer to derived object in this
+
+ public:
+ base() { self_ptr = static_cast<Derived *>(this); }
+
+ 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 = dynamic_cast<Derived *>(this);
+ alloc.deallocate_bytes(reinterpret_cast<abstract_allocator::pointer>(ptr), alignment);
+ }
+
+ virtual this_type *create_new(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();
+ return ptr;
+ }
+
+ 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;
+ }
+ };
+
+ /// ensure correct alignment when allocating derived instances
+ template <class Derived, class Base/*, class AbstractBase*/>
+ const size_t base<Derived, Base/*, AbstractBase*/>::alignment = aligned_storage<sizeof(Derived)>::alignment;
+
+ } // namespace cloneable
+
+} // namespace boost
+
+#include <boost/cloneable/detail/suffix.hpp>
+
+#endif // BOOST_CLONEABLE_BASE_HPP
+
+//EOF

Added: sandbox/cloneable/boost/cloneable/detail/allocation.hpp
==============================================================================
--- (empty file)
+++ sandbox/cloneable/boost/cloneable/detail/allocation.hpp 2009-06-30 16:54:32 EDT (Tue, 30 Jun 2009)
@@ -0,0 +1,74 @@
+// Copyright (C) 2009 Christian Schladetsch
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_CLONEABLE_DETAIL_ALLOCATION_HPP
+#define BOOST_CLONEABLE_DETAIL_ALLOCATION_HPP
+
+#include <boost/cloneable/detail/prefix.hpp>
+#include <boost/cloneable/base.hpp>
+#include <boost/cloneable/detail/pointer.hpp>
+
+namespace boost
+{
+ namespace cloneable
+ {
+ namespace detail
+ {
+ template <class U, class Alloc>
+ U *allocate(Alloc &al)
+ {
+ typename Alloc::template rebind<U>::other alloc(al);
+ return alloc.allocate(1);
+ }
+
+ // TODO: use variadic template arguments, or BOOST_PP
+
+ template <class U, class Base, class Alloc>
+ pointer<U,Base> construct(Alloc &al)
+ {
+ typename Alloc::template rebind<U>::other alloc(al);
+ U *ptr = alloc.allocate(1);
+ alloc.construct(ptr);
+ return ptr;
+ }
+
+ template <class U, class Base, class Alloc, class A0>
+ pointer<U,Base> construct(Alloc &al, A0 a0)
+ {
+ U *ptr = allocate<U>(al);
+ new (ptr) U(a0);
+ return ptr;
+ }
+
+ template <class U, class Base, class Alloc, class A0, class A1>
+ pointer<U,Base> construct(Alloc &al, A0 a0, A1 a1)
+ {
+ U *ptr = allocate<U>(al);
+ new (ptr) U(a0, a1);
+ return ptr;
+ }
+
+ template <class U, class Base, class Alloc, class A0, class A1, class A2>
+ pointer<U,Base> construct(Alloc &al, A0 a0, A1 a1, A2 a2)
+ {
+ U *ptr = allocate<U>(al);
+ new (ptr) U(a0, a1, a2);
+ return ptr;
+ }
+
+ // etc...
+
+ } // namespace detail
+
+ } // namespace cloneable
+
+} // namespace boost
+
+#include <boost/cloneable/detail/suffix.hpp>
+
+#endif // BOOST_CLONEABLE_DETAIL_ALLOCATION_HPP
+
+//EOF
+

Added: sandbox/cloneable/boost/cloneable/detail/make_clone_allocator.hpp
==============================================================================
--- (empty file)
+++ sandbox/cloneable/boost/cloneable/detail/make_clone_allocator.hpp 2009-06-30 16:54:32 EDT (Tue, 30 Jun 2009)
@@ -0,0 +1,100 @@
+// Copyright (C) 2009 Christian Schladetsch
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_CLONEABLE_DETAIL_MAKE_CLONEABLE_ALLOCATOR_HPP
+#define BOOST_CLONEABLE_DETAIL_MAKE_CLONEABLE_ALLOCATOR_HPP
+
+#include <boost/type_traits/is_convertible.hpp>
+#include <boost/cloneable/detail/prefix.hpp>
+#include <boost/cloneable/allocator.hpp>
+
+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);
+
+ // 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 cloneable
+
+} // namespace boost
+
+#include <boost/cloneable/detail/suffix.hpp>
+
+#endif // BOOST_CLONEABLE_DETAIL_MAKE_CLONEABLE_ALLOCATOR_HPP
+
+//EOF

Added: sandbox/cloneable/boost/cloneable/detail/pointer.hpp
==============================================================================
--- (empty file)
+++ sandbox/cloneable/boost/cloneable/detail/pointer.hpp 2009-06-30 16:54:32 EDT (Tue, 30 Jun 2009)
@@ -0,0 +1,59 @@
+// Copyright (C) 2009 Christian Schladetsch
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_CLONEABLE_DETAIL_POINTER_HPP
+#define BOOST_CLONEABLE_DETAIL_POINTER_HPP
+
+#include <boost/cloneable/detail/prefix.hpp>
+#include <boost/cloneable/base.hpp>
+
+namespace boost
+{
+ namespace cloneable
+ {
+ namespace detail
+ {
+ template <class U, class B>
+ struct pointer
+ {
+ typedef U derived_type;
+ typedef B base_type;
+ typedef base<derived_type, base_type> cloneable_type;
+ typedef typename cloneable_type::abstract_base_type abstract_base_type;
+
+ private:
+ cloneable_type *ptr;
+
+ public:
+ pointer(derived_type *p = 0) : ptr(dynamic_cast<cloneable_type *>(p))
+ {
+ }
+ abstract_base_type *to_abstract() const
+ {
+ return ptr;
+ }
+ base_type *to_base() const
+ {
+ return ptr;
+ }
+ cloneable_type *to_cloneable() const
+ {
+ return ptr;
+ }
+ derived_type *to_derived() const
+ {
+ return ptr->cloneable_type::self_ptr;
+ }
+ };
+
+ } // namespace detail
+
+ } // namespace cloneable
+
+} // namespace boost
+
+#endif // BOOST_CLONEABLE_DETAIL_POINTER_HPP
+
+//EOF

Added: sandbox/cloneable/boost/cloneable/detail/prefix.hpp
==============================================================================
--- (empty file)
+++ sandbox/cloneable/boost/cloneable/detail/prefix.hpp 2009-06-30 16:54:32 EDT (Tue, 30 Jun 2009)
@@ -0,0 +1,10 @@
+// Copyright (C) 2009 Christian Schladetsch
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_CONFIG_HPP
+# include <boost/config.hpp>
+#endif
+
+//EOF

Added: sandbox/cloneable/boost/cloneable/detail/suffix.hpp
==============================================================================
--- (empty file)
+++ sandbox/cloneable/boost/cloneable/detail/suffix.hpp 2009-06-30 16:54:32 EDT (Tue, 30 Jun 2009)
@@ -0,0 +1,6 @@
+// Copyright (C) 2009 Christian Schladetsch
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+//EOF

Added: sandbox/cloneable/boost/cloneable/forward_declarations.hpp
==============================================================================
--- (empty file)
+++ sandbox/cloneable/boost/cloneable/forward_declarations.hpp 2009-06-30 16:54:32 EDT (Tue, 30 Jun 2009)
@@ -0,0 +1,71 @@
+// Copyright (C) 2009 Christian Schladetsch
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_CLONEABLE_FORWARD_DECLARATIONS_HPP
+#define BOOST_CLONEABLE_FORWARD_DECLARATIONS_HPP
+
+#include <functional>
+#include <boost/cloneable/detail/prefix.hpp>
+
+namespace boost
+{
+ namespace cloneable
+ {
+ /// 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 default_base_type;
+
+ /// provides a set of pure-virtual methods for allocation, de-allocation, and cloning
+ template <class Base>
+ struct abstract_base;
+
+ /// a structure derived from this, with type Derived, is correctly
+ /// cloneable from a base pointer, given an abstract_allocator.
+ template <
+ class Derived
+ , class Base = default_base_type
+ >// this is too much uncessary customisation:, class AbstractBase = abstract_cloneable<Base> >
+ struct base;
+
+ /// 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 = default_base_type
+ >//, class AbstractBase = abstract_cloneable<Base> >
+ struct adaptor;
+
+ /* TODO: move to boost/heterogenous/foward
+ /// a heterogenous vector of objects
+ template <
+ class Base = default_base_type
+ , class Alloc = monotonic::allocator<int>
+ >//, class AbstractBase = abstract_cloneable<Base> >
+ struct vector;
+
+ /// a mapping of heterogenous objects to heterogenous objects
+ template <
+ class Base = default_base_type
+ , class Pred = std::less<Base>
+ , class Alloc = monotonic::allocator<int>
+ >//, class AbstractBase = abstract_cloneable<Base> >
+ struct map;
+ */
+
+ } // namespace cloneable
+
+} // namespace boost
+
+#include <boost/cloneable/detail/suffix.hpp>
+
+#endif // BOOST_CLONEABLE_FORWARD_DECLARATIONS_HPP
+
+//EOF

Added: sandbox/cloneable/libs/cloneable/test/cloneable.vcproj
==============================================================================
--- (empty file)
+++ sandbox/cloneable/libs/cloneable/test/cloneable.vcproj 2009-06-30 16:54:32 EDT (Tue, 30 Jun 2009)
@@ -0,0 +1,234 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="cloneable_tests"
+ ProjectGUID="{5FF650E3-53E2-447F-8D2D-A85B76B214D3}"
+ RootNamespace="cloneable_tests"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="c:/source/boost/sandbox/cloneable;c:/source/boost/sandbox/monotonic"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ Description="Running tests"
+ CommandLine="$(OutDir)\$(ProjectName).exe"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ RuntimeLibrary="2"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="boost"
+ >
+ <Filter
+ Name="cloneable"
+ >
+ <File
+ RelativePath="..\..\..\boost\cloneable\abstract_allocator.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\boost\cloneable\abstract_base.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\boost\cloneable\adaptor.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\boost\cloneable\allocator.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\boost\cloneable\base.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\boost\cloneable\forward_declarations.hpp"
+ >
+ </File>
+ <Filter
+ Name="detail"
+ >
+ <File
+ RelativePath="..\..\..\boost\cloneable\detail\allocation.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\boost\cloneable\detail\make_clone_allocator.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\boost\cloneable\detail\pointer.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\boost\cloneable\detail\prefix.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\boost\cloneable\detail\suffix.hpp"
+ >
+ </File>
+ </Filter>
+ </Filter>
+ </Filter>
+ <File
+ RelativePath=".\tests.cpp"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>

Added: sandbox/cloneable/libs/cloneable/test/tests.cpp
==============================================================================
--- (empty file)
+++ sandbox/cloneable/libs/cloneable/test/tests.cpp 2009-06-30 16:54:32 EDT (Tue, 30 Jun 2009)
@@ -0,0 +1,285 @@
+// (C) 2009 Christian Schladetsch
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// documentation at https://svn.boost.org/svn/boost/sandbox/monotonic/libs/monotonic/doc/index.html
+// sandbox at https://svn.boost.org/svn/boost/sandbox/monotonic/
+
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MAIN
+
+#include <string>
+#include <iostream>
+
+#define BOOST_HETEROGENOUS
+#include <boost/monotonic/allocator.hpp>
+#include <boost/monotonic/local.hpp>
+
+//#include <boost/heterogenous/vector.hpp>
+//#include <boost/heterogenous/map.hpp>
+#include <boost/cloneable/adaptor.hpp>
+#include <boost/cloneable/allocator.hpp>
+#include <boost/bind.hpp>
+#include <boost/any.hpp>
+#include <boost/variant.hpp>
+
+#define BOOST_TEST_MODULE basic_test test
+#include <boost/test/unit_test.hpp>
+#include <boost/timer.hpp>
+
+using namespace std;
+using namespace boost;
+using namespace cloneable;
+
+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 my_region { };
+}
+
+BOOST_AUTO_TEST_CASE(test_clones)
+{
+ using namespace mulitple_inheritance_test;
+ 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 = dynamic_cast<Q0 *>(q0->clone(alloc));
+ BOOST_ASSERT(typeid(*q0_c) == typeid(Q0));
+
+ Q1 *q1 = create<Q1>(alloc);
+ BOOST_ASSERT(typeid(*q1) == typeid(Q1));
+
+ Q0 *q1_c0 = dynamic_cast<Q0 *>(q1->clone_as<Q0>(alloc));
+ BOOST_ASSERT(typeid(*q1_c0) == typeid(Q0));
+
+ Q1 *q1_c1 = dynamic_cast<Q1 *>(q1->clone_as<Q1>(alloc));
+ BOOST_ASSERT(typeid(*q1_c1) == typeid(Q1));
+}
+//
+//BOOST_AUTO_TEST_CASE(test_multiple_inheritance)
+//{
+// using namespace mulitple_inheritance_test;
+// typedef cloneable::vector<> vec;
+// vec v;
+// v.emplace_back<Q0>(42);
+// v.emplace_back<Q1>("foo");
+// vec v2 = v;
+// BOOST_ASSERT(v2.ref_at<Q0>(0).num == 42);
+// BOOST_ASSERT(v2.ref_at<Q1>(1).str == "foo");
+//}
+
+struct my_base
+{
+ virtual ~my_base() { }
+};
+
+struct T0 : base<T0, my_base>
+{
+ int num;
+ T0() : num(0) { }
+ T0(int n) : num(n) { }
+};
+
+struct T1 : base<T1, my_base>
+{
+ std::string str;
+
+ 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;
+ }
+};
+
+/// some external type that we cannot change
+struct ExternalType
+{
+ std::string text;
+ ExternalType() { }
+ ExternalType(const char *T) : text(T) { }
+};
+
+/// make an adaptor type, which makes `ExternalType` cloneable
+typedef cloneable::adaptor<ExternalType, my_base> ExternalType_;
+
+//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.emplace_back<T0>(42);
+// bases.emplace_back<T1>("foo");
+// bases.emplace_back<T2>(3.14f, -123, "spam");
+// bases.emplace_back<ExternalType_>("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 default_base_type
+// my_base &generic0 = copy[0];
+// my_base &generic1 = copy[1];
+// my_base &generic2 = copy[2];
+//
+// // get a reference; will throw bad_cast on type mismatch
+// T0 &p1 = copy.ref_at<T0>(0);
+//
+// // get a pointer; returns null on type mismatch
+// T1 *p2 = copy.ptr_at<T1>(1);
+// T2 *p3 = copy.ptr_at<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.ref_at<ExternalType_>(3).text == "external");
+//
+// bool caught = false;
+// try
+// {
+// my_base &base = copy.ref_at<T1>(0);
+// }
+// catch (std::bad_cast)
+// {
+// caught = true;
+// }
+// BOOST_ASSERT(caught);
+//
+// }
+//}
+//
+//namespace map_test
+//{
+// struct my_base
+// {
+// int number;
+// my_base(int n = 0) : number(n) { }
+// virtual ~my_base() { }
+// };
+//
+// struct M0 : base<M0, my_base>
+// {
+// M0(int n = 0) : my_base(n) {}
+// };
+//
+// struct M1 : base<M1, my_base>
+// {
+// string str;
+// M1() { }
+// M1(const char *s) : str(s) { }
+// };
+//
+// struct M2 : base<M2, my_base>
+// {
+// };
+//
+// struct M3 : base<M3, my_base>
+// {
+// };
+//
+// struct my_less
+// {
+// bool operator()(my_base const *left, my_base const *right) const
+// {
+// return left->number < right->number;
+// }
+// };
+//}
+//
+//BOOST_AUTO_TEST_CASE(test_map)
+//{
+// using namespace map_test;
+// typedef cloneable::map<map_test::my_base,my_less> map_type;
+// map_type map;
+// map .key<M0>(42).value<M1>("foo")
+// .key<M2>().value<M3>()
+// ;
+// M0 *m0 = create<M0>(map.get_allocator(), 42);
+// map_type::iterator iter = map.find(m0);
+// BOOST_ASSERT(iter!= map.end());
+// M1 *m1 = dynamic_cast<M1 *>(iter->second);
+// BOOST_ASSERT(m1 != 0);
+// BOOST_ASSERT(m1->str == "foo");
+//}
+//
+//BOOST_AUTO_TEST_CASE(test_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"));
+//
+// vec v2 = v;
+//
+// 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");
+//}
+//
+//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