Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53993 - sandbox/monotonic/boost/monotonic
From: christian.schladetsch_at_[hidden]
Date: 2009-06-17 00:03:05


Author: cschladetsch
Date: 2009-06-17 00:03:04 EDT (Wed, 17 Jun 2009)
New Revision: 53993
URL: http://svn.boost.org/trac/boost/changeset/53993

Log:
reformatting, comments, simplified allocator ctors

Text files modified:
   sandbox/monotonic/boost/monotonic/allocator.h | 75 +++++++++++++++++++--------------------
   sandbox/monotonic/boost/monotonic/static_storage.h | 4 +
   2 files changed, 40 insertions(+), 39 deletions(-)

Modified: sandbox/monotonic/boost/monotonic/allocator.h
==============================================================================
--- sandbox/monotonic/boost/monotonic/allocator.h (original)
+++ sandbox/monotonic/boost/monotonic/allocator.h 2009-06-17 00:03:04 EDT (Wed, 17 Jun 2009)
@@ -16,15 +16,13 @@
 {
         namespace monotonic
         {
- /// forward declaration
+ /// a monotonic allocator always increases in size
                 template <class>
- class allocator;
+ struct allocator;
 
- /// specialization for void
                 template <>
- class allocator<void>
+ struct allocator<void>
                 {
- public:
                         typedef void* pointer;
                         typedef const void* const_pointer;
 
@@ -36,11 +34,10 @@
                         };
                 };
 
- /// a monotonic allocator always increases in size
                 template <class T>
- class allocator
+ struct allocator
                 {
- public:
+ 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;
@@ -48,8 +45,6 @@
                         typedef T &reference;
                         typedef const T &const_reference;
                         typedef T value_type;
-
- /// rebind storage to a another type
                         template <class U>
                         struct rebind
                         {
@@ -57,7 +52,6 @@
                         };
 
                 private:
- /// the storage used by the allocator
                         storage_base *storage;
 
                 public:
@@ -66,22 +60,20 @@
                         {
                         }
 
- allocator(storage_base &P) throw()
- : storage(&P)
+ allocator(storage_base &store) throw()
+ : storage(&store)
                         {
                         }
 
- allocator(const allocator& Q) throw()
- : storage(Q.storage)
+ allocator(const allocator& alloc) throw()
+ : storage(alloc.get_storage())
                         {
                         }
 
                         template <class U>
- allocator(const allocator<U> &Q) throw()
+ allocator(const allocator<U> &alloc) throw()
+ : storage(alloc.get_storage())
                         {
- typedef BOOST_DEDUCED_TYPENAME allocator<T>::template rebind<U> Other;
- typedef BOOST_DEDUCED_TYPENAME Other::other OtherStorage;
- storage = OtherStorage(*Q.get_storage()).get_storage();
                         }
 
                         ~allocator() throw()
@@ -98,16 +90,14 @@
                                 return &x;
                         }
 
- BOOST_STATIC_CONSTANT(size_t, alignment = boost::aligned_storage<sizeof(T)>::alignment);
-
                         pointer allocate(size_type num, allocator<void>::const_pointer /*hint*/ = 0)
                         {
                                 BOOST_ASSERT(num > 0);
                                 BOOST_ASSERT(storage != 0);
- return static_cast<T *>(storage->allocate(num*sizeof(T), alignment));
+ return static_cast<pointer>(storage->allocate(num*sizeof(value_type), alignment));
                         }
 
- void deallocate(pointer p, size_type n)
+ void deallocate(pointer, size_type)
                         {
                                 // do nothing
                         }
@@ -117,36 +107,36 @@
                                 if (!storage)
                                         return 0;
                                 //return storage->max_size()/(sizeof(T) + alignment);
- return storage->max_size()/sizeof(T);
+ return storage->max_size()/sizeof(value_type);
                         }
 
- void construct(pointer p)
+ void construct(pointer ptr)
                         {
- new (p) T();
+ new (ptr) value_type();
                         }
 
- void construct(pointer p, const T& val)
+ void construct(pointer ptr, const T& val)
                         {
- new (p) T(val);
+ new (ptr) value_type(val);
                         }
 
- void destroy(pointer p)
+ void destroy(pointer ptr)
                         {
- if (!p)
+ if (!ptr)
                                         return;
- destroy(p, boost::has_trivial_destructor<T>());
+ destroy(ptr, boost::has_trivial_destructor<value_type>());
                         }
 
- void destroy(pointer p, const boost::false_type& )
+ void destroy(pointer ptr, const boost::false_type& )
                         {
- (*p).~T();
+ (*ptr).~value_type();
                         }
 
                         void destroy(pointer, const boost::true_type& )
                         {
                         }
 
- void swap(allocator<T> &other)
+ void swap(allocator<value_type> &other)
                         {
                                 std::swap(storage, other.storage);
                         }
@@ -156,10 +146,19 @@
                                 return storage;
                         }
 
- friend bool operator==(allocator<T> const &A, allocator<T> const &B) { return A.storage == B.storage; }
- friend bool operator!=(allocator<T> const &A, allocator<T> const &B) { return A.storage != B.storage; }
+ friend bool operator==(allocator<T> const &A, allocator<T> const &B)
+ {
+ return A.storage == B.storage;
+ }
+
+ friend bool operator!=(allocator<T> const &A, allocator<T> const &B)
+ {
+ return A.storage != B.storage;
+ }
                 };
- }
-}
+
+ } // namespace monotonic
+
+} // namespace boost
 
 //EOF

Modified: sandbox/monotonic/boost/monotonic/static_storage.h
==============================================================================
--- sandbox/monotonic/boost/monotonic/static_storage.h (original)
+++ sandbox/monotonic/boost/monotonic/static_storage.h 2009-06-17 00:03:04 EDT (Wed, 17 Jun 2009)
@@ -23,7 +23,9 @@
                 template <size_t InlineSize, size_t MinHeapIncrement, class Al, template <size_t, size_t, class> class Storage>
                 struct static_storage_base : storage_base
                 {
- typedef Storage<InlineSize, MinHeapIncrement, Al> StorageType;
+ typedef Al HeapAllocator;
+ typedef Storage<InlineSize, MinHeapIncrement, HeapAllocator> StorageType;
+
                 private:
                         StorageType global;
 


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