Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54270 - in sandbox/monotonic: boost/monotonic/extra libs/monotonic/test/Tests
From: christian.schladetsch_at_[hidden]
Date: 2009-06-23 03:36:27


Author: cschladetsch
Date: 2009-06-23 03:36:24 EDT (Tue, 23 Jun 2009)
New Revision: 54270
URL: http://svn.boost.org/trac/boost/changeset/54270

Log:
added monotonic::set, map, list, vector, string
Text files modified:
   sandbox/monotonic/boost/monotonic/extra/list.hpp | 23 +++++++--
   sandbox/monotonic/boost/monotonic/extra/map.hpp | 34 +++++++------
   sandbox/monotonic/boost/monotonic/extra/set.hpp | 96 ++++++++++++++++++++++++++++++++++-----
   sandbox/monotonic/boost/monotonic/extra/string.hpp | 51 ++++++++++----------
   sandbox/monotonic/boost/monotonic/extra/vector.hpp | 22 ++++----
   sandbox/monotonic/libs/monotonic/test/Tests/tests.cpp | 54 +++++++++++++++++-----
   6 files changed, 198 insertions(+), 82 deletions(-)

Modified: sandbox/monotonic/boost/monotonic/extra/list.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/extra/list.hpp (original)
+++ sandbox/monotonic/boost/monotonic/extra/list.hpp 2009-06-23 03:36:24 EDT (Tue, 23 Jun 2009)
@@ -15,12 +15,13 @@
         namespace monotonic
         {
                 /// A list that uses a monotonic allocator by default
- template <class T>
- struct list : detail::monotonic_container<list<T> >
+ template <class T, class Region = default_region_tag, class Access = default_access_tag>
+ struct list : detail::monotonic_container<list<T,Region,Access> >
                 {
- typedef allocator<T> Allocator;
+ typedef allocator<T,Region,Access> Allocator;
                         typedef std::list<T, Allocator> List, Implementation;
                         typedef detail::monotonic_container<std::list<T, Allocator> > Parent;
+
                         typedef typename List::iterator iterator;
                         typedef typename List::const_iterator const_iterator;
                         typedef typename List::size_type size_type;
@@ -34,10 +35,11 @@
 
                 public:
                         list() { }
- list(Allocator const &A)
+ list(Allocator A)
                                 : impl(A) { }
+
                         template <class II>
- list(II F, II L, Allocator const &A)
+ list(II F, II L, Allocator A = Allocator())
                                 : impl(F,L,A) { }
                 
                         Allocator get_allocator()
@@ -107,6 +109,17 @@
                         }
                 };
 
+ template <class Ty,class R,class Acc,class Ty2,class R2,class Acc2>
+ bool operator==(list<Ty,R,Acc> const &A, list<Ty2,R2,Acc2> const &B)
+ {
+ return A.size() == B.size() && std::equal(A.begin(), A.end(), B.begin());
+ }
+
+ template <class Ty,class R,class Acc,class Ty2,class R2,class Acc2>
+ bool operator<(list<Ty,R,Acc> const &A, list<Ty2,R2,Acc2> const &B)
+ {
+ return std::lexicographical_compare(A.begin(), A.end(), B.begin(), B.end());
+ }
         } // namespace monotonic
 
 } // namespace boost

Modified: sandbox/monotonic/boost/monotonic/extra/map.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/extra/map.hpp (original)
+++ sandbox/monotonic/boost/monotonic/extra/map.hpp 2009-06-23 03:36:24 EDT (Tue, 23 Jun 2009)
@@ -13,16 +13,20 @@
 {
         namespace monotonic
         {
- /// A map that uses a monotonic allocator, and respects that allocator
- /// when creating new referent instances
- template <class K, class T, class P = std::less<K> >
- struct map : detail::monotonic_container<map<K,T,P> >
+ /// A map that uses a monotonic allocator
+ template <class K // key-type
+ , class T // value-type
+ , class Region = default_region_tag // allocation region
+ , class P = std::less<K> // predicate
+ , class Access = default_access_tag // access type
+ >
+ struct map : detail::monotonic_container<map<K,T,Region,P,Access> >
                 {
- typedef detail::monotonic_container<map<K,T,P> > Parent;
+ typedef P Predicate;
+ typedef allocator<K,Region,Access> Allocator;
+ typedef detail::monotonic_container<map<K,T,Region,P,Access> > Parent;
                         typedef detail::Create<detail::is_monotonic<T>::value, T> Create;
 
- typedef P Predicate;
- typedef allocator<K> Allocator;
                         typedef std::map<K,T,P,Allocator > Map, Implementation;
                         typedef typename Map::iterator iterator;
                         typedef typename Map::const_iterator const_iterator;
@@ -33,20 +37,19 @@
 
                 private:
                         Implementation impl;
- Predicate pred;
+ Predicate pred; ///< do we really need to store a copy of the predicate?
 
                 public:
 
                         map() { }
                         map(Allocator const &A)
                                 : impl(Predicate(), A) { }
- map(Predicate Pr, Allocator const &A)
+ map(Predicate Pr, Allocator A = Allocator())
                                 : impl(Pr, A), pred(Pr) { }
+ map(const map& other)
+ : impl(other.impl), pred(other.pred) { }
                         template <class II>
- map(II F, II L, Allocator const &A, Predicate const &Pr = Predicate())
- : impl(F,L,Pr,A), pred(Pr) { }
- template <class II>
- map(II F, II L, Predicate const &Pr, Allocator const &A)
+ map(II F, II L, Predicate const &Pr = Predicate(), Allocator A = Allocator())
                                 : impl(F,L,Pr,A), pred(Pr) { }
 
                         Allocator get_allocator() const
@@ -117,8 +120,9 @@
                         }
                 };
 
- }
-}
+ } // namespace monotonic
+
+} // namespace boost
 
 #endif // BOOST_MONOTONIC_MAP_H
 

