|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r54512 - in sandbox/monotonic: boost/heterogenous boost/heterogenous/detail libs/monotonic/test/clones
From: christian.schladetsch_at_[hidden]
Date: 2009-06-29 19:58:53
Author: cschladetsch
Date: 2009-06-29 19:58:51 EDT (Mon, 29 Jun 2009)
New Revision: 54512
URL: http://svn.boost.org/trac/boost/changeset/54512
Log:
added detail/allocation.hpp
Added:
sandbox/monotonic/boost/heterogenous/detail/allocation.hpp (contents, props changed)
Text files modified:
sandbox/monotonic/boost/heterogenous/make_clone_allocator.hpp | 12 +
sandbox/monotonic/boost/heterogenous/map.hpp | 203 +++++++++++++++------------------------
sandbox/monotonic/boost/heterogenous/vector.hpp | 37 +-----
sandbox/monotonic/libs/monotonic/test/clones/clones.vcproj | 4
4 files changed, 95 insertions(+), 161 deletions(-)
Added: sandbox/monotonic/boost/heterogenous/detail/allocation.hpp
==============================================================================
--- (empty file)
+++ sandbox/monotonic/boost/heterogenous/detail/allocation.hpp 2009-06-29 19:58:51 EDT (Mon, 29 Jun 2009)
@@ -0,0 +1,72 @@
+// 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_HETEROGENOUS_DETAIL_CONTAINER_BASE_HPP
+#define BOOST_HETEROGENOUS_DETAIL_CONTAINER_BASE_HPP
+
+#include <boost/heterogenous/detail/prefix.hpp>
+
+namespace boost
+{
+ namespace heterogenous
+ {
+ namespace detail
+ {
+ template <class U, class Alloc>
+ U *allocate_type(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 Alloc>
+ U *construct_type(Alloc &al)
+ {
+ typename Alloc::template rebind<U>::other alloc(al);
+ U *ptr = alloc.allocate(1);
+ alloc.construct(ptr);
+ return ptr;
+ }
+
+ template <class U, class Alloc, class A0>
+ U *construct_type(Alloc &al, A0 a0)
+ {
+ U *ptr = allocate_type<U>(al);
+ new (ptr) U(a0);
+ return ptr;
+ }
+
+ template <class U, class Alloc, class A0, class A1>
+ U *construct_type(Alloc &al, A0 a0, A1 a1)
+ {
+ U *ptr = allocate_type<U>(al);
+ new (ptr) U(a0, a1);
+ return ptr;
+ }
+
+ template <class U, class Alloc, class A0, class A1, class A2>
+ U *construct_type(Alloc &al, A0 a0, A1 a1, A2 a2)
+ {
+ U *ptr = allocate_type<U>(al);
+ new (ptr) U(a0, a1, a2);
+ return ptr;
+ }
+
+ // etc...
+
+ } // namespace detail
+
+ } // namespace heterogenous
+
+} // namespace boost
+
+#include <boost/heterogenous/detail/suffix.hpp>
+
+#endif // BOOST_HETEROGENOUS_DETAIL_CONTAINER_BASE_HPP
+
+//EOF
+
Modified: sandbox/monotonic/boost/heterogenous/make_clone_allocator.hpp
==============================================================================
--- sandbox/monotonic/boost/heterogenous/make_clone_allocator.hpp (original)
+++ sandbox/monotonic/boost/heterogenous/make_clone_allocator.hpp 2009-06-29 19:58:51 EDT (Mon, 29 Jun 2009)
@@ -30,9 +30,10 @@
size_t num_bytes;
};
- abstract_allocator::pointer allocate_bytes(size_t num_bytes, size_t alignment)
+ abstract_allocator::pointer allocate_bytes(size_t num_bytes, size_t /*alignment*/)
{
- return 0;
+ CharAlloc alloc(*this);
+ return alloc.allocate(num_bytes);
//CharAlloc alloc(*this);
//header head;
//head.num_bytes = sizeof(header) + num_bytes + alignment; // don't need this much, but will do for now
@@ -44,11 +45,12 @@
//return base;
}
- void deallocate_bytes(abstract_allocator::pointer ptr, size_t alignment)
+ void deallocate_bytes(abstract_allocator::pointer ptr, size_t /*alignment*/)
{
CharAlloc alloc(*this);
- header *head = reinterpret_cast<header *>(ptr - sizeof(head));
- alloc.deallocate(head->allocated_ptr, head->num_bytes);
+ alloc.deallocate(ptr);
+ //header *head = reinterpret_cast<header *>(ptr - sizeof(head));
+ //alloc.deallocate(head->allocated_ptr, head->num_bytes);
}
};
Modified: sandbox/monotonic/boost/heterogenous/map.hpp
==============================================================================
--- sandbox/monotonic/boost/heterogenous/map.hpp (original)
+++ sandbox/monotonic/boost/heterogenous/map.hpp 2009-06-29 19:58:51 EDT (Mon, 29 Jun 2009)
@@ -43,60 +43,98 @@
public:
map()
{
- //insert.key.parent = this;
}
map(allocator_type a)
: impl(a)
{
- //insert.key.parent = this;
}
/* purposefully elided
template <class II>
- vector(II F, II L, allocator_type a = allocator_type());
- vector(size_t reserved);
+ map(II F, II L, allocator_type a = allocator_type());
*/
- /*struct inserter
+ private:
+ struct value_adder
{
- struct key_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()
+ {
+ U *val = detail::construct_type<U>(parent->get_allocator());
+ 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)
{
- this_type *parent;
+ U *val = detail::construct_type<U>(parent->get_allocator(), a0);
+ parent->insert(std::make_pair(key_instance, val));
+ return *parent;
+ }
+ template <class U, class A0, class A1>
+ this_type &value(A0 a0, A1 a1)
+ {
+ U *val = detail::construct_type<U>(parent->get_allocator(), a0, a1);
+ parent->insert(std::make_pair(key_instance, val));
+ return *parent;
+ }
+ };
+
+ public:
+ template <class U>
+ value_adder key()
+ {
+ U *key_instance = detail::construct_type<U>(get_allocator());
+ 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)
+ {
+ U *key_instance = detail::construct_type<U>(get_allocator(), a0);
+ return value_adder(*this, *key_instance);
+ }
+ template <class U, class A0, class A1>
+ value_adder key(A0 a0, A1 a1)
+ {
+ U *key_instance = detail::construct_type<U>(get_allocator(), a0, a1);
+ return value_adder(*this, *key_instance);
+ }
+ template <class U, class A0, class A1, class A2>
+ value_adder key(A0 a0, A1 a1, A2 a2)
+ {
+ U *key_instance = detail::construct_type<U>(get_allocator(), a0, a1, a2);
+ return value_adder(*this, *key_instance);
+ }
- */ 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()
- {
- U *val = parent->construct_type<U>();
- parent->insert(std::make_pair(key_instance, val));
- return *parent;
- }
- };
-
- template <class U>
- //value_adder /*operator()*/set() const
- value_adder key()
- {
- U *key_instance = this->construct_type<U>();
- return value_adder(this, key_instance);
- }
- // } key;
- //} insert;
+ // 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(common_base &b, *this)
+ //BOOST_FOREACH(base_type &b, *this)
//{
// if (Ty *ptr = dynamic_cast<Ty *>(&b))
// {
@@ -106,12 +144,6 @@
return fun;
}
- void insert(value_type const &x)// key_type& key, mapped_type x )
- {
- impl.insert(x);
- }
-
-
template <class Ty, class Fun>
Fun for_each_mapped(Fun fun) const
{
@@ -151,100 +183,19 @@
return impl.end();
}
- //reference operator[](size_t n)
+ //reference operator[](key_type const &key)
//{
// return impl[n];
//}
- //const_reference operator[](size_t n) const
+ //const_reference operator[](key_type const &key) 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 push_back()
- //{
- // U *ptr = construct_type<U>();
- // impl.push_back(ptr);
- //}
- //template <class U, class A0>
- //void push_back(A0 a0)
- //{
- // U *ptr = allocate_type<U>();
- // new (ptr) U(a0);
- // impl.push_back(ptr);
- //}
- //template <class U, class A0, class A1>
- //void push_back(A0 a0, A1 a1)
- //{
- // U *ptr = allocate_type<U>();
- // new (ptr) U(a0, a1);
- // impl.push_back(ptr);
- //}
- //template <class U, class A0, class A1, class A2>
- //void push_back(A0 a0, A1 a1, A2 a2)
- //{
- // U *ptr = allocate_type<U>();
- // new (ptr) U(a0, a1, a2);
- // impl.push_back(ptr);
- //}
-
typename implementation::allocator_type get_allocator()
{
return impl.get_allocator();
}
-
- private:
- template <class U>
- U *allocate_type()
- {
- typename allocator_type::template rebind<U>::other alloc(get_allocator());
- return alloc.allocate(1);
- }
-
- template <class U>
- U *construct_type()
- {
- typename allocator_type::template rebind<U>::other alloc(get_allocator());
- U *ptr = alloc.allocate(1);
- alloc.construct(ptr);
- return ptr;
- }
-
};
} // namespace heterogenous
Modified: sandbox/monotonic/boost/heterogenous/vector.hpp
==============================================================================
--- sandbox/monotonic/boost/heterogenous/vector.hpp (original)
+++ sandbox/monotonic/boost/heterogenous/vector.hpp 2009-06-29 19:58:51 EDT (Mon, 29 Jun 2009)
@@ -13,6 +13,7 @@
#include <boost/heterogenous/detail/prefix.hpp>
#include <boost/heterogenous/base.hpp>
#include <boost/heterogenous/make_clone_allocator.hpp>
+#include <boost/heterogenous/detail/allocation.hpp>
namespace boost
{
@@ -38,7 +39,8 @@
vector()
{
}
- vector(allocator_type a)
+
+ vector(allocator_type &a)
: impl(a)
{
}
@@ -173,53 +175,28 @@
template <class U>
void emplace_back()
{
- U *ptr = construct_type<U>();
- impl.emplace_back(ptr);
+ impl.push_back(detail::construct_type<U>(get_allocator()));
}
template <class U, class A0>
void emplace_back(A0 a0)
{
- U *ptr = allocate_type<U>();
- new (ptr) U(a0);
- impl.push_back(ptr);
+ impl.push_back(detail::construct_type<U>(get_allocator(), a0));
}
template <class U, class A0, class A1>
void emplace_back(A0 a0, A1 a1)
{
- U *ptr = allocate_type<U>();
- new (ptr) U(a0, a1);
- impl.push_back(ptr);
+ impl.push_back(detail::construct_type<U>(get_allocator(), a0,a1));
}
template <class U, class A0, class A1, class A2>
void emplace_back(A0 a0, A1 a1, A2 a2)
{
- U *ptr = allocate_type<U>();
- new (ptr) U(a0, a1, a2);
- impl.push_back(ptr);
+ impl.push_back(detail::construct_type<U>(get_allocator(), a0,a1,a2));
}
typename implementation::allocator_type get_allocator()
{
return impl.get_allocator();
}
-
- private:
- template <class U>
- U *allocate_type()
- {
- typename allocator_type::template rebind<U>::other alloc(get_allocator());
- return alloc.allocate(1);
- }
-
- template <class U>
- U *construct_type()
- {
- typename allocator_type::template rebind<U>::other alloc(get_allocator());
- U *ptr = alloc.allocate(1);
- alloc.construct(ptr);
- return ptr;
- }
-
};
} // namespace heterogenous
Modified: sandbox/monotonic/libs/monotonic/test/clones/clones.vcproj
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/clones/clones.vcproj (original)
+++ sandbox/monotonic/libs/monotonic/test/clones/clones.vcproj 2009-06-29 19:58:51 EDT (Mon, 29 Jun 2009)
@@ -386,6 +386,10 @@
Name="detail"
>
<File
+ RelativePath="..\..\..\..\boost\heterogenous\detail\allocation.hpp"
+ >
+ </File>
+ <File
RelativePath="..\..\..\..\boost\heterogenous\detail\prefix.hpp"
>
</File>
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