--- /dev/null
+// Copyright (C) 2000, 2001 Stephen Cleary\r
+//\r
+// Distributed under the Boost Software License, Version 1.0. (See\r
+// accompanying file LICENSE_1_0.txt or copy at\r
+// http://www.boost.org/LICENSE_1_0.txt)\r
+//\r
+// See http://www.boost.org for updates, documentation, and revision history.\r
+\r
+#ifndef BOOST_POOL_ALLOC_HPP\r
+#define BOOST_POOL_ALLOC_HPP\r
+\r
+// std::numeric_limits\r
+#include <boost/limits.hpp>\r
+// new, std::bad_alloc\r
+#include <new>\r
+\r
+#include <boost/pool/poolfwd.hpp>\r
+\r
+// boost::singleton_pool\r
+#include <boost/pool/singleton_pool.hpp>\r
+\r
+#include <boost/detail/workaround.hpp>\r
+\r
+// The following code will be put into Boost.Config in a later revision\r
+#if defined(_RWSTD_VER) || defined(__SGI_STL_PORT) || \\r
+ BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))\r
+ #define BOOST_NO_PROPER_STL_DEALLOCATE\r
+#endif\r
+\r
+namespace boost {\r
+\r
+struct pool_allocator_tag { };\r
+\r
+template <typename T,\r
+ typename UserAllocator,\r
+ typename Mutex,\r
+ unsigned NextSize>\r
+class pool_allocator\r
+{\r
+ public:\r
+ typedef T value_type;\r
+ typedef UserAllocator user_allocator;\r
+ typedef Mutex mutex;\r
+ BOOST_STATIC_CONSTANT(unsigned, next_size = NextSize);\r
+\r
+ typedef value_type * pointer;\r
+ typedef const value_type * const_pointer;\r
+ typedef value_type & reference;\r
+ typedef const value_type & const_reference;\r
+ typedef typename pool<UserAllocator>::size_type size_type;\r
+ typedef typename pool<UserAllocator>::difference_type difference_type;\r
+\r
+ template <typename U>\r
+ struct rebind\r
+ {\r
+ typedef pool_allocator<U, UserAllocator, Mutex, NextSize> other;\r
+ };\r
+\r
+ public:\r
+ pool_allocator() { }\r
+\r
+ // default copy constructor\r
+\r
+ // default assignment operator\r
+\r
+ // not explicit, mimicking std::allocator [20.4.1]\r
+ template <typename U>\r
+ pool_allocator(const pool_allocator<U, UserAllocator, Mutex, NextSize> &)\r
+ { }\r
+\r
+ // default destructor\r
+\r
+ static pointer address(reference r)\r
+ { return &r; }\r
+ static const_pointer address(const_reference s)\r
+ { return &s; }\r
+ static size_type max_size()\r
+ { return (std::numeric_limits<size_type>::max)(); }\r
+ static void construct(const pointer ptr, const value_type & t)\r
+ { new (ptr) T(t); }\r
+ static void destroy(const pointer ptr)\r
+ {\r
+ ptr->~T();\r
+ (void) ptr; // avoid unused variable warning\r
+ }\r
+\r
+ bool operator==(const pool_allocator &) const\r
+ { return true; }\r
+ bool operator!=(const pool_allocator &) const\r
+ { return false; }\r
+\r
+ static pointer allocate(const size_type n)\r
+ {\r
+ const pointer ret = static_cast<pointer>(\r
+ singleton_pool<pool_allocator_tag, sizeof(T), UserAllocator, Mutex,\r
+ NextSize>::ordered_malloc(n) );\r
+ if (ret == 0)\r
+ throw std::bad_alloc();\r
+ return ret;\r
+ }\r
+ static pointer allocate(const size_type n, const void * const)\r
+ { return allocate(n); }\r
+ static void deallocate(const pointer ptr, const size_type n)\r
+ {\r
+#ifdef BOOST_NO_PROPER_STL_DEALLOCATE\r
+ if (ptr == 0 || n == 0)\r
+ return;\r
+#endif\r
+ singleton_pool<pool_allocator_tag, sizeof(T), UserAllocator, Mutex,\r
+ NextSize>::ordered_free(ptr, n);\r
+ }\r
+};\r
+\r
+struct fast_pool_allocator_tag { };\r
+\r
+template <typename T,\r
+ typename UserAllocator,\r
+ typename Mutex,\r
+ unsigned NextSize>\r
+class fast_pool_allocator\r
+{\r
+ public:\r
+ typedef T value_type;\r
+ typedef UserAllocator user_allocator;\r
+ typedef Mutex mutex;\r
+ BOOST_STATIC_CONSTANT(unsigned, next_size = NextSize);\r
+\r
+ typedef value_type * pointer;\r
+ typedef const value_type * const_pointer;\r
+ typedef value_type & reference;\r
+ typedef const value_type & const_reference;\r
+ typedef typename pool<UserAllocator>::size_type size_type;\r
+ typedef typename pool<UserAllocator>::difference_type difference_type;\r
+\r
+ template <typename U>\r
+ struct rebind\r
+ {\r
+ typedef fast_pool_allocator<U, UserAllocator, Mutex, NextSize> other;\r
+ };\r
+\r
+ public:\r
+ fast_pool_allocator() { }\r
+\r
+ // default copy constructor\r
+\r
+ // default assignment operator\r
+\r
+ // not explicit, mimicking std::allocator [20.4.1]\r
+ template <typename U>\r
+ fast_pool_allocator(\r
+ const fast_pool_allocator<U, UserAllocator, Mutex, NextSize> &)\r
+ { }\r
+\r
+ // default destructor\r
+\r
+ static pointer address(reference r)\r
+ { return &r; }\r
+ static const_pointer address(const_reference s)\r
+ { return &s; }\r
+ static size_type max_size()\r
+ { return (std::numeric_limits<size_type>::max)(); }\r
+ void construct(const pointer ptr, const value_type & t)\r
+ { new (ptr) T(t); }\r
+ void destroy(const pointer ptr)\r
+ {\r
+ ptr->~T();\r
+ (void) ptr; // avoid unused variable warning\r
+ }\r
+\r
+ bool operator==(const fast_pool_allocator &) const\r
+ { return true; }\r
+ bool operator!=(const fast_pool_allocator &) const\r
+ { return false; }\r
+\r
+ static pointer allocate(const size_type n)\r
+ {\r
+ const pointer ret = (n == 1) ? \r
+ static_cast<pointer>(\r
+ singleton_pool<fast_pool_allocator_tag, sizeof(T),\r
+ UserAllocator, Mutex, NextSize>::malloc() ) :\r
+ static_cast<pointer>(\r
+ singleton_pool<fast_pool_allocator_tag, sizeof(T),\r
+ UserAllocator, Mutex, NextSize>::ordered_malloc(n) );\r
+ if (ret == 0)\r
+ throw std::bad_alloc();\r
+ return ret;\r
+ }\r
+ static pointer allocate(const size_type n, const void * const)\r
+ { return allocate(n); }\r
+ static pointer allocate()\r
+ {\r
+ const pointer ret = static_cast<pointer>(\r
+ singleton_pool<fast_pool_allocator_tag, sizeof(T),\r
+ UserAllocator, Mutex, NextSize>::malloc() );\r
+ if (ret == 0)\r
+ throw std::bad_alloc();\r
+ return ret;\r
+ }\r
+ static void deallocate(const pointer ptr, const size_type n)\r
+ {\r
+#ifdef BOOST_NO_PROPER_STL_DEALLOCATE\r
+ if (ptr == 0 || n == 0)\r
+ return;\r
+#endif\r
+ if (n == 1)\r
+ singleton_pool<fast_pool_allocator_tag, sizeof(T),\r
+ UserAllocator, Mutex, NextSize>::free(ptr);\r
+ else\r
+ singleton_pool<fast_pool_allocator_tag, sizeof(T),\r
+ UserAllocator, Mutex, NextSize>::free(ptr, n);\r
+ }\r
+ static void deallocate(const pointer ptr)\r
+ {\r
+ singleton_pool<fast_pool_allocator_tag, sizeof(T),\r
+ UserAllocator, Mutex, NextSize>::free(ptr);\r
+ }\r
+};\r
+\r
+} // namespace boost\r
+\r
+#endif\r