Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54546 - in sandbox: cloneable/boost/cloneable cloneable/boost/cloneable/detail cloneable/libs/cloneable/test monotonic/boost/heterogenous monotonic/boost/monotonic monotonic/libs/monotonic/test monotonic/libs/monotonic/test/Tests monotonic/libs/object_model/src
From: christian.schladetsch_at_[hidden]
Date: 2009-06-30 17:06:43


Author: cschladetsch
Date: 2009-06-30 17:06:41 EDT (Tue, 30 Jun 2009)
New Revision: 54546
URL: http://svn.boost.org/trac/boost/changeset/54546

Log:
moved from cloneable out from monotonic/cloneable

Added:
   sandbox/cloneable/boost/cloneable/map.hpp (contents, props changed)
   sandbox/cloneable/boost/cloneable/vector.hpp (contents, props changed)
Text files modified:
   sandbox/cloneable/boost/cloneable/detail/prefix.hpp | 4
   sandbox/cloneable/boost/cloneable/forward_declarations.hpp | 3
   sandbox/cloneable/libs/cloneable/test/cloneable.vcproj | 12 +
   sandbox/cloneable/libs/cloneable/test/tests.cpp | 344 ++++++++++++++++++++-------------------
   sandbox/monotonic/boost/heterogenous/map.hpp | 3
   sandbox/monotonic/boost/heterogenous/vector.hpp | 9
   sandbox/monotonic/boost/monotonic/allocator_base.hpp | 15 -
   sandbox/monotonic/boost/monotonic/local.hpp | 1
   sandbox/monotonic/libs/monotonic/test/Tests/Tests.vcproj | 2
   sandbox/monotonic/libs/monotonic/test/monotonic.sln | 16
   sandbox/monotonic/libs/monotonic/test/monotonic.vcproj | 2
   sandbox/monotonic/libs/object_model/src/object_model.vcproj | 2
   12 files changed, 219 insertions(+), 194 deletions(-)

Modified: sandbox/cloneable/boost/cloneable/detail/prefix.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/detail/prefix.hpp (original)
+++ sandbox/cloneable/boost/cloneable/detail/prefix.hpp 2009-06-30 17:06:41 EDT (Tue, 30 Jun 2009)
@@ -7,4 +7,8 @@
 # include <boost/config.hpp>
 #endif
 
+#ifndef BOOST_CLONEABLE_FORWARD_DECLARATIONS_HPP
+# include <boost/cloneable/forward_declarations.hpp>
+#endif
+
 //EOF

Modified: sandbox/cloneable/boost/cloneable/forward_declarations.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/forward_declarations.hpp (original)
+++ sandbox/cloneable/boost/cloneable/forward_declarations.hpp 2009-06-30 17:06:41 EDT (Tue, 30 Jun 2009)
@@ -43,7 +43,7 @@
>//, class AbstractBase = abstract_cloneable<Base> >
                 struct adaptor;
 
- /* TODO: move to boost/heterogenous/foward
+ // TODO: move to boost/heterogenous/foward
                 /// a heterogenous vector of objects
                 template <
                         class Base = default_base_type
@@ -58,7 +58,6 @@
                         , class Alloc = monotonic::allocator<int>
>//, class AbstractBase = abstract_cloneable<Base> >
                 struct map;
- */
 
         } // namespace cloneable
 

