00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00048 #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_ALLOCATOR_BASE
00049 #define STLSOFT_INCL_STLSOFT_MEMORY_HPP_ALLOCATOR_BASE
00050
00051 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00052 # define STLSOFT_VER_STLSOFT_MEMORY_HPP_ALLOCATOR_BASE_MAJOR 4
00053 # define STLSOFT_VER_STLSOFT_MEMORY_HPP_ALLOCATOR_BASE_MINOR 1
00054 # define STLSOFT_VER_STLSOFT_MEMORY_HPP_ALLOCATOR_BASE_REVISION 6
00055 # define STLSOFT_VER_STLSOFT_MEMORY_HPP_ALLOCATOR_BASE_EDIT 48
00056 #endif
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
00071 # include <stlsoft/stlsoft.h>
00072 #endif
00073 #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_ALLOCATOR_FEATURES
00074 # include <stlsoft/memory/allocator_features.hpp>
00075 #endif
00076 #ifdef STLSOFT_CF_ALLOCATOR_CHARALLOC_METHOD
00077 # ifndef STLSOFT_INCL_STLSOFT_CONVERSION_HPP_SAP_CAST
00078 # include <stlsoft/conversion/sap_cast.hpp>
00079 # endif
00080 #endif
00081 #if defined(STLSOFT_CF_THROW_BAD_ALLOC) || \
00082 ( defined(STLSOFT_COMPILER_IS_MSVC) && \
00083 _MSC_VER < 1100)
00084 # include <new>
00085 #endif
00086
00087
00088
00089
00090
00091 #ifndef _STLSOFT_NO_NAMESPACE
00092 namespace stlsoft
00093 {
00094 #endif
00095
00096
00097
00098
00099
00143 template< ss_typename_param_k T
00144 , ss_typename_param_k A
00145 >
00146 class allocator_base
00147 {
00150 public:
00152 typedef T value_type;
00154 typedef allocator_base<T, A> class_type;
00156 typedef value_type* pointer;
00158 typedef value_type const* const_pointer;
00160 typedef value_type& reference;
00162 typedef value_type const& const_reference;
00164 typedef ss_ptrdiff_t difference_type;
00166 typedef ss_size_t size_type;
00167 private:
00169 #ifdef STLSOFT_CF_ALLOCATOR_TYPED_DEALLOCATE_POINTER
00170 typedef pointer deallocate_pointer;
00171 #else
00172 typedef void* deallocate_pointer;
00173 #endif
00174 private:
00175 #if defined(STLSOFT_CF_COMPILER_SUPPORTS_CRTP)
00176 typedef A concrete_allocator_type;
00177 #else
00178 typedef class_type concrete_allocator_type;
00179 private:
00180 virtual void *do_allocate(size_type n, void const* hint) = 0;
00181 virtual void do_deallocate(void* pv, size_type n) = 0;
00182 virtual void do_deallocate(void* pv) = 0;
00183 #endif
00185
00188 public:
00190 size_type max_size() const stlsoft_throw_0()
00191 {
00192 return static_cast<size_type>(-1) / sizeof(value_type);
00193 }
00195
00198 public:
00202 pointer address(reference x) const stlsoft_throw_0()
00203 {
00204 return &x;
00205 }
00209 const_pointer address(const_reference x) const stlsoft_throw_0()
00210 {
00211 return &x;
00212 }
00214
00217 public:
00224 pointer allocate(size_type n, void const* hint = NULL)
00225 {
00226 void* p = static_cast<concrete_allocator_type*>(this)->do_allocate(n, hint);
00227
00228 #if !defined(STLSOFT_FORCE_ATORS_RETURN_NULL) && \
00229 ( defined(STLSOFT_FORCE_ATORS_THROW_BAD_ALLOC) || \
00230 defined(STLSOFT_CF_THROW_BAD_ALLOC))
00231 if(p == NULL)
00232 {
00233 STLSOFT_THROW_X(stlsoft_ns_qual_std(bad_alloc)());
00234 }
00235 #endif
00236
00237 return static_cast<pointer>(p);
00238 }
00239
00240 #if defined(STLSOFT_CF_ALLOCATOR_CHARALLOC_METHOD) || \
00241 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00250 char* _Charalloc(size_type n)
00251 {
00252 return sap_cast<char*>(allocate(n, NULL));
00253 }
00254 #endif
00255
00260 void deallocate(deallocate_pointer p, size_type n)
00261 {
00262 static_cast<concrete_allocator_type*>(this)->do_deallocate(p, n * sizeof(value_type));
00263 }
00264
00268 void deallocate(deallocate_pointer p)
00269 {
00270 static_cast<concrete_allocator_type*>(this)->do_deallocate(p);
00271 }
00273
00276 public:
00281 void construct(pointer p, value_type const& x)
00282 {
00283 STLSOFT_ASSERT(NULL != p);
00284
00285 new(p) value_type(x);
00286 }
00287
00291 void construct(pointer p)
00292 {
00293 STLSOFT_ASSERT(NULL != p);
00294
00295 new(p) value_type();
00296 }
00297
00301 void destroy(pointer p) stlsoft_throw_0()
00302 {
00303 STLSOFT_ASSERT(NULL != p);
00304
00305 STLSOFT_DESTROY_INSTANCE(T, value_type, p);
00306 }
00308
00311 private:
00312
00314 };
00315
00316
00317
00318 #ifndef _STLSOFT_NO_NAMESPACE
00319 }
00320 #endif
00321
00322
00323
00324 #endif
00325
00326