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
00047 #ifndef WINSTL_INCL_WINSTL_MEMORY_HPP_GLOBAL_ALLOCATOR
00048 #define WINSTL_INCL_WINSTL_MEMORY_HPP_GLOBAL_ALLOCATOR
00049
00050 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00051 # define WINSTL_VER_WINSTL_MEMORY_HPP_GLOBAL_ALLOCATOR_MAJOR 4
00052 # define WINSTL_VER_WINSTL_MEMORY_HPP_GLOBAL_ALLOCATOR_MINOR 1
00053 # define WINSTL_VER_WINSTL_MEMORY_HPP_GLOBAL_ALLOCATOR_REVISION 2
00054 # define WINSTL_VER_WINSTL_MEMORY_HPP_GLOBAL_ALLOCATOR_EDIT 77
00055 #endif
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #ifndef WINSTL_INCL_WINSTL_H_WINSTL
00070 # include <winstl/winstl.h>
00071 #endif
00072 #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_ALLOCATOR_BASE
00073 # include <stlsoft/memory/allocator_base.hpp>
00074 #endif
00075
00076
00077
00078
00079
00080 #ifndef _WINSTL_NO_NAMESPACE
00081 # if defined(_STLSOFT_NO_NAMESPACE) || \
00082 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00083
00084 namespace winstl
00085 {
00086 # else
00087
00088
00089 namespace stlsoft
00090 {
00091
00092 namespace winstl_project
00093 {
00094
00095 # endif
00096 #endif
00097
00098
00099
00100
00101
00108 template <ss_typename_param_k T>
00109 class global_allocator
00110 : public allocator_base<T, global_allocator<T> >
00111 {
00112 private:
00113 typedef allocator_base<T, global_allocator<T> > parent_class_type;
00114 public:
00116 typedef global_allocator<T> class_type;
00118 typedef ss_typename_type_k parent_class_type::value_type value_type;
00120 typedef ss_typename_type_k parent_class_type::pointer pointer;
00122 typedef ss_typename_type_k parent_class_type::const_pointer const_pointer;
00124 typedef ss_typename_type_k parent_class_type::reference reference;
00126 typedef ss_typename_type_k parent_class_type::const_reference const_reference;
00128 typedef ss_typename_type_k parent_class_type::difference_type difference_type;
00130 typedef ss_typename_type_k parent_class_type::size_type size_type;
00131
00132 public:
00133 #ifdef STLSOFT_CF_ALLOCATOR_REBIND_SUPPORT
00135 template <ss_typename_param_k U>
00136 struct rebind
00137 {
00138 typedef global_allocator<U> other;
00139 };
00140 #endif
00141
00144 public:
00146 global_allocator()
00147 {}
00149 #ifdef STLSOFT_CF_ALLOCATOR_REBIND_SUPPORT
00150 template <ss_typename_param_k U>
00151 global_allocator(global_allocator<U> const&)
00152 {}
00153 #else
00154 global_allocator(class_type const&)
00155 {}
00156 #endif
00158
00159 private:
00160 friend class allocator_base<T, global_allocator<T> >;
00161
00162 void *do_allocate(size_type n, void const* hint)
00163 {
00164 STLSOFT_SUPPRESS_UNUSED(hint);
00165
00166 return static_cast<void*>(::GlobalAlloc(GMEM_FIXED, n * sizeof(value_type)));
00167 }
00168 void do_deallocate(void *pv, size_type n)
00169 {
00170 STLSOFT_SUPPRESS_UNUSED(n);
00171
00172 ::GlobalFree(static_cast<HGLOBAL>(pv));
00173 }
00174 void do_deallocate(void *pv)
00175 {
00176 ::GlobalFree(static_cast<HGLOBAL>(pv));
00177 }
00178 };
00179
00180
00181
00182 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00183
00184
00185 STLSOFT_TEMPLATE_SPECIALISATION
00186 class global_allocator<void>
00187 {
00188 public:
00189 typedef void value_type;
00190 typedef global_allocator<void> class_type;
00191 typedef void* pointer;
00192 typedef void const* const_pointer;
00193 typedef ws_ptrdiff_t difference_type;
00194 typedef ws_size_t size_type;
00195
00196 #ifdef STLSOFT_CF_ALLOCATOR_REBIND_SUPPORT
00198 template <ss_typename_param_k U>
00199 struct rebind
00200 {
00201 typedef global_allocator<U> other;
00202 };
00203 #endif
00204 };
00205
00206 #endif
00207
00208 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00209
00210 template <ss_typename_param_k T>
00211 inline ws_bool_t operator ==(const global_allocator<T> &, const global_allocator<T> &)
00212 {
00213 return ws_true_v;
00214 }
00215
00216 template <ss_typename_param_k T>
00217 inline ws_bool_t operator !=(const global_allocator<T> &, const global_allocator<T> &)
00218 {
00219 return ws_false_v;
00220 }
00221
00222 #endif
00223
00225
00226
00227 #ifdef STLSOFT_UNITTEST
00228 # include "./unittest/global_allocator_unittest_.h"
00229 #endif
00230
00231
00232
00233 #ifndef _WINSTL_NO_NAMESPACE
00234 # if defined(_STLSOFT_NO_NAMESPACE) || \
00235 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00236 }
00237 # else
00238 }
00239 }
00240 # endif
00241 #endif
00242
00243
00244
00245 #endif
00246
00247