|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r54723 - in sandbox/monotonic: boost/monotonic libs/monotonic/test libs/monotonic/test/Tests
From: christian.schladetsch_at_[hidden]
Date: 2009-07-06 15:51:25
Author: cschladetsch
Date: 2009-07-06 15:51:24 EDT (Mon, 06 Jul 2009)
New Revision: 54723
URL: http://svn.boost.org/trac/boost/changeset/54723
Log:
added monotonic::stack<>
Added:
sandbox/monotonic/boost/monotonic/stack.hpp (contents, props changed)
Text files modified:
sandbox/monotonic/boost/monotonic/fixed_storage.hpp | 68 +++++++++++++++++++++++++++++++++++
sandbox/monotonic/boost/monotonic/storage.hpp | 37 ++++++++++++++-----
sandbox/monotonic/libs/monotonic/test/Tests/Tests.vcproj | 76 ++++++++++++++++++++++++++++++++++++++++
sandbox/monotonic/libs/monotonic/test/Tests/tests.cpp | 34 ++++++++++++++++-
sandbox/monotonic/libs/monotonic/test/monotonic.sln | 6 +--
sandbox/monotonic/libs/monotonic/test/monotonic.vcproj | 4 ++
6 files changed, 209 insertions(+), 16 deletions(-)
Modified: sandbox/monotonic/boost/monotonic/fixed_storage.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/fixed_storage.hpp (original)
+++ sandbox/monotonic/boost/monotonic/fixed_storage.hpp 2009-07-06 15:51:24 EDT (Mon, 06 Jul 2009)
@@ -142,6 +142,74 @@
return num_allocations;
}
#endif
+ //-----------------------------------------------------------------
+
+
+ template <class Ty>
+ Ty *uninitialised_create()
+ {
+ return reinterpret_cast<Ty *>(allocate_bytes<sizeof(Ty)>());
+ }
+
+ template <class Ty>
+ void construct(Ty *ptr, const boost::true_type& /*is_pod*/)
+ {
+ // do nothing
+ }
+
+ template <class Ty>
+ void construct(Ty *ptr, const boost::false_type&)
+ {
+ new (ptr) Ty();
+ }
+
+ template <class Ty>
+ Ty &create()
+ {
+ Ty *ptr = uninitialised_create<Ty>();
+ construct(ptr, boost::is_pod<Ty>());
+ return *ptr;
+ }
+
+ template <class Ty, class A0>
+ Ty &create(A0 a0)
+ {
+ Ty *ptr = uninitialised_create<Ty>();
+ new (ptr) Ty(a0);
+ return *ptr;
+ }
+
+ template <class Ty, class A0, class A1>
+ Ty &create(A0 a0, A1 a1)
+ {
+ Ty *ptr = uninitialised_create<Ty>();
+ new (ptr) Ty(a0, a1);
+ return *ptr;
+ }
+
+ template <class Ty>
+ void destroy(Ty &object)
+ {
+ object.~Ty();
+ }
+
+ template <class Ty>
+ void destroy(Ty const &object)
+ {
+ destroy(const_cast<Ty &>(object));
+ }
+
+ template <size_t N>
+ char *allocate_bytes()
+ {
+ return allocate_bytes(N, boost::aligned_storage<N>::alignment);
+ }
+
+ char *allocate_bytes(size_t num_bytes, size_t alignment = 1)
+ {
+ return reinterpret_cast<char *>(allocate(num_bytes, alignment));
+ }
+
};
} // namespace monotonic
Added: sandbox/monotonic/boost/monotonic/stack.hpp
==============================================================================
--- (empty file)
+++ sandbox/monotonic/boost/monotonic/stack.hpp 2009-07-06 15:51:24 EDT (Mon, 06 Jul 2009)
@@ -0,0 +1,104 @@
+// 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_STACK_HPP
+#define BOOST_MONOTONIC_STACK_HPP
+
+#include <boost/monotonic/detail/prefix.hpp>
+#include <boost/monotonic/storage.hpp>
+#include <boost/monotonic/containers/vector.hpp>
+
+// warning C4345: behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized
+#pragma warning(disable:4345)
+
+namespace boost
+{
+ namespace monotonic
+ {
+ template <size_t InlineSize = DefaultSizes::InlineSize>
+ struct stack
+ {
+ typedef stack<InlineSize> this_type;
+
+ private:
+ fixed_storage<InlineSize> store;
+
+ struct element_base
+ {
+ element_base *previous;
+ size_t cursor;
+ virtual ~element_base() { }
+ };
+ template <class T>
+ struct element : element_base
+ {
+ typedef T type;
+
+ type *val;
+ char value[sizeof(T)];
+ element()
+ {
+ val = reinterpret_cast<T *>(value);
+ }
+ ~element()
+ {
+ val->~T();
+ }
+ };
+
+ element_base *previous;
+
+ public:
+ stack() : previous(0)
+ {
+ }
+
+ template <class T>
+ T &push()
+ {
+ size_t cursor = store.get_cursor();
+ element<T> &elem = store.create<element<T> >();
+ elem.previous = previous;
+ elem.cursor = cursor;
+ previous = &elem;
+ new (elem.val) T();
+ return *elem.val;
+ }
+
+ template <class T, class A0>
+ T &push(A0 a0)
+ {
+ size_t cursor = store.get_cursor();
+ element<T> &elem = store.create<element<T> >();
+ elem.previous = previous;
+ elem.cursor = cursor;
+ previous = &elem;
+ new (elem.val) T(a0);
+ return *elem.val;
+ }
+ void pop()
+ {
+ BOOST_ASSERT(previous);
+ element_base *elem = previous;
+ previous = elem->previous;
+ size_t cursor = elem->cursor;
+ elem->~element_base();
+ store.set_cursor(cursor);
+ }
+
+ size_t top() const
+ {
+ return store.get_cursor();
+ }
+ };
+ }
+}
+
+#include <boost/monotonic/detail/postfix.hpp>
+
+#endif // BOOST_MONOTONIC_STACK_HPP
+
+//EOF
+
Modified: sandbox/monotonic/boost/monotonic/storage.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/storage.hpp (original)
+++ sandbox/monotonic/boost/monotonic/storage.hpp 2009-07-06 15:51:24 EDT (Mon, 06 Jul 2009)
@@ -186,14 +186,6 @@
}
template <class Ty>
- Ty &create()
- {
- Ty *ptr = uninitialised_create<Ty>();
- construct(ptr, boost::is_pod<Ty>());
- return *ptr;
- }
-
- template <class Ty>
void construct(Ty *ptr, const boost::true_type& /*is_pod*/)
{
// do nothing
@@ -206,10 +198,26 @@
}
template <class Ty>
- Ty &create(Ty const &X)
+ Ty &create()
{
Ty *ptr = uninitialised_create<Ty>();
- new (ptr) Ty(X);
+ construct(ptr, boost::is_pod<Ty>());
+ return *ptr;
+ }
+
+ template <class Ty, class A0>
+ Ty &create(A0 a0)
+ {
+ Ty *ptr = uninitialised_create<Ty>();
+ new (ptr) Ty(a0);
+ return *ptr;
+ }
+
+ template <class Ty, class A0, class A1>
+ Ty &create(A0 a0, A1 a1)
+ {
+ Ty *ptr = uninitialised_create<Ty>();
+ new (ptr) Ty(a0, a1);
return *ptr;
}
@@ -236,6 +244,15 @@
return reinterpret_cast<char *>(allocate(num_bytes, alignment));
}
+ size_t get_cursor() const
+ {
+ return fixed.get_cursor();
+ }
+ void set_cursor(size_t n)
+ {
+ fixed.set_cursor(n);
+ }
+
private:
void AddLink(size_t size)
{
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-07-06 15:51:24 EDT (Mon, 06 Jul 2009)
@@ -174,6 +174,82 @@
Name="VCPostBuildEventTool"
/>
</Configuration>
+ <Configuration
+ Name="ReleaseSym|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="3"
+ AdditionalIncludeDirectories="$(ProjectDir)/../../../..;C:\Lib\tbb21_20080605oss\include;c:/source/boost/sandbox/cloneable;"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="0"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ AdditionalLibraryDirectories="C:\Program Files\boost\boost_1_38\lib"
+ 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"
+ ExcludedFromBuild="true"
+ />
+ </Configuration>
</Configurations>
<References>
</References>
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-07-06 15:51:24 EDT (Mon, 06 Jul 2009)
@@ -20,6 +20,7 @@
#include <boost/monotonic/allocator.hpp>
#include <boost/interprocess/containers/list.hpp>
#include <boost/monotonic/reclaimable_storage.hpp>
+#include <boost/monotonic/stack.hpp>
#include <boost/iterator.hpp>
#define BOOST_TEST_MODULE basic_test test
@@ -61,27 +62,56 @@
struct Tracked
{
static int count;
- Tracked(Tracked const &)
+ Tracked()
{
++count;
+ std::cout << "T::T(): " << count << endl;
}
- Tracked()
+ Tracked(Tracked const &)
{
++count;
+ std::cout << "T::T(T const &): " << count << endl;
}
Tracked &operator=(Tracked const &)
{
++count;
+ std::cout << "T &operator=(T const &): " << count << endl;
return *this;
}
~Tracked()
{
--count;
+ std::cout << "T::~T(): " << count << endl;
}
};
int Tracked::count = 0;
+BOOST_AUTO_TEST_CASE(test_stack)
+{
+ monotonic::stack<> stack;
+ {
+ size_t top = stack.top();
+ int &n = stack.push<int>();
+ stack.pop();
+ size_t top2 = stack.top();
+ BOOST_ASSERT(top2 == top);
+
+ int &n2 = stack.push<int>();
+ int &n3 = stack.push<int>();
+ Tracked &tracked = stack.push<Tracked>();
+ boost::array<int, 42> &a = stack.push<boost::array<int, 42> >();
+ size_t peak = stack.top();
+ stack.pop();
+ stack.pop();
+ stack.pop();
+ stack.pop();
+ top2 = stack.top();
+ BOOST_ASSERT(top2 == top);
+ BOOST_ASSERT(Tracked::count == 0);
+ }
+}
+
template <class Number>
Number work(size_t iterations, std::vector<Number> const &data)
{
Modified: sandbox/monotonic/libs/monotonic/test/monotonic.sln
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/monotonic.sln (original)
+++ sandbox/monotonic/libs/monotonic/test/monotonic.sln 2009-07-06 15:51:24 EDT (Mon, 06 Jul 2009)
@@ -21,18 +21,16 @@
{5688980A-015B-4C7D-8D8D-F5894205FACE}.Release|Win32.ActiveCfg = Release|Win32
{5688980A-015B-4C7D-8D8D-F5894205FACE}.Release|Win32.Build.0 = Release|Win32
{5688980A-015B-4C7D-8D8D-F5894205FACE}.ReleaseSym|Win32.ActiveCfg = ReleaseSym|Win32
- {5688980A-015B-4C7D-8D8D-F5894205FACE}.ReleaseSym|Win32.Build.0 = ReleaseSym|Win32
{D4779B0F-266B-46D3-8BCF-0E14EF8B817B}.Debug|Win32.ActiveCfg = Debug|Win32
{D4779B0F-266B-46D3-8BCF-0E14EF8B817B}.Debug|Win32.Build.0 = Debug|Win32
{D4779B0F-266B-46D3-8BCF-0E14EF8B817B}.Release|Win32.ActiveCfg = Release|Win32
- {D4779B0F-266B-46D3-8BCF-0E14EF8B817B}.ReleaseSym|Win32.ActiveCfg = Release|Win32
- {D4779B0F-266B-46D3-8BCF-0E14EF8B817B}.ReleaseSym|Win32.Build.0 = Release|Win32
+ {D4779B0F-266B-46D3-8BCF-0E14EF8B817B}.ReleaseSym|Win32.ActiveCfg = ReleaseSym|Win32
+ {D4779B0F-266B-46D3-8BCF-0E14EF8B817B}.ReleaseSym|Win32.Build.0 = ReleaseSym|Win32
{E557E90C-C695-4A7B-B5A6-2F133AF88563}.Debug|Win32.ActiveCfg = Debug|Win32
{E557E90C-C695-4A7B-B5A6-2F133AF88563}.Debug|Win32.Build.0 = Debug|Win32
{E557E90C-C695-4A7B-B5A6-2F133AF88563}.Release|Win32.ActiveCfg = Release|Win32
{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
{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
Modified: sandbox/monotonic/libs/monotonic/test/monotonic.vcproj
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/monotonic.vcproj (original)
+++ sandbox/monotonic/libs/monotonic/test/monotonic.vcproj 2009-07-06 15:51:24 EDT (Mon, 06 Jul 2009)
@@ -307,6 +307,10 @@
>
</File>
<File
+ RelativePath="..\..\..\boost\monotonic\stack.hpp"
+ >
+ </File>
+ <File
RelativePath="..\..\..\boost\monotonic\static_storage.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