Modified: sandbox/monotonic/boost/monotonic/extra/set.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/extra/set.hpp (original)
+++ sandbox/monotonic/boost/monotonic/extra/set.hpp 2009-06-23 03:36:24 EDT (Tue, 23 Jun 2009)
@@ -8,33 +8,101 @@
 
 #include <set>
 #include <boost/monotonic/allocator.hpp>
+#include <boost/monotonic/container.hpp>
 
 namespace boost
 {
         namespace monotonic
         {
                 /// A std::set<T,P> that uses a monotonic allocator
- template <class T, class P = std::less<T> >
- struct set : std::set<T,P, allocator<T> >
+ template <class T
+ , class Region = default_region_tag // allocation region
+ , class P = std::less<T> // predicate
+ , class Access = default_access_tag> // access type
+ struct set : detail::monotonic_container<set<T,Region,P,Access> >
                 {
- typedef allocator<T> Allocator;
+ typedef allocator<T,Region,Access> Allocator;
                         typedef P Predicate;
- typedef std::set<T,P,allocator<T> > Set;
+ typedef std::set<T,P,Allocator > Set;
+ typedef typename Set::iterator iterator;
+ typedef typename Set::const_iterator const_iterator;
+ typedef typename Set::value_type value_type;
+ typedef typename Set::key_type key_type;
+ typedef typename Set::size_type size_type;
+ private:
+ Set impl;
 
+ public:
                         set() { }
- set(Allocator const &A)
- : Set(Predicate(), A) { }
- set(Predicate Pr, Allocator const &A)
- : Set(Pr, A) { }
+ set(Allocator A)
+ : impl(Predicate(), A) { }
+ set(Predicate Pr, Allocator A)
+ : impl(Pr, A) { }
                         template <class II>
- set(II F, II L, Allocator const &A)
- : Set(F,L,Predicate(),A) { }
+ set(II F, II L, Allocator A = Allocator())
+ : impl(F,L,Predicate(),A) { }
                         template <class II>
- set(II F, II L, Predicate const &Pr, Allocator const &A)
- : Set(F,L,Pr,A) { }
+ set(II F, II L, Predicate Pr, Allocator A = Allocator())
+ : impl(F,L,Pr,A) { }
+
+ Allocator get_allocator() const
+ {
+ return impl.get_allocator();
+ }
+ void clear()
+ {
+ impl.clear();
+ }
+ size_type 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();
+ }
+
+ void insert(const value_type& value)
+ {
+ impl.insert(value);
+ }
+ void erase(iterator first)
+ {
+ impl.erase(first);
+ }
+ void erase(iterator first, iterator last)
+ {
+ impl.erase(first, last);
+ }
+ iterator find(value_type const &key)
+ {
+ return impl.find(key);
+ }
+ const_iterator find(value_type const &key) const
+ {
+ return impl.find(key);
+ }
                 };
- }
-}
+
+ } // namespace monotonic
+
+} // namespace boost
 
 #endif // BOOST_MONOTONIC_SET_H
 

Modified: sandbox/monotonic/boost/monotonic/extra/string.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/extra/string.hpp (original)
+++ sandbox/monotonic/boost/monotonic/extra/string.hpp 2009-06-23 03:36:24 EDT (Tue, 23 Jun 2009)
@@ -8,24 +8,23 @@
 
 #include <string>
 #include <boost/monotonic/allocator.hpp>
