/[pcsx2_0.9.7]/trunk/3rdparty/wxWidgets/include/wx/msw/HeapAllocator.h
ViewVC logotype

Annotation of /trunk/3rdparty/wxWidgets/include/wx/msw/HeapAllocator.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62 - (hide annotations) (download)
Tue Sep 7 11:08:22 2010 UTC (9 years, 11 months ago) by william
File MIME type: text/plain
File size: 4670 byte(s)
Auto Commited Import of: pcsx2-0.9.7-r3738-debug in ./trunk
1 william 31 #pragma once
2    
3     #include <limits>
4     #include <memory>
5    
6     extern void _createHeap_wxString();
7     extern void _destroyHeap_wxString();
8     extern void* _allocHeap_wxString( size_t size );
9     extern void* _reallocHeap_wxString( void* original, size_t size );
10     extern void _freeHeap_wxString( void* ptr );
11     extern char* _mswHeap_Strdup( const char* src );
12     extern wchar_t* _mswHeap_Strdup( const wchar_t* src );
13    
14    
15     extern void _createHeap_wxObject();
16     extern void _destroyHeap_wxObject();
17     extern void* _allocHeap_wxObject( size_t size );
18     extern void* _reallocHeap_wxObject( void* original, size_t size );
19     extern void _freeHeap_wxObject( void* ptr );
20    
21     // _pxDestroy_ uses microsoft's internal definition for _Destroy(), found in xmemory;
22     // which suppresses a warning that we otherwise get. The warning appears to be specific
23     // to MSVC, so a basic _MSC_VER define will hopefully do the trick to allow support to
24     // non-Micrsoft compilers.
25     template<class T> inline
26     void _pxDestroy_(T* _Ptr)
27     {
28     #ifdef _MSC_VER
29 william 62 std::_Destroy( _Ptr );
30 william 31 #else
31     (_Ptr)->~T();
32     #endif
33     }
34    
35     // --------------------------------------------------------------------------------------
36     // wxStringAllocator
37     // --------------------------------------------------------------------------------------
38     template<typename T>
39     class wxStringAllocator
40     {
41     public :
42     // typedefs
43    
44     typedef T value_type;
45     typedef value_type* pointer;
46     typedef const value_type* const_pointer;
47     typedef value_type& reference;
48     typedef const value_type& const_reference;
49     typedef std::size_t size_type;
50     typedef std::ptrdiff_t difference_type;
51    
52     public :
53     // convert an allocator<T> to allocator<U>
54    
55     template<typename U>
56     struct rebind {
57     typedef wxStringAllocator<U> other;
58     };
59    
60     public :
61     wxStringAllocator()
62     {
63     _createHeap_wxString();
64     }
65    
66     ~wxStringAllocator()
67     {
68     _destroyHeap_wxString();
69     }
70    
71     wxStringAllocator(wxStringAllocator const&) {}
72    
73     template<typename U>
74     explicit wxStringAllocator(wxStringAllocator<U> const&) {}
75    
76     // address
77    
78     pointer address(reference r) { return &r; }
79     const_pointer address(const_reference r) { return &r; }
80    
81     // memory allocation
82    
83     pointer allocate(size_type cnt,
84     typename std::allocator<void>::const_pointer = 0)
85     {
86     return reinterpret_cast<pointer>( _allocHeap_wxString(cnt * sizeof(T)) );
87     }
88    
89     void deallocate(pointer p, size_type)
90     {
91     _freeHeap_wxString( p );
92     }
93    
94     // size
95    
96     size_type max_size() const {
97     return std::numeric_limits<size_type>::max() / sizeof(T);
98     }
99    
100     // construction/destruction
101    
102     // standard placement-new syntax to initialize the object:
103     void construct(pointer p, const T& t) { new(p) T(t); }
104     // standard placement destructor:
105     void destroy(pointer p) { _pxDestroy_(p); }
106    
107     bool operator==(wxStringAllocator const&) { return true; }
108     bool operator!=(wxStringAllocator const& a) { return !operator==(a); }
109     }; // end of class Allocator
110    
111     // --------------------------------------------------------------------------------------
112     // wxObjectAllocator
113     // --------------------------------------------------------------------------------------
114     template<typename T>
115     class wxObjectAllocator
116     {
117     public :
118     // typedefs
119    
120     typedef T value_type;
121     typedef value_type* pointer;
122     typedef const value_type* const_pointer;
123     typedef value_type& reference;
124     typedef const value_type& const_reference;
125     typedef std::size_t size_type;
126     typedef std::ptrdiff_t difference_type;
127    
128     public :
129     // convert an allocator<T> to allocator<U>
130    
131     template<typename U>
132     struct rebind {
133     typedef wxObjectAllocator<U> other;
134     };
135    
136     public :
137     wxObjectAllocator()
138     {
139     _createHeap_wxObject();
140     }
141    
142     ~wxObjectAllocator()
143     {
144     _destroyHeap_wxObject();
145     }
146    
147     wxObjectAllocator(wxObjectAllocator const&) {}
148    
149     template<typename U>
150     explicit wxObjectAllocator(wxObjectAllocator<U> const&) {}
151    
152     // address
153    
154     pointer address(reference r) { return &r; }
155     const_pointer address(const_reference r) { return &r; }
156    
157     // memory allocation
158    
159     pointer allocate(size_type cnt,
160     typename std::allocator<void>::const_pointer = 0)
161     {
162     return reinterpret_cast<pointer>( _allocHeap_wxObject(cnt * sizeof(T)) );
163     }
164    
165     void deallocate(pointer p, size_type)
166     {
167     _freeHeap_wxObject( p );
168     }
169    
170     // size
171    
172     size_type max_size() const {
173     return std::numeric_limits<size_type>::max() / sizeof(T);
174     }
175    
176     // construction/destruction
177    
178     // standard placement-new syntax to initialize the object:
179     void construct(pointer p, const T& t) { new(p) T(t); }
180    
181     // standard placement destructor:
182     void destroy(pointer p) { _pxDestroy_(p); }
183    
184     bool operator==(wxObjectAllocator const&) { return true; }
185     bool operator!=(wxObjectAllocator const& a) { return !operator==(a); }
186     }; // end of class Allocator
187    

  ViewVC Help
Powered by ViewVC 1.1.22