00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef INCLUDED_RTL_ALLOCATOR_HXX
00020 #define INCLUDED_RTL_ALLOCATOR_HXX
00021
00022 #include "sal/types.h"
00023 #include "rtl/alloc.h"
00024 #include <cstddef>
00025
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 namespace rtl {
00039
00040 template<class T>
00041 class Allocator
00042 {
00043 public:
00044 typedef T value_type;
00045 typedef T* pointer;
00046 typedef const T* const_pointer;
00047 typedef T& reference;
00048 typedef const T& const_reference;
00049 typedef ::std::size_t size_type;
00050 typedef ::std::ptrdiff_t difference_type;
00051
00052
00053 template<class U>
00054 struct rebind
00055 {
00056 typedef Allocator<U> other;
00057 };
00058
00059
00060 pointer address (reference value) const
00061 {
00062 return &value;
00063 }
00064
00065
00066 const_pointer address (const_reference value) const
00067 {
00068 return &value;
00069 }
00070
00071
00072 Allocator() SAL_THROW(())
00073 {}
00074
00075
00076 template<class U>
00077 Allocator (SAL_UNUSED_PARAMETER const Allocator<U>&) SAL_THROW(())
00078 {}
00079
00080
00081 Allocator(const Allocator&) SAL_THROW(())
00082 {}
00083
00084
00085 ~Allocator() SAL_THROW(())
00086 {}
00087
00088
00089 size_type max_size() const SAL_THROW(())
00090 {
00091 return size_type(-1)/sizeof(T);
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 pointer allocate (size_type n, SAL_UNUSED_PARAMETER const void* = 0)
00116 {
00117 return reinterpret_cast<pointer>(
00118 rtl_allocateMemory(sal_uInt32(n * sizeof(T))));
00119 }
00120
00121
00122 void deallocate (pointer p, SAL_UNUSED_PARAMETER size_type )
00123 {
00124 rtl_freeMemory(p);
00125 }
00126
00127
00128 #if defined HAVE_CXX11_PERFECT_FORWARDING
00129 template< typename... Args >
00130 void construct (pointer p, Args &&... value)
00131 {
00132 new ((void*)p)T(std::forward< Args >(value)...);
00133 }
00134 #else
00135 void construct (pointer p, const T& value)
00136 {
00137 new ((void*)p)T(value);
00138 }
00139 #endif
00140
00141
00142 void destroy (pointer p)
00143 {
00144 p->~T();
00145 (void)p;
00146 }
00147 };
00148
00149
00150
00151
00152
00153
00154 template<class T, class U> inline bool operator ==(
00155 SAL_UNUSED_PARAMETER const Allocator<T>&,
00156 SAL_UNUSED_PARAMETER const Allocator<U>&) SAL_THROW(())
00157 {
00158 return true;
00159 }
00160
00161 template<class T, class U>
00162 inline bool operator!= (const Allocator<T>&, const Allocator<U>&) SAL_THROW(())
00163 {
00164 return false;
00165 }
00166
00167 }
00168
00173 namespace _STL
00174 {
00175 template<class T, class U>
00176 inline ::rtl::Allocator<U> & __stl_alloc_rebind (::rtl::Allocator<T> & a, U const *)
00177 {
00178 return (::rtl::Allocator<U>&)(a);
00179 }
00180 }
00181
00183
00184 #endif
00185
00186