-#include <boost/monotonic/container.hpp>
 
 namespace boost
 {
         namespace monotonic
         {
- //template <class Ch = char, class Tr = std::char_traits<Ch> >
+ /// a string that uses a monotonic allocator in the given region
+ template <class Region = default_region_tag>
                 struct string
                 {
                         typedef char Ch;
                         typedef std::char_traits<Ch> Tr;
- typedef allocator<Ch> Allocator;
-
- typedef std::basic_string<Ch, Tr, Allocator > Impl;
+ typedef allocator<Ch, Region> Allocator;
+ typedef std::basic_string<Ch, Tr, Allocator> Impl;
                         typedef size_t size_type;
- typedef Impl::iterator iterator;
- typedef Impl::const_iterator const_iterator;
- typedef Impl::value_type value_type;
+ typedef typename Impl::iterator iterator;
+ typedef typename Impl::const_iterator const_iterator;
+ typedef typename Impl::value_type value_type;
 
                 private:
                         Impl impl;
@@ -38,37 +37,39 @@
                                 : impl(other.impl)
                         {
                         }
- string(storage_base &store)
- : impl(store)
+ template <class U>
+ string(allocator<U, Region> &alloc)
+ : impl(alloc)
                         {
                         }
- template <class U>
- string(allocator<U> &store)
- : impl(store)
+ string(const Ch *str)
+ : impl(str)
                         {
                         }
- string(const Ch *str, storage_base &store)
- : impl(str, store)
+ template <class U>
+ string(const Ch *str, allocator<U, Region> &alloc)
+ : impl(str, alloc)
                         {
                         }
                         template <class II>
- string(II F, II L, storage_base &store)
- : impl(F, L, store)
+ string(II F, II L)
+ : impl(F, L)
                         {
                         }
- string &operator=(string const &other)
+ template <class II, class U>
+ string(II F, II L, allocator<U, Region> &alloc)
+ : impl(F, L, alloc)
                         {
- if (&other == this)
- return *this;
- impl = other.impl;
- return *this;
                         }
- //string &operator+=(string const &other)
- //{
 
- //}
+ string &operator+=(Ch const *str)
+ {
+ impl += str;
+ return *this;
+ }
 
                 };
+
         } // namespace monotonic
 
 } // namespace boost

Modified: sandbox/monotonic/boost/monotonic/extra/vector.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/extra/vector.hpp (original)
+++ sandbox/monotonic/boost/monotonic/extra/vector.hpp 2009-06-23 03:36:24 EDT (Tue, 23 Jun 2009)
@@ -14,13 +14,14 @@
         namespace monotonic
         {
                 /// a vector that uses a monotonic allocator by default
- template <class T>
- struct vector : detail::monotonic_container<vector<T> >
+ template <class T, class Region = default_region_tag, class Access = default_access_tag>
+ struct vector : detail::monotonic_container<vector<T,Region,Access> >
                 {
- typedef detail::monotonic_container<std::vector<T, allocator<T> > > Parent;
+ typedef allocator<T,Region,Access> Allocator;
+ typedef detail::monotonic_container<std::vector<T, Allocator > > Parent;
                         typedef detail::Create<detail::is_monotonic<T>::value, T> Create;
- typedef allocator<T> Allocator;
                         typedef std::vector<T,Allocator> Vector;
+
                         typedef typename Vector::iterator iterator;
                         typedef typename Vector::const_iterator const_iterator;
                         typedef typename Vector::size_type size_type;
@@ -28,7 +29,6 @@
                         typedef typename Vector::reference reference;
                         typedef typename Vector::const_reference const_reference;
 
-
                 private:
                         Vector impl;
 
@@ -36,10 +36,10 @@
                         vector() { }
                         vector(Allocator const &A)
                                 : impl(A) { }
- vector(size_t N, T const &X, Allocator const &A)
+ vector(size_t N, T const &X, Allocator A = Allocator())
                                 : impl(N,X,A) { }
                         template <class II>
- vector(II F, II L, Allocator const &A)
+ vector(II F, II L, Allocator A = Allocator())
                                 : impl(F,L,A) { }
 
                         Allocator get_allocator() const
@@ -129,14 +129,14 @@
                         }
                 };
 
- template <class Ty>
- bool operator==(vector<Ty> const &A, vector<Ty> const &B)
+ template <class Ty,class R,class Acc,class Ty2,class R2,class Acc2>
+ bool operator==(vector<Ty,R,Acc> const &A, vector<Ty2,R2,Acc2> const &B)
                 {
                         return A.size() == B.size() && std::equal(A.begin(), A.end(), B.begin());
                 }
                 