Added: sandbox/cloneable/boost/cloneable/map.hpp
==============================================================================
--- (empty file)
+++ sandbox/cloneable/boost/cloneable/map.hpp 2009-06-30 17:06:41 EDT (Tue, 30 Jun 2009)
@@ -0,0 +1,213 @@
+// 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_MAP_HPP
+#define BOOST_CLONEABLE_MAP_HPP
+
+#include <boost/ptr_container/ptr_map.hpp>
+#include <boost/foreach.hpp>
+
+#include <boost/cloneable/detail/make_clone_allocator.hpp>
+
+namespace boost
+{
+ namespace cloneable
+ {
+ /// a vector of heterogenous objects
+ // TODO: move to boost/heterogenous/map
+ template <class Base, class Pred, class Alloc>//, class AbstractBase>
+ struct map
+ {
+ typedef typename detail::make_clone_allocator<Alloc>::type allocator_type;
+ typedef Base base_type;
+ //typedef ptr_map<Base, Base, Pred, allocator, allocator_type> implementation;
+ typedef abstract_base<Base> abstract_base_type;
+
+ typedef std::map<Base *, Base *, Pred, allocator_type> implementation;
+
+ typedef typename implementation::value_type value_type;
+ typedef typename implementation::reference reference;
+ typedef typename implementation::const_reference const_reference;
+ typedef typename implementation::iterator iterator;
+ typedef typename implementation::const_iterator const_iterator;
+ typedef typename implementation::key_type key_type;
+ typedef typename implementation::mapped_type mapped_type;
+ typedef map<Base, Pred, Alloc/*, AbstractBase*/> this_type;
+
+ private:
+ implementation impl;
+
+ public:
+ map()
+ {
+ }
+ map(allocator_type a)
+ : impl(a)
+ {
+ }
+
+ /* purposefully elided
+ template <class II>
+ map(II F, II L, allocator_type a = allocator_type());
+ */
+
+ private:
+ struct value_adder
+ {
+ this_type *parent;
+ base_type *key_instance;
+
+ value_adder(this_type &P, base_type &K)
+ : parent(&P), key_instance(&K) { }
+
+ template <class U>
+ this_type &value()
+ {
+ base_type *val = detail::construct<U,base_type>(parent->get_allocator()).to_base();
+ parent->insert(std::make_pair(key_instance, val));
+ return *parent;
+ }
+
+ // TODO: use variadic arguments or BOOST_PP to pass ctor args
+ template <class U, class A0>
+ this_type &value(A0 a0)
+ {
+ base_type *val = detail::construct<U,base_type>(parent->get_allocator(), a0).to_base();
+ parent->insert(std::make_pair(key_instance, val));
+ return *parent;
+ }
+ template <class U, class A0, class A1>
+ this_type &value(A0 a0, A1 a1)
+ {
+ base_type *val = detail::construct<U,base_type>(parent->get_allocator(), a0, a1).to_base();
+ parent->insert(std::make_pair(key_instance, val));
+ return *parent;
+ }
+ };
+
+ public:
+ template <class U>
+ value_adder key()
+ {
+ base_type *key_instance = detail::construct<U,base_type>(get_allocator()).to_base();
+ return value_adder(*this, *key_instance);
+ }
+
+ // TODO: use variadic arguments or BOOST_PP to pass ctor args
+ template <class U, class A0>
+ value_adder key(A0 a0)
+ {
+ base_type *key_instance = detail::construct<U,base_type>(get_allocator(), a0).to_base();
+ return value_adder(*this, *key_instance);
+ }
+ template <class U, class A0, class A1>
+ value_adder key(A0 a0, A1 a1)
+ {
+ base_type *key_instance = detail::construct<U,base_type>(get_allocator(), a0, a1).to_base();
+ return value_adder(*this, *key_instance);
+ }
+ template <class U, class A0, class A1, class A2>
+ value_adder key(A0 a0, A1 a1, A2 a2)
+ {
+ base_type *key_instance = detail::construct<U,base_type>(get_allocator(), a0, a1, a2).to_base();
+ return value_adder(*this, *key_instance);
+ }
+
+ // TODO: make this private
+ void insert(value_type x)
+ {
+ impl.insert(x);
+ }
+
+ template <class Fun>
+ Fun for_each(Fun fun)
+ {
+ BOOST_FOREACH(value_type &value, *this)
+ {
+ fun(value);
+ }
+ }
+
+ 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;
+ }
+
+ 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();
+ }
+
+ iterator find(key_type const &key)
+ {
+ return impl.find(key);
+ }
+
+ //reference operator[](key_type const &key)
+ //{
+ // return impl[n];
+ //}
+ //const_reference operator[](key_type const &key) const
+ //{
+ // return impl[n];
+ //}
+
+ typename implementation::allocator_type get_allocator()
+ {
+ return impl.get_allocator();
+ }
+ };
+
+ } // namespace heterogenous
+
+} // namespace boost
+
+#include <boost/heterogenous/detail/suffix.hpp>
+
+#endif // BOOST_HETEROGENOUS_MAP_HPP
+
+//EOF

