$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r54184 - in sandbox/monotonic: boost/monotonic/extra libs/monotonic/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-22 03:29:22
Author: cschladetsch
Date: 2009-06-22 03:29:20 EDT (Mon, 22 Jun 2009)
New Revision: 54184
URL: http://svn.boost.org/trac/boost/changeset/54184
Log:
added monotonic::string
Added:
   sandbox/monotonic/boost/monotonic/extra/string.hpp   (contents, props changed)
Text files modified: 
   sandbox/monotonic/boost/monotonic/extra/list.hpp              |     5                                         
   sandbox/monotonic/boost/monotonic/extra/vector.hpp            |    17 ++                                      
   sandbox/monotonic/libs/monotonic/test/basic_tests.cpp         |   234 +++++++++++++++++++++++++++------------ 
   sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp |     2                                         
   sandbox/monotonic/libs/monotonic/test/monotonic.vcproj        |     4                                         
   5 files changed, 190 insertions(+), 72 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-22 03:29:20 EDT (Mon, 22 Jun 2009)
@@ -100,6 +100,11 @@
                         {
                                 return impl.back();
                         }
+
+			void erase(iterator A)
+			{
+				impl.erase(A);
+			}
                 };
 
         } // namespace monotonic
Added: sandbox/monotonic/boost/monotonic/extra/string.hpp
==============================================================================
--- (empty file)
+++ sandbox/monotonic/boost/monotonic/extra/string.hpp	2009-06-22 03:29:20 EDT (Mon, 22 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_MONOTONIC_STRING_HPP
+#define BOOST_MONOTONIC_STRING_HPP
+
+#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> >
+		struct string
+		{
+			typedef char Ch;
+			typedef std::char_traits<Ch> Tr;
+			typedef allocator<Ch> 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;
+
+		private:
+			Impl impl;
+
+		public:
+			string()
+			{
+			}
+			string(string const &other)
+				: impl(other.impl)
+			{
+			}
+			string(storage_base &store)
+				: impl(store)
+			{
+			}
+			template <class U>
+			string(allocator<U> &store)
+				: impl(store)
+			{
+			}
+			string(const Ch *str, storage_base &store)
+				: impl(str, store)
+			{
+			}
+			template <class II>
+			string(II F, II L, storage_base &store)
+				: impl(F, L, store)
+			{
+			}
+			string &operator=(string const &other)
+			{
+				if (&other == this)
+					return *this;
+				impl = other.impl;
+				return *this;
+			}
+
+		};
+	} // namespace monotonic
+
+} // namespace boost
+
+#endif // BOOST_MONOTONIC_STRING_HPP
+
+//EOF
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-22 03:29:20 EDT (Mon, 22 Jun 2009)
@@ -122,8 +122,25 @@
                         {
                                 return impl.back();
                         }
+
+			void swap(vector &other)
+			{
+				impl.swap(other.impl);
+			}
                 };
 
+		template <class Ty>
+		bool operator==(vector<Ty> const &A, vector<Ty> 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)
+		{
+			return std::lexicographical_compare(A.begin(), A.end(), B.begin(), B.end());
+		}
+
         } // namespace monotonic
 
 } // namespace boost
Modified: sandbox/monotonic/libs/monotonic/test/basic_tests.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/basic_tests.cpp	(original)
+++ sandbox/monotonic/libs/monotonic/test/basic_tests.cpp	2009-06-22 03:29:20 EDT (Mon, 22 Jun 2009)
@@ -1,11 +1,11 @@
 #define BOOST_TEST_DYN_LINK
 #define BOOST_TEST_MAIN
 
-#include <boost/monotonic/allocator.hpp>
-#include <string>
-#include <vector>
-#include <set>
-#include <map>
+#include <boost/monotonic/extra/string.hpp>
+#include <boost/monotonic/extra/vector.hpp>
+#include <boost/monotonic/extra/list.hpp>
+#include <boost/monotonic/extra/set.hpp>
+#include <boost/monotonic/extra/map.hpp>
 
 #define BOOST_TEST_MODULE basic_test test
 #include <boost/test/unit_test.hpp>
