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_PROCESSHEAP_ALLOCATOR
00048 #define WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR
00049
00050 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00051 # define WINSTL_VER_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR_MAJOR 4
00052 # define WINSTL_VER_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR_MINOR 1
00053 # define WINSTL_VER_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR_REVISION 3
00054 # define WINSTL_VER_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR_EDIT 83
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 processheap_allocator
00110 : public allocator_base<T, processheap_allocator<T> >
00111 {
00112 private:
00113 typedef allocator_base<T, processheap_allocator<T> > parent_class_type;
00114 public:
00116 typedef processheap_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 processheap_allocator<U> other;
00139 };
00140 #endif
00141
00144 public:
00146 processheap_allocator() stlsoft_throw_0()
00147 : m_processheap(::GetProcessHeap())
00148 {}
00150 #ifdef STLSOFT_CF_ALLOCATOR_REBIND_SUPPORT
00151 template <ss_typename_param_k U>
00152 processheap_allocator(processheap_allocator<U> const& ) stlsoft_throw_0()
00153 : m_processheap(::GetProcessHeap())
00154 {}
00155 #else
00156 processheap_allocator(processheap_allocator const& ) stlsoft_throw_0()
00157 : m_processheap(::GetProcessHeap())
00158 {}
00159 #endif
00161 ~processheap_allocator() stlsoft_throw_0()
00162 {}
00163
00167 class_type& operator =(class_type const& )
00168 {
00169 return *this;
00170 }
00172
00173 private:
00174 friend class allocator_base<T, processheap_allocator<T> >;
00175
00176 void* do_allocate(size_type n, void const* hint)
00177 {
00178 STLSOFT_SUPPRESS_UNUSED(hint);
00179
00180 return ::HeapAlloc(m_processheap, 0, n * sizeof(value_type));
00181 }
00182 void do_deallocate(void* pv, size_type n)
00183 {
00184 STLSOFT_SUPPRESS_UNUSED(n);
00185
00186 ::HeapFree(m_processheap, 0, pv);
00187 }
00188 void do_deallocate(void* pv)
00189 {
00190 ::HeapFree(m_processheap, 0, pv);
00191 }
00192
00193
00194 private:
00195 HANDLE m_processheap;
00196 };
00197
00198
00199
00200 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00201
00202
00203 STLSOFT_TEMPLATE_SPECIALISATION
00204 class processheap_allocator<void>
00205 {
00206 public:
00207 typedef void value_type;
00208 typedef processheap_allocator<void> class_type;
00209 typedef void* pointer;
00210 typedef void const* const_pointer;
00211 typedef ws_ptrdiff_t difference_type;
00212 typedef ws_size_t size_type;
00213
00214 #ifdef STLSOFT_CF_ALLOCATOR_REBIND_SUPPORT
00216 template <ss_typename_param_k U>
00217 struct rebind
00218 {
00219 typedef processheap_allocator<U> other;
00220 };
00221 #endif
00222 };
00223
00224 #endif
00225
00226 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00227
00228 template <ss_typename_param_k T>
00229 inline ws_bool_t operator ==(processheap_allocator<T> const& , processheap_allocator<T> const& )
00230 {
00231 return ws_true_v;
00232 }
00233
00234 template <ss_typename_param_k T>
00235 inline ws_bool_t operator !=(processheap_allocator<T> const& , processheap_allocator<T> const& )
00236 {
00237 return ws_false_v;
00238 }
00239
00240 #endif
00241
00243
00244
00245 #ifdef STLSOFT_UNITTEST
00246 # include "./unittest/processheap_allocator_unittest_.h"
00247 #endif
00248
00249
00250
00251 #ifndef _WINSTL_NO_NAMESPACE
00252 # if defined(_STLSOFT_NO_NAMESPACE) || \
00253 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00254 }
00255 # else
00256 }
00257 }
00258 # endif
00259 #endif
00260
00261
00262
00263 #endif
00264
00265