Added: sandbox/cloneable/boost/cloneable/vector.hpp
==============================================================================
--- (empty file)
+++ sandbox/cloneable/boost/cloneable/vector.hpp 2009-06-30 17:06:41 EDT (Tue, 30 Jun 2009)
@@ -0,0 +1,211 @@
+// 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_VECTOR_HPP
+#define BOOST_CLONEABLE_VECTOR_HPP
+
+#include <boost/ptr_container/ptr_vector.hpp>
+#include <boost/foreach.hpp>
+
+#include <boost/cloneable/detail/prefix.hpp>
+#include <boost/cloneable/detail/make_clone_allocator.hpp>
+#include <boost/cloneable/base.hpp>
+#include <boost/cloneable/detail/allocation.hpp>
+
+namespace boost
+{
+ namespace cloneable
+ {
+ /// a vector of heterogenous objects
+ // TODO: move to boost/heterogenous/vector
+ template <class Base, class Alloc>//, class AbstractBase>
+ struct vector
+ {
+ typedef Base base_type;
+ //typedef AbstractBase abstract_base_type;
+ typedef abstract_base<Base> abstract_base_type;
+ typedef typename detail::make_clone_allocator<Alloc>::type allocator_type;
+ typedef ptr_vector<abstract_base_type, allocator, allocator_type> implementation;
+ typedef typename implementation::value_type value_type;
+ typedef typename implementation::reference reference;
+ typedef typename implementation::const_reference const_reference;
+ typedef typename implementation::iterator iterator;
+ typedef typename implementation::const_iterator const_iterator;
+
+ private:
+ implementation impl;
+
+ public:
+ vector()
+ {
+ }
+
+ vector(allocator_type &a)
+ : impl(a)
+ {
+ }
+
+ //purposefully elided
+ //template <class II>
+ //vector(II F, II L, allocator_type a = allocator_type());
+ //vector(size_t reserved);
+
+ 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 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();
+ }
+
+ value_type &back()
+ {
+ return impl.back();
+ }
+ const value_type &back() const
+ {
+ return impl.back();
+ }
+ value_type &front()
+ {
+ return impl.front();
+ }
+ const value_type &front() const
+ {
+ return impl.front();
+ }
+
+ 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 &ref_at(size_t n)
+ {
+ Other *ptr = ptr_at<Other>(n);
+ if (ptr == 0)
+ throw std::bad_cast();
+ return *ptr;
+ }
+ template <class Other>
+ const Other &ref_at(size_t n) const
+ {
+ const Other *ptr = ptr_at<const Other>(n);
+ if (ptr == 0)
+ throw std::bad_cast();
+ return *ptr;
+ }
+
+ template <class Other>
+ Other *ptr_at(size_t n)
+ {
+ return dynamic_cast<Other *>(&at(n));
+ }
+ template <class Other>
+ const Other *ptr_at(size_t n) const
+ {
+ return dynamic_cast<const Other *>(&at(n));
+ }
+
+ // TODO: use variadic arguments or BOOST_PP to pass ctor args
+ template <class U>
+ void emplace_back()
+ {
+ impl.push_back(detail::construct<U,base_type>(get_allocator()).to_abstract());
+ }
+ template <class U, class A0>
+ void emplace_back(A0 a0)
+ {
+ impl.push_back(detail::construct<U,base_type>(get_allocator(), a0).to_abstract());
+ }
+ template <class U, class A0, class A1>
+ void emplace_back(A0 a0, A1 a1)
+ {
+ impl.push_back(detail::construct<U,base_type>(get_allocator(), a0,a1).to_abstract());
+ }
+ template <class U, class A0, class A1, class A2>
+ void emplace_back(A0 a0, A1 a1, A2 a2)
+ {
+ impl.push_back(detail::construct<U,base_type>(get_allocator(), a0,a1,a2).to_abstract());
+ }
+
+ typename implementation::allocator_type get_allocator()
+ {
+ return impl.get_allocator();
+ }
+ };
+
+ } // namespace cloneable
+
+} // namespace boost
+
+#include <boost/cloneable/detail/suffix.hpp>
+
+#endif // BOOST_CLONEABLE_VECTOR_HPP
+
+//EOF