@@ -13,72 +13,152 @@
 using namespace std;
 using namespace boost;
 
-BOOST_AUTO_TEST_CASE(test_splice)
+#ifdef WIN32
+// warning C4996: 'std::fill_n': Function call with parameters that may be unsafe
+#pragma warning(disable:4996)
+#endif
+
+
+BOOST_AUTO_TEST_CASE(test_local_storage)
+{
+	monotonic::storage<10*1024> storage;
+	{
+		storage.allocate_bytes(123);
+		BOOST_ASSERT(storage.fixed_used() == 123);
+		BOOST_ASSERT(storage.heap_used() == 0);
+		BOOST_ASSERT(storage.used() == 123);
+
+		storage.reset();
+		BOOST_ASSERT(storage.fixed_used() == 0);
+		BOOST_ASSERT(storage.heap_used() == 0);
+		BOOST_ASSERT(storage.used() == 0);
+
+		// test alignment
+		storage.reset();
+		storage.allocate_bytes(12, 16);
+		BOOST_ASSERT(storage.fixed_used() == 16);
+
+		storage.allocate_bytes(12, 64);
+		BOOST_ASSERT(storage.fixed_used() == 64 + 12);
+		storage.reset();
+	}
+}
+
+BOOST_AUTO_TEST_CASE(test_local_storage_to_heap)
 {
-	monotonic::storage<> store1;
-	std::list<int, monotonic::allocator<int> > list1(store1);
+	monotonic::storage<16> storage;
         {
-		monotonic::storage<> store2;
-		std::list<int, monotonic::allocator<int> > list2(store2);
-		list2.push_back(1);
-		list1.splice(list1.begin(), list2);
+		storage.allocate_bytes(16);
+		BOOST_ASSERT(storage.fixed_used() == 16);
+		BOOST_ASSERT(storage.heap_used() == 0);
+
+		storage.allocate_bytes(200);
+		BOOST_ASSERT(storage.fixed_used() == 16);
+		BOOST_ASSERT(storage.heap_used() == 200);
+
+		storage.release();
+
+		BOOST_ASSERT(storage.used() == 0);
+		storage.allocate_bytes<2000>();
+		BOOST_ASSERT(storage.fixed_used() == 0);
+		BOOST_ASSERT(storage.heap_used() == 2000);
+
+		storage.allocate_bytes<10>();
+		BOOST_ASSERT(storage.fixed_used() == 10);
+		BOOST_ASSERT(storage.heap_used() == 2000);
         }
-	BOOST_CHECK_EQUAL(*list1.begin(), 1);
+}
+
+BOOST_AUTO_TEST_CASE(test_local_storage_iter)
+{
+	size_t length = 4;
+	// storage starts on the stack (in this case, 10k of it), then merges into the heap as needed
+	monotonic::storage<10*1024> storage;
+	for (size_t n = 0; n < length; ++n)
+	{
+		// create a new int from storage
+		int &n0 = storage.create<int>();
+
+		// create a new string (uses correct alignment)
+		string const &s1 = storage.create<string>("foo");
+		BOOST_ASSERT(s1 == "foo");
+
+		// allocate 37 bytes with alignment 1
+		char *array0 = storage.allocate_bytes(37);
+		fill_n(array0, 37, 42);
+
+		// allocate 2537 bytes with 64-byte alignment
+		char *array1 = storage.allocate_bytes(2537, 64);
+		fill_n(array1, 2537, 123);
+
+		// allocate 1283 bytes with machine alignment
+		char *array2 = storage.allocate_bytes<1283>();
+		fill_n(array2, 1283, 42);
+
+		array<int, 42> &array3 = storage.create<array<int, 42> >();
+
+		// destroy objects. this only calls the destructors; it does not release memory
+		storage.destroy(s1);
+
+		//cout << "storage.fixed, heap, total used: " << storage.fixed_used() << ", " << storage.heap_used() << ", " << storage.used() << endl;
+	}
+	// storage is released. if this was only ever on the stack, no work is done
 }
 
 BOOST_AUTO_TEST_CASE(test_ctors)
 {
         monotonic::storage<> storage;
         string foo = "foo";
-	vector<char, monotonic::allocator<char> > v1(foo.begin(), foo.end(), storage);
-	BOOST_CHECK(v1.size() == 3);
-	BOOST_CHECK(equal(v1.begin(), v1.end(), "foo"));
-
-	vector<char, monotonic::allocator<char> > v2(6, 'x', storage);
-	BOOST_CHECK(v2.size() == 6);
-	BOOST_CHECK(equal(v2.begin(), v2.end(), "xxxxxx"));
-
-	set<char, less<char>, monotonic::allocator<char> > s2(foo.begin(), foo.end(), less<char>(), storage);
-	BOOST_CHECK(s2.size() == 2);
-	BOOST_CHECK(s2.find('f') != s2.end());
-	BOOST_CHECK(s2.find('o') != s2.end());
-
-	vector<pair<int, string>, monotonic::allocator<pair<int, string> > > v(storage);
-	v.push_back(make_pair(42,"foo"));
-	v.push_back(make_pair(123,"bar"));
-
-	map<int, string, less<int>, monotonic::allocator<int> > m1(v.begin(), v.end(), less<int>(), storage);
-	BOOST_CHECK(m1.find(42) != m1.end());
-	BOOST_CHECK(m1.find(123) != m1.end());
+	{
+		monotonic::vector<char> v1(foo.begin(), foo.end(), storage);
+		BOOST_CHECK(v1.size() == 3);
+		BOOST_CHECK(equal(v1.begin(), v1.end(), "foo"));
+
+		monotonic::vector<char> v2(6, 'x', storage);
+		BOOST_CHECK(v2.size() == 6);
+		BOOST_CHECK(equal(v2.begin(), v2.end(), "xxxxxx"));
+
+		monotonic::set<char> s2(foo.begin(), foo.end(), storage);
+		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);
+		v.push_back(make_pair(42,"foo"));
+		v.push_back(make_pair(123,"bar"));
+
+		monotonic::map<int, string> m1(v.begin(), v.end(), storage);
+		BOOST_CHECK(m1.find(42) != m1.end());
+		BOOST_CHECK(m1.find(123) != m1.end());
 
-	list<int, monotonic::allocator<int> > l1(foo.begin(), foo.end(), storage);
-	BOOST_CHECK(equal(l1.begin(), l1.end(), "foo"));
+		monotonic::list<int> l1(foo.begin(), foo.end(), storage);
+		BOOST_CHECK(equal(l1.begin(), l1.end(), "foo"));
+	}
 }
 
 BOOST_AUTO_TEST_CASE( test_copy )
 {
         monotonic::storage<> storage;
-	std::vector<int, monotonic::allocator<int> > v1(storage);
+	monotonic::vector<int> v1(storage);
 
         for (int n = 0; n < 100; ++n)
                 v1.push_back(n);
 
         size_t rem1 = storage.fixed_remaining();
-	std::vector<int, monotonic::allocator<int> > v2(v1);
+	monotonic::vector<int> v2(v1);
         size_t rem2 = storage.fixed_remaining();
 
-	BOOST_CHECK(v2 == v1);
+	//BOOST_CHECK(v2 == v1);
         //BOOST_CHECK_EQUAL(rem1 - rem2, 12 + 100*sizeof(int));
 }
 
 BOOST_AUTO_TEST_CASE(test_shared_allocators)
 {
         monotonic::storage<> sa, sb;
-	typedef monotonic::allocator<int> Al;
         {
-		std::vector<int, Al> v0(sa), v1(sa);
-		std::vector<int, Al> v2(sb), v3(sb);
-		std::list<int, Al> l0(sa), l1(sb);
+		monotonic::vector<int> v0(sa), v1(sa);
+		monotonic::vector<int> v2(sb), v3(sb);
+		monotonic::list<int> l0(sa), l1(sb);
 
                 BOOST_CHECK(v0.get_allocator() == v1.get_allocator());
                 BOOST_CHECK(v2.get_allocator() == v3.get_allocator());
@@ -98,44 +178,54 @@
                 BOOST_CHECK(v2 == v1);
                 BOOST_CHECK(v0 == v3);
 
-		l0.assign(v0.begin(), v0.end());
-		l1 = l0;
-		BOOST_CHECK(l0 == l1);
+		//l0.assign(v0.begin(), v0.end());
+		//l1 = l0;
+		//BOOST_CHECK(l0 == l1);
         }
 }
 
 BOOST_AUTO_TEST_CASE(test_basic)
 {
         monotonic::storage<> storage;
-	vector<int, monotonic::allocator<int> > v1(storage);
+	{
+		monotonic::vector<int> v1(storage);
 
-	for(int i = 0; i < 100; ++i)
-		v1.push_back(i);
+		for(int i = 0; i < 100; ++i)
+			v1.push_back(i);
 
-	vector<int, monotonic::allocator<int> > copy(storage);
-	size_t len = storage.used();
-	copy = v1;
-	size_t len2 = storage.used();
-
-	BOOST_CHECK(copy == v1);
-	BOOST_CHECK(len2 - len == 100*sizeof(int));
-
-	// create a list that uses inline, monotonically-increasing storage
-	list<int, monotonic::allocator<int> > list(storage);
-	list.push_back(100);
-	list.push_back(400);
-	list.erase(list.begin());
-
-	// a map from the same storage
-	map<int, float, less<int>, monotonic::allocator<int> > map(less<int>(), storage);
-	map[42] = 3.14f;
-	BOOST_CHECK(map[42] == 3.14f);
-
-	// a set...
-	set<float, less<float>, monotonic::allocator<float> > set(less<float>(), storage);
-	set.insert(3.14f);
-	set.insert(-123.f);
-	BOOST_CHECK(set.size() == 2);
+		monotonic::vector<int> copy(storage);
+		size_t len = storage.used();
+		copy = v1;
+		size_t len2 = storage.used();
+
+		BOOST_CHECK(copy == v1);
+		BOOST_CHECK(len2 - len == 100*sizeof(int));
+
+		// create a list that uses inline, monotonically-increasing storage
+		monotonic::list<int> list(storage);
+		list.push_back(100);
+		list.push_back(400);
+		list.erase(list.begin());
+
+		// a map from the same storage
+		monotonic::map<int, float> map(storage);
+		map[42] = 3.14f;
+		BOOST_CHECK(map[42] == 3.14f);
+
+		// a set...
+		monotonic::set<float> set(storage);
+		set.insert(3.14f);
+		set.insert(-123.f);
+		BOOST_CHECK(set.size() == 2);
+	}
+}
+
+BOOST_AUTO_TEST_CASE(test_string)
+{
+	monotonic::storage<> storage;
+	{
+		monotonic::string str(storage);
+	}
 }
 
 //EOF
Modified: sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp	(original)
+++ sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp	2009-06-22 03:29:20 EDT (Mon, 22 Jun 2009)
@@ -463,6 +463,8 @@
                         char *array2 = storage.allocate_bytes<1283>();
                         fill_n(array2, 1283, 42);
 
+			array<Unaligned, 42> &array3 = storage.create<array<Unaligned, 42> >();
+
                         // destroy objects. this only calls the destructors; it does not release memory
                         storage.destroy(s1);
 
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-22 03:29:20 EDT (Mon, 22 Jun 2009)
@@ -342,6 +342,10 @@
 						>
                                         </File>
                                         <File
+						RelativePath="..\..\..\boost\monotonic\extra\string.hpp"
+						>
+					</File>
+					<File
                                                 RelativePath="..\..\..\boost\monotonic\extra\vector.hpp"
 						>
                                         </File>