- template <class Ty>
- bool operator<(vector<Ty> const &A, vector<Ty> const &B)
+ template <class Ty,class R,class Acc,class Ty2,class R2,class Acc2>
+ bool operator<(vector<Ty,R,Acc> const &A, vector<Ty2,R2,Acc2> const &B)
                 {
                         return std::lexicographical_compare(A.begin(), A.end(), B.begin(), B.end());
                 }

Modified: sandbox/monotonic/libs/monotonic/test/Tests/tests.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/Tests/tests.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/Tests/tests.cpp 2009-06-23 03:36:24 EDT (Tue, 23 Jun 2009)
@@ -10,6 +10,7 @@
 #include <boost/monotonic/shared_allocator.hpp>
 #include <boost/monotonic/local.hpp>
 #include <boost/monotonic/allocator.hpp>
+#include <boost/monotonic/extra/string.hpp>
 
 #define BOOST_TEST_MODULE basic_test test
 #include <boost/test/unit_test.hpp>
@@ -26,6 +27,38 @@
 struct region0 {};
 struct region1 {};
 
+BOOST_AUTO_TEST_CASE(test_map)
+{
+ monotonic::map<int, monotonic::string<region1>, region1> map;
+ map[1] = "foo";
+ map[2] = "bar";
+}
+
+BOOST_AUTO_TEST_CASE(test_vector)
+{
+ monotonic::vector<int> vec;
+ vec.resize(100);
+
+ monotonic::vector<int, region1> vec2;
+ vec2.resize(100);
+
+ monotonic::static_storage<>::reset();
+ monotonic::static_storage<region1>::reset();
+}
+
+BOOST_AUTO_TEST_CASE(test_list)
+{
+ monotonic::list<int> cont;
+ fill_n(back_inserter(cont), 100, 42);
+
+ monotonic::list<int, region1> cont2;
+ fill_n(back_inserter(cont2), 100, 42);
+
+ monotonic::static_storage<>::reset();
+ monotonic::static_storage<region1>::reset();
+}
+
+
 BOOST_AUTO_TEST_CASE(test_local)
 {
         monotonic::local<region0> storage0;
@@ -36,7 +69,7 @@
                 fill_n(back_inserter(list0), 100, 42);
                 fill_n(back_inserter(list1), 100, 42);
 
- std::basic_string<char, std::char_traits<char>, monotonic::allocator<char, region0> > str("foo");
+ monotonic::string<region0> str("foo");
                 str += "bar";
                 BOOST_ASSERT(str == "foobar");
         }
@@ -159,33 +192,33 @@
 
 BOOST_AUTO_TEST_CASE(test_ctors)
 {
- monotonic::storage<> storage;
         string foo = "foo";
         {
- monotonic::vector<char> v1(foo.begin(), foo.end(), storage);
+ monotonic::vector<char> v1(foo.begin(), foo.end());
                 BOOST_CHECK(v1.size() == 3);
                 BOOST_CHECK(equal(v1.begin(), v1.end(), "foo"));
 
- monotonic::vector<char> v2(6, 'x', storage);
+ monotonic::vector<char> v2(6, 'x');
                 BOOST_CHECK(v2.size() == 6);
                 BOOST_CHECK(equal(v2.begin(), v2.end(), "xxxxxx"));
 
- monotonic::set<char> s2(foo.begin(), foo.end(), storage);
+ monotonic::set<char> s2(foo.begin(), foo.end());
                 BOOST_CHECK(s2.size() == 2);
                 BOOST_CHECK(s2.find('f') != s2.end());
                 BOOST_CHECK(s2.find('o') != s2.end());
 
- monotonic::vector<pair<int, string> > v(storage);
+ monotonic::vector<pair<int, string> > v;
                 v.push_back(make_pair(42,"foo"));
                 v.push_back(make_pair(123,"bar"));
 
- monotonic::map<int, string> m1(v.begin(), v.end(), storage);
+ monotonic::map<int, string> m1(v.begin(), v.end());
                 BOOST_CHECK(m1.find(42) != m1.end());
                 BOOST_CHECK(m1.find(123) != m1.end());
 
- monotonic::list<int> l1(foo.begin(), foo.end(), storage);
+ monotonic::list<int> l1(foo.begin(), foo.end());
                 BOOST_CHECK(equal(l1.begin(), l1.end(), "foo"));
         }
+ monotonic::reset_storage();
 }
 
 BOOST_AUTO_TEST_CASE( test_copy )
@@ -274,10 +307,7 @@
 
 BOOST_AUTO_TEST_CASE(test_string)
 {
- monotonic::storage<> storage;
- {
- monotonic::string str(storage);
- }
+ monotonic::string<> str;
 }
 
 //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