Modified: sandbox/cloneable/libs/cloneable/test/cloneable.vcproj
==============================================================================
--- sandbox/cloneable/libs/cloneable/test/cloneable.vcproj (original)
+++ sandbox/cloneable/libs/cloneable/test/cloneable.vcproj 2009-06-30 17:06:41 EDT (Tue, 30 Jun 2009)
@@ -198,6 +198,14 @@
                                         RelativePath="..\..\..\boost\cloneable\forward_declarations.hpp"
>
                                 </File>
+ <File
+ RelativePath="..\..\..\boost\cloneable\map.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\boost\cloneable\vector.hpp"
+ >
+ </File>
                                 <Filter
                                         Name="detail"
>
@@ -222,6 +230,10 @@
>
                                         </File>
                                 </Filter>
+ <Filter
+ Name="containers"
+ >
+ </Filter>
                         </Filter>
                 </Filter>
                 <File

Modified: sandbox/cloneable/libs/cloneable/test/tests.cpp
==============================================================================
--- sandbox/cloneable/libs/cloneable/test/tests.cpp (original)
+++ sandbox/cloneable/libs/cloneable/test/tests.cpp 2009-06-30 17:06:41 EDT (Tue, 30 Jun 2009)
@@ -16,8 +16,8 @@
 #include <boost/monotonic/allocator.hpp>
 #include <boost/monotonic/local.hpp>
 
-//#include <boost/heterogenous/vector.hpp>
-//#include <boost/heterogenous/map.hpp>
+#include <boost/cloneable/vector.hpp>
+#include <boost/cloneable/map.hpp>
 #include <boost/cloneable/adaptor.hpp>
 #include <boost/cloneable/allocator.hpp>
 #include <boost/bind.hpp>
@@ -72,18 +72,19 @@
         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");
-//}
+
+
+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
 {
@@ -131,155 +132,168 @@
 /// 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");
-//}
-//
+BOOST_AUTO_TEST_CASE(test_external_types)
+{
+ monotonic::local<> local;
+ monotonic::allocator<int> alloc = local.make_allocator<int>();
+
+ ExternalType_ *ext = create<ExternalType_>(alloc);
+ BOOST_ASSERT(typeid(*ext) == typeid(ExternalType_));
+
+ ExternalType_ *clone = dynamic_cast<ExternalType_ *>(ext->clone(alloc));
+ BOOST_ASSERT(typeid(*clone) == typeid(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

Modified: sandbox/monotonic/boost/heterogenous/map.hpp
==============================================================================
--- sandbox/monotonic/boost/heterogenous/map.hpp (original)
+++ sandbox/monotonic/boost/heterogenous/map.hpp 2009-06-30 17:06:41 EDT (Tue, 30 Jun 2009)
@@ -9,8 +9,7 @@
 #include <boost/ptr_container/ptr_map.hpp>
 #include <boost/foreach.hpp>
 
-#include <boost/heterogenous/detail/prefix.hpp>
-#include <boost/heterogenous/make_clone_allocator.hpp>
+#include <boost/cloneable/detail/make_clone_allocator.hpp>
 
 namespace boost
 {

Modified: sandbox/monotonic/boost/heterogenous/vector.hpp
==============================================================================
--- sandbox/monotonic/boost/heterogenous/vector.hpp (original)
+++ sandbox/monotonic/boost/heterogenous/vector.hpp 2009-06-30 17:06:41 EDT (Tue, 30 Jun 2009)
@@ -10,15 +10,16 @@
 #include <boost/monotonic/allocator.hpp>
 #include <boost/foreach.hpp>
 
-#include <boost/heterogenous/detail/prefix.hpp>
-#include <boost/heterogenous/cloneable.hpp>
-#include <boost/heterogenous/make_clone_allocator.hpp>
-#include <boost/heterogenous/detail/allocation.hpp>
+#include <boost/cloneable/cloneable.hpp>
+#include <boost/cloneable/detail/make_clone_allocator.hpp>
+#include <boost/cloneable/detail/allocation.hpp>
 
 namespace boost
 {
         namespace heterogenous
         {
+ using namespace cloneable;
+
                 /// a vector of heterogenous objects
                 template <class Base, class Alloc>//, class AbstractBase>
                 struct vector

Modified: sandbox/monotonic/boost/monotonic/allocator_base.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/allocator_base.hpp (original)
+++ sandbox/monotonic/boost/monotonic/allocator_base.hpp 2009-06-30 17:06:41 EDT (Tue, 30 Jun 2009)
@@ -7,8 +7,9 @@
 #define BOOST_MONOTONIC_ALLOCATOR_BASE_HPP
 
 #ifdef BOOST_HETEROGENOUS
-#include <boost/heterogenous/abstract_allocator.hpp>
+#include <boost/cloneable/abstract_allocator.hpp>
 #endif
+
 #include <boost/assert.hpp>
 #include <boost/monotonic/detail/prefix.hpp>
 #include <boost/type_traits/has_trivial_constructor.hpp>
@@ -18,12 +19,6 @@
 #include <boost/monotonic/detail/container.hpp>
 #include <boost/monotonic/detail/construct.hpp>
 
-//#include <boost/interprocess/containers/version_type.hpp>
-
-#ifdef BOOST_MONOTONIC_USE_POOLS
-# include <boost/monotonic/storage_pool.hpp>
-#endif
-
 namespace boost
 {
         namespace monotonic
@@ -32,7 +27,7 @@
                 template <class T, class Derived>
                 struct allocator_base
 #ifdef BOOST_HETEROGENOUS
- : heterogenous::abstract_allocator
+ : cloneable::abstract_allocator
 #endif
                 {
                         typedef size_t size_type;
@@ -54,10 +49,10 @@
 
 #ifdef BOOST_HETEROGENOUS
                         // override for abstract_allocator
- virtual heterogenous::abstract_allocator::pointer allocate_bytes(size_t num_bytes, size_t alignment)
+ virtual cloneable::abstract_allocator::pointer allocate_bytes(size_t num_bytes, size_t alignment)
                         {
                                 void *ptr = storage->allocate(num_bytes, alignment);
- return reinterpret_cast<heterogenous::abstract_allocator::pointer>(ptr);
+ return reinterpret_cast<cloneable::abstract_allocator::pointer>(ptr);
                         }
 
                         virtual void deallocate_bytes(char * /*bytes*/, size_t /*alignment*/ )

Modified: sandbox/monotonic/boost/monotonic/local.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/local.hpp (original)
+++ sandbox/monotonic/boost/monotonic/local.hpp 2009-06-30 17:06:41 EDT (Tue, 30 Jun 2009)
@@ -8,6 +8,7 @@
 
 #include <boost/monotonic/detail/prefix.hpp>
 #include <boost/monotonic/storage.hpp>
+#include <boost/monotonic/static_storage.hpp>
 
 namespace boost
 {

Modified: sandbox/monotonic/libs/monotonic/test/Tests/Tests.vcproj
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/Tests/Tests.vcproj (original)
+++ sandbox/monotonic/libs/monotonic/test/Tests/Tests.vcproj 2009-06-30 17:06:41 EDT (Tue, 30 Jun 2009)
@@ -41,7 +41,7 @@
                         <Tool
                                 Name="VCCLCompilerTool"
                                 Optimization="0"
- AdditionalIncludeDirectories="$(ProjectDir)/../../../..;C:\Lib\tbb21_20080605oss\include"
+ AdditionalIncludeDirectories="$(ProjectDir)/../../../..;C:\Lib\tbb21_20080605oss\include;c:/source/boost/sandbox/cloneable;"
                                 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
                                 MinimalRebuild="true"
                                 BasicRuntimeChecks="3"

Modified: sandbox/monotonic/libs/monotonic/test/monotonic.sln
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/monotonic.sln (original)
+++ sandbox/monotonic/libs/monotonic/test/monotonic.sln 2009-06-30 17:06:41 EDT (Tue, 30 Jun 2009)
@@ -7,7 +7,7 @@
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "object_model", "..\..\object_model\src\object_model.vcproj", "{E557E90C-C695-4A7B-B5A6-2F133AF88563}"
 EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "clones", "clones\clones.vcproj", "{36FA062B-37D3-49FF-A470-DDEDEBB7DE01}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cloneable_tests", "..\..\..\..\cloneable\libs\cloneable\test\cloneable.vcproj", "{5FF650E3-53E2-447F-8D2D-A85B76B214D3}"
 EndProject
 Global
         GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -33,17 +33,17 @@
                 {E557E90C-C695-4A7B-B5A6-2F133AF88563}.Release|Win32.Build.0 = Release|Win32
                 {E557E90C-C695-4A7B-B5A6-2F133AF88563}.ReleaseSym|Win32.ActiveCfg = ReleaseSym|Win32
                 {E557E90C-C695-4A7B-B5A6-2F133AF88563}.ReleaseSym|Win32.Build.0 = ReleaseSym|Win32
- {36FA062B-37D3-49FF-A470-DDEDEBB7DE01}.Debug|Win32.ActiveCfg = Debug|Win32
- {36FA062B-37D3-49FF-A470-DDEDEBB7DE01}.Debug|Win32.Build.0 = Debug|Win32
- {36FA062B-37D3-49FF-A470-DDEDEBB7DE01}.Release|Win32.ActiveCfg = Release|Win32
- {36FA062B-37D3-49FF-A470-DDEDEBB7DE01}.Release|Win32.Build.0 = Release|Win32
- {36FA062B-37D3-49FF-A470-DDEDEBB7DE01}.ReleaseSym|Win32.ActiveCfg = Release|Win32
- {36FA062B-37D3-49FF-A470-DDEDEBB7DE01}.ReleaseSym|Win32.Build.0 = Release|Win32
+ {5FF650E3-53E2-447F-8D2D-A85B76B214D3}.Debug|Win32.ActiveCfg = Debug|Win32
+ {5FF650E3-53E2-447F-8D2D-A85B76B214D3}.Debug|Win32.Build.0 = Debug|Win32
+ {5FF650E3-53E2-447F-8D2D-A85B76B214D3}.Release|Win32.ActiveCfg = Release|Win32
+ {5FF650E3-53E2-447F-8D2D-A85B76B214D3}.Release|Win32.Build.0 = Release|Win32
+ {5FF650E3-53E2-447F-8D2D-A85B76B214D3}.ReleaseSym|Win32.ActiveCfg = Release|Win32
+ {5FF650E3-53E2-447F-8D2D-A85B76B214D3}.ReleaseSym|Win32.Build.0 = Release|Win32
         EndGlobalSection
         GlobalSection(SolutionProperties) = preSolution
                 HideSolutionNode = FALSE
         EndGlobalSection
         GlobalSection(ExtensibilityGlobals) = postSolution
- VisualSVNWorkingCopyRoot = ..\..\..
+ VisualSVNWorkingCopyRoot = ..\..\..\..
         EndGlobalSection
 EndGlobal

Modified: sandbox/monotonic/libs/monotonic/test/monotonic.vcproj
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/monotonic.vcproj (original)
+++ sandbox/monotonic/libs/monotonic/test/monotonic.vcproj 2009-06-30 17:06:41 EDT (Tue, 30 Jun 2009)
@@ -41,7 +41,7 @@
                         <Tool
                                 Name="VCCLCompilerTool"
                                 Optimization="0"
- AdditionalIncludeDirectories="$(ProjectDir)/../../..;C:\Lib\tbb21_20080605oss\include"
+ AdditionalIncludeDirectories="$(ProjectDir)/../../..;C:\Lib\tbb21_20080605oss\include;c:/source/boost/sandbox/cloneable;"
                                 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
                                 MinimalRebuild="true"
                                 ExceptionHandling="2"

Modified: sandbox/monotonic/libs/object_model/src/object_model.vcproj
==============================================================================
--- sandbox/monotonic/libs/object_model/src/object_model.vcproj (original)
+++ sandbox/monotonic/libs/object_model/src/object_model.vcproj 2009-06-30 17:06:41 EDT (Tue, 30 Jun 2009)
@@ -41,7 +41,7 @@
                         <Tool
                                 Name="VCCLCompilerTool"
                                 Optimization="0"
- AdditionalIncludeDirectories="$(ProjectDir)/../../..;C:\Lib\tbb21_20080605oss\include"
+ AdditionalIncludeDirectories="$(ProjectDir)/../../..;C:\Lib\tbb21_20080605oss\include;$(ProjectDir)/../../../../cloneable;"
                                 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
                                 MinimalRebuild="true"
                                 BasicRuntimeChecks="3"


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