|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r54039 - in sandbox/monotonic: boost/monotonic libs/monotonic/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-17 20:17:18
Author: cschladetsch
Date: 2009-06-17 20:17:17 EDT (Wed, 17 Jun 2009)
New Revision: 54039
URL: http://svn.boost.org/trac/boost/changeset/54039
Log:
renamed detail::Creator to detail::Create
Added:
sandbox/monotonic/boost/monotonic/allocator_base.hpp (contents, props changed)
Text files modified:
sandbox/monotonic/boost/monotonic/allocator.hpp | 195 +--------------------------------------
sandbox/monotonic/boost/monotonic/forward_declarations.hpp | 4
sandbox/monotonic/boost/monotonic/map.hpp | 4
sandbox/monotonic/boost/monotonic/shared_allocator.hpp | 23 +---
sandbox/monotonic/boost/monotonic/vector.hpp | 2
sandbox/monotonic/libs/monotonic/test/main.cpp | 1
sandbox/monotonic/libs/monotonic/test/monotonic.vcproj | 4
7 files changed, 29 insertions(+), 204 deletions(-)
Modified: sandbox/monotonic/boost/monotonic/allocator.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/allocator.hpp (original)
+++ sandbox/monotonic/boost/monotonic/allocator.hpp 2009-06-17 20:17:17 EDT (Wed, 17 Jun 2009)
@@ -6,12 +6,7 @@
#ifndef BOOST_MONOTONIC_ALLOCATOR_H
#define BOOST_MONOTONIC_ALLOCATOR_H
-#include <boost/assert.hpp>
-#include <boost/type_traits/has_trivial_constructor.hpp>
-#include <boost/type_traits/has_trivial_destructor.hpp>
-
-#include <boost/monotonic/static_storage.hpp>
-#include <boost/monotonic/container.hpp>
+#include <boost/monotonic/allocator_base.hpp>
namespace boost
{
@@ -31,172 +26,6 @@
};
};
- namespace detail
- {
- template <bool is_mono_container>
- struct Construct
- {
- template <class T, class Alloc>
- static void Given(T *ptr, Alloc *allocator)
- {
- new (ptr) T();
- }
- template <class T, class Alloc>
- static void Given(T *ptr, T const &val, Alloc *allocator)
- {
- new (ptr) T(val);
- }
- };
- template <>
- struct Construct<true>
- {
- template <class T, class Alloc>
- static void Given(T *ptr, Alloc *allocator)
- {
- new (ptr) T(*allocator);
- }
- template <class T, class Alloc>
- static void Given(T *ptr, T const &val, Alloc *allocator)
- {
- // unfortunately, there is no requirement for a container to
- // have a copy-ctor that also passes an allocator.
- new (ptr) T(*allocator);
- *ptr = val;
- }
- };
-
- template <bool is_monotonic_container, class T>
- struct Creator
- {
- static T Create(storage_base &)
- {
- return T();
- }
- };
- template <class T>
- struct Creator<true, T>
- {
- static T Create(storage_base &storage)
- {
- return T(storage);
- }
- };
- }
-
- template <class T, class Derived>
- struct allocator_base
- {
- BOOST_STATIC_CONSTANT(size_t, alignment = boost::aligned_storage<sizeof(T)>::alignment);
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
- typedef T *pointer;
- typedef const T *const_pointer;
- typedef T &reference;
- typedef const T &const_reference;
- typedef T value_type;
-
-
- private:
- storage_base *storage;
-
- public:
- allocator_base() throw()
- : storage(&static_storage)
- {
- }
-
- allocator_base(storage_base &store) throw()
- : storage(&store)
- {
- }
-
- allocator_base(const allocator_base& alloc) throw()
- : storage(alloc.get_storage())
- {
- }
-
- template <class U, class D>
- allocator_base(const allocator_base<U,D> &alloc) throw()
- : storage(alloc.get_storage())
- {
- }
-
- pointer address(reference x) const
- {
- return &x;
- }
-
- const_pointer address(const_reference x) const
- {
- return &x;
- }
-
- pointer allocate(size_type num, allocator<void>::const_pointer /*hint*/ = 0)
- {
- BOOST_ASSERT(num > 0);
- BOOST_ASSERT(storage != 0);
- return static_cast<pointer>(storage->allocate(num*sizeof(value_type), alignment));
- }
-
- void deallocate(pointer, size_type)
- {
- // do nothing
- }
-
- size_type max_size() const throw()
- {
- if (!storage)
- return 0;
- //return storage->max_size()/(sizeof(T) + alignment);
- return storage->max_size()/sizeof(value_type);
- }
-
- void construct(pointer ptr)
- {
- detail::Construct<detail::is_monotonic<T>::value>::Given(ptr, static_cast<Derived *>(this));
- }
-
- void construct(pointer ptr, const T& val)
- {
- detail::Construct<detail::is_monotonic<T>::value>::Given(ptr, val, static_cast<Derived *>(this));
- }
-
- void destroy(pointer ptr)
- {
- if (!ptr)
- return;
- destroy(ptr, boost::has_trivial_destructor<value_type>());
- }
-
- void destroy(pointer ptr, const boost::false_type& )
- {
- (*ptr).~value_type();
- }
-
- void destroy(pointer, const boost::true_type& )
- {
- }
-
- void swap(allocator<value_type> &other)
- {
- std::swap(storage, other.storage);
- }
-
- storage_base *get_storage() const
- {
- return storage;
- }
- friend bool operator==(allocator_base<T,Derived> const &A, allocator_base<T,Derived> const &B)
- {
- return A.storage == B.storage;
- }
-
- friend bool operator!=(allocator_base<T,Derived> const &A, allocator_base<T,Derived> const &B)
- {
- return A.storage != B.storage;
- }
- };
-
template <class T>
struct allocator : allocator_base<T, allocator<T> >
{
@@ -214,34 +43,28 @@
{
typedef allocator<U> other;
};
+
allocator() throw()
- : Parent(static_storage)
- {
- }
+ : Parent(static_storage) { }
allocator(storage_base &store) throw()
- : Parent(store)
- {
- }
+ : Parent(store) { }
allocator(const allocator& alloc) throw()
- : Parent(alloc)
- {
- }
+ : Parent(alloc) { }
template <class U>
allocator(const allocator<U> &alloc) throw()
- : Parent(alloc)
- {
- }
+ : Parent(alloc) { }
+
friend bool operator==(allocator<T> const &A, allocator<T> const &B)
{
- return operator==(static_cast<Parent const &>(A), static_cast<Parent const &>(B));
+ return static_cast<Parent const &>(A) == static_cast<Parent const &>(B);
}
friend bool operator!=(allocator<T> const &A, allocator<T> const &B)
{
- return operator!=(static_cast<Parent const &>(A), static_cast<Parent const &>(B));
+ return static_cast<Parent const &>(A) != static_cast<Parent const &>(B);
}
};
Added: sandbox/monotonic/boost/monotonic/allocator_base.hpp
==============================================================================
--- (empty file)
+++ sandbox/monotonic/boost/monotonic/allocator_base.hpp 2009-06-17 20:17:17 EDT (Wed, 17 Jun 2009)
@@ -0,0 +1,185 @@
+// 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_ALLOCATOR_BASE_HPP
+#define BOOST_MONOTONIC_ALLOCATOR_BASE_HPP
+
+#include <boost/assert.hpp>
+#include <boost/type_traits/has_trivial_constructor.hpp>
+#include <boost/type_traits/has_trivial_destructor.hpp>
+
+#include <boost/monotonic/static_storage.hpp>
+#include <boost/monotonic/container.hpp>
+
+namespace boost
+{
+ namespace monotonic
+ {
+ namespace detail
+ {
+ template <bool is_mono_container>
+ struct Construct
+ {
+ template <class T, class Alloc>
+ static void Given(T *ptr, Alloc *allocator)
+ {
+ new (ptr) T();
+ }
+ template <class T, class Alloc>
+ static void Given(T *ptr, T const &val, Alloc *allocator)
+ {
+ new (ptr) T(val);
+ }
+ };
+ template <>
+ struct Construct<true>
+ {
+ template <class T, class Alloc>
+ static void Given(T *ptr, Alloc *allocator)
+ {
+ new (ptr) T(*allocator);
+ }
+ template <class T, class Alloc>
+ static void Given(T *ptr, T const &val, Alloc *allocator)
+ {
+ // unfortunately, there is no requirement for a container to
+ // have a copy-ctor that also passes an allocator.
+ new (ptr) T(*allocator);
+ *ptr = val;
+ }
+ };
+
+ template <bool is_monotonic_container, class T>
+ struct Create
+ {
+ static T Given(storage_base &)
+ {
+ return T();
+ }
+ };
+ template <class T>
+ struct Create<true, T>
+ {
+ static T Given(storage_base &storage)
+ {
+ return T(storage);
+ }
+ };
+ }
+
+ /// common to other monotonic allocators for type T of type Derived
+ template <class T, class Derived>
+ struct allocator_base
+ {
+ BOOST_STATIC_CONSTANT(size_t, alignment = boost::aligned_storage<sizeof(T)>::alignment);
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef T *pointer;
+ typedef const T *const_pointer;
+ typedef T &reference;
+ typedef const T &const_reference;
+ typedef T value_type;
+
+ private:
+ storage_base *storage;
+
+ public:
+ allocator_base() throw()
+ : storage(&static_storage) { }
+
+ allocator_base(storage_base &store) throw()
+ : storage(&store) { }
+
+ allocator_base(const allocator_base& alloc) throw()
+ : storage(alloc.get_storage()) { }
+
+ template <class U, class D>
+ allocator_base(const allocator_base<U,D> &alloc) throw()
+ : storage(alloc.get_storage()) { }
+
+ pointer address(reference x) const
+ {
+ return &x;
+ }
+
+ const_pointer address(const_reference x) const
+ {
+ return &x;
+ }
+
+ pointer allocate(size_type num, allocator<void>::const_pointer /*hint*/ = 0)
+ {
+ BOOST_ASSERT(num > 0);
+ BOOST_ASSERT(storage != 0);
+ return static_cast<pointer>(storage->allocate(num*sizeof(value_type), alignment));
+ }
+
+ void deallocate(pointer, size_type)
+ {
+ // do nothing
+ }
+
+ size_type max_size() const throw()
+ {
+ if (!storage)
+ return 0;
+ //return storage->max_size()/(sizeof(T) + alignment);
+ return storage->max_size()/sizeof(value_type);
+ }
+
+ void construct(pointer ptr)
+ {
+ detail::Construct<detail::is_monotonic<T>::value>::Given(ptr, static_cast<Derived *>(this));
+ }
+
+ void construct(pointer ptr, const T& val)
+ {
+ detail::Construct<detail::is_monotonic<T>::value>::Given(ptr, val, static_cast<Derived *>(this));
+ }
+
+ void destroy(pointer ptr)
+ {
+ if (!ptr)
+ return;
+ destroy(ptr, boost::has_trivial_destructor<value_type>());
+ }
+
+ void destroy(pointer ptr, const boost::false_type& )
+ {
+ (*ptr).~value_type();
+ }
+
+ void destroy(pointer, const boost::true_type& )
+ {
+ }
+
+ void swap(allocator<value_type> &other)
+ {
+ std::swap(storage, other.storage);
+ }
+
+ storage_base *get_storage() const
+ {
+ return storage;
+ }
+
+ friend bool operator==(allocator_base<T,Derived> const &A, allocator_base<T,Derived> const &B)
+ {
+ return A.storage == B.storage;
+ }
+
+ friend bool operator!=(allocator_base<T,Derived> const &A, allocator_base<T,Derived> const &B)
+ {
+ return A.storage != B.storage;
+ }
+ };
+
+ } // namespace monotonic
+
+} // namespace boost
+
+#endif // BOOST_MONOTONIC_ALLOCATOR_BASE_HPP
+
+//EOF
Modified: sandbox/monotonic/boost/monotonic/forward_declarations.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/forward_declarations.hpp (original)
+++ sandbox/monotonic/boost/monotonic/forward_declarations.hpp 2009-06-17 20:17:17 EDT (Wed, 17 Jun 2009)
@@ -47,6 +47,10 @@
>
struct static_storage_base;
+ /// common to other monotonic allocators for type T of type Derived
+ template <class T, class Derived>
+ struct allocator_base;
+
/// a monotonic allocator has a storage buffer and a no-op deallocate() method
/// default to use static_storage_base<..., storage>
template <class>
Modified: sandbox/monotonic/boost/monotonic/map.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/map.hpp (original)
+++ sandbox/monotonic/boost/monotonic/map.hpp 2009-06-17 20:17:17 EDT (Wed, 17 Jun 2009)
@@ -19,7 +19,7 @@
struct map : detail::monotonic_container<map<K,T,P> >
{
typedef detail::monotonic_container<map<K,T,P> > Parent;
- typedef detail::Creator<detail::is_monotonic<T>::value, T> Creator;
+ typedef detail::Create<detail::is_monotonic<T>::value, T> Create;
typedef P Predicate;
typedef allocator<K> Allocator;
@@ -103,7 +103,7 @@
iterator where = impl.lower_bound(key);
if (where == impl.end() || pred(key, where->first))
{
- where = impl.insert(where, value_type(key, Creator::Create(this->Parent::get_storage())));
+ where = impl.insert(where, value_type(key, Create::Given(this->Parent::get_storage())));
}
return where->second;
}
Modified: sandbox/monotonic/boost/monotonic/shared_allocator.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/shared_allocator.hpp (original)
+++ sandbox/monotonic/boost/monotonic/shared_allocator.hpp 2009-06-17 20:17:17 EDT (Wed, 17 Jun 2009)
@@ -6,7 +6,7 @@
#ifndef BOOST_MONOTONIC_SHARED_ALLOCATOR_H
#define BOOST_MONOTONIC_SHARED_ALLOCATOR_H
-#include <boost/monotonic/allocator.hpp>
+#include <boost/monotonic/allocator_base.hpp>
namespace boost
{
@@ -48,33 +48,26 @@
};
shared_allocator() throw()
- : Parent(static_shared_storage)
- {
- }
+ : Parent(static_shared_storage) { }
shared_allocator(shared_storage_base &store) throw()
- : Parent(store)
- {
- }
+ : Parent(store) { }
shared_allocator(const shared_allocator& alloc) throw()
- : Parent(alloc)
- {
- }
+ : Parent(alloc) { }
template <class U>
shared_allocator(const shared_allocator<U> &alloc) throw()
- : Parent(alloc)
- {
- }
+ : Parent(alloc) { }
+
friend bool operator==(shared_allocator<T> const &A, shared_allocator<T> const &B)
{
- return operator==(static_cast<Parent const &>(A), static_cast<Parent const &>(B));
+ return static_cast<Parent const &>(A) == static_cast<Parent const &>(B);
}
friend bool operator!=(shared_allocator<T> const &A, shared_allocator<T> const &B)
{
- return operator!=(static_cast<Parent const &>(A), static_cast<Parent const &>(B));
+ return static_cast<Parent const &>(A) == static_cast<Parent const &>(B);
}
};
Modified: sandbox/monotonic/boost/monotonic/vector.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/vector.hpp (original)
+++ sandbox/monotonic/boost/monotonic/vector.hpp 2009-06-17 20:17:17 EDT (Wed, 17 Jun 2009)
@@ -18,7 +18,7 @@
struct vector : detail::monotonic_container<vector<T> >
{
typedef detail::monotonic_container<std::vector<T, allocator<T> > > Parent;
- typedef detail::Creator<detail::is_monotonic<T>::value, T> Creator;
+ 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;
Modified: sandbox/monotonic/libs/monotonic/test/main.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/main.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/main.cpp 2009-06-17 20:17:17 EDT (Wed, 17 Jun 2009)
@@ -5,6 +5,7 @@
// the sandbox is at https://svn.boost.org/svn/boost/sandbox/monotonic/
+// commented-out till i add the correct libs for boost::mutex
//#include <boost/monotonic/shared_storage.hpp>
//#include <boost/monotonic/shared_allocator.hpp>
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-17 20:17:17 EDT (Wed, 17 Jun 2009)
@@ -180,6 +180,10 @@
>
</File>
<File
+ RelativePath="..\..\..\boost\monotonic\allocator_base.hpp"
+ >
+ </File>
+ <File
RelativePath="..\..\..\boost\monotonic\chain.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