Merge branch 'db/rev'
[plumiferos.git] / intern / memutil / MEM_Allocator.h
blob68712e45558dcdb330d5579e4b6f1c06fd7fe62d
1 /**
3 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version. The Blender
9 * Foundation also sells licenses for use in proprietary software under
10 * the Blender License. See http://www.blender.org/BL/ for information
11 * about this.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * Contributor(s): Peter Schlaile <peter@schlaile.de> 2005
24 * ***** END GPL/BL DUAL LICENSE BLOCK *****
27 #ifndef __MEM_Allocator_h_included__
28 #define __MEM_Allocator_h_included__ 1
30 #include "guardedalloc/MEM_guardedalloc.h"
32 #ifdef _MSC_VER
33 #if _MSC_VER < 1300 // 1200 == VC++ 6.0 according to boost
34 #define MS_VISUALC_6_0_WORKAROUND 1
35 #endif
36 #endif
38 template<typename _Tp>
39 struct MEM_Allocator
41 typedef size_t size_type;
42 typedef ptrdiff_t difference_type;
43 typedef _Tp* pointer;
44 typedef const _Tp* const_pointer;
45 typedef _Tp& reference;
46 typedef const _Tp& const_reference;
47 typedef _Tp value_type;
49 #ifndef MS_VISUALC_6_0_WORKAROUND
50 template<typename _Tp1>
51 struct rebind {
52 typedef MEM_Allocator<_Tp1> other;
54 #endif
56 MEM_Allocator() throw() {}
57 MEM_Allocator(const MEM_Allocator&) throw() {}
59 #ifndef MS_VISUALC_6_0_WORKAROUND
60 template<typename _Tp1>
61 MEM_Allocator(const MEM_Allocator<_Tp1>) throw() { }
62 #endif
64 ~MEM_Allocator() throw() {}
66 pointer address(reference __x) const { return &__x; }
68 const_pointer address(const_reference __x) const { return &__x; }
70 #ifdef MS_VISUALC_6_0_WORKAROUND
71 char *_Charalloc(size_type n) {
72 return (char *) MEM_mallocN(n, "STL MEM_Allocator VC6.0");
74 #endif
75 // NB: __n is permitted to be 0. The C++ standard says nothing
76 // about what the return value is when __n == 0.
77 _Tp* allocate(size_type __n, const void* = 0) {
78 _Tp* __ret = 0;
79 if (__n)
80 __ret = static_cast<_Tp*>(
81 MEM_mallocN(__n * sizeof(_Tp),
82 "STL MEM_Allocator"));
83 return __ret;
86 #ifndef MS_VISUALC_6_0_WORKAROUND
87 // __p is not permitted to be a null pointer.
88 void deallocate(pointer __p, size_type){
89 MEM_freeN(__p);
91 #else
92 // __p is not permitted to be a null pointer.
93 void deallocate(void* __p, size_type){
94 MEM_freeN(__p);
96 #endif
98 size_type max_size() const throw() {
99 return size_t(-1) / sizeof(_Tp);
102 void construct(pointer __p, const _Tp& __val) {
103 new(__p) _Tp(__val);
106 void destroy(pointer __p) {
107 __p->~_Tp();
111 #endif