00001 #ifndef __LDK_STLALLOCATOR_H__
00002 #define __LDK_STLALLOCATOR_H__
00003
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00028
00035
00036 namespace LDK
00037 {
00047 template<class T>
00048 class Allocator
00049 {
00050 public:
00051 typedef size_t size_type;
00052 typedef ptrdiff_t difference_type;
00053 typedef T* pointer;
00054 typedef const T* const_pointer;
00055 typedef T& reference;
00056 typedef const T& const_reference;
00057 typedef T value_type;
00058
00059 template<typename T1>
00060 struct rebind
00061 {
00062 typedef Allocator<T1> other;
00063 };
00064
00065 inline Allocator() throw() {}
00066 inline Allocator(const Allocator&) {}
00067 template<typename T1>
00068 inline Allocator(const Allocator<T1>&) {}
00069 inline ~Allocator() {}
00070
00071 inline pointer address(reference r) const { return &r; }
00072
00073 inline const_pointer address(const_reference r) const { return &r; }
00074
00075
00076 inline pointer allocate(size_type n, const void* = 0)
00077 {
00078 assert(n);
00079 return reinterpret_cast<pointer>(LDK_RTALLOC(n*sizeof(value_type)));
00080 }
00081
00082
00083 template <size_type n>
00084 inline pointer allocate()
00085 {
00086 CTASSERT(n>0,allocatorInvalidObjectCount);
00087 return reinterpret_cast<pointer>(LDK_CTALLOC(n*sizeof(value_type)));
00088 }
00089
00090 inline pointer reallocate(pointer mem, size_type newNo)
00091 {
00092 assert(mem);
00093 assert(newNo);
00094 return reinterpret_cast<pointer>(LDK_REALLOC(mem,newNo*sizeof(value_type)));
00095 }
00096
00097
00098 inline char* _Charalloc(size_type n, const void* = 0)
00099 {
00100 assert(n);
00101 return reinterpret_cast<char*>(LDK_RTALLOC(n));
00102 }
00103
00104 inline void deallocate(void* p, size_type n)
00105 {
00106 LDK::dealloc(p);
00107 }
00108
00109 inline size_type max_size() const { return size_type(-1) / sizeof(value_type); }
00110
00111 inline void construct(pointer p, const value_type& val) { new(p) value_type(val); }
00112 inline void destroy(pointer p) { p->~T(); }
00113 };
00114 template<typename T1, typename T2>
00115 inline bool operator==(const Allocator<T1>&, const Allocator<T2>&) { return true; }
00116
00117 template<typename T1, typename T2>
00118 inline bool operator!=(const Allocator<T1>&, const Allocator<T2>&) { return false; }
00119
00120 }
00121
00122 #endif //__LDK_STLALLOCATOR_H__
00123