epoc32/include/tools/stlport/stl/_alloc_old.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 template<class _Tp, class _Alloc>
     2 class __simple_alloc {
     3   typedef _Alloc __alloc_type;
     4 public:
     5   typedef typename _Alloc::value_type __alloc_value_type;
     6   typedef _Tp value_type;
     7   static size_t  _STLP_CALL __chunk(size_t __n) {
     8     return (sizeof(__alloc_value_type)==sizeof(value_type)) ? __n :
     9       ((__n*sizeof(value_type)+sizeof(__alloc_value_type)-1)/sizeof(__alloc_value_type));
    10   }
    11   static _Tp*  _STLP_CALL allocate(size_t __n) { return 0 == __n ? 0 : (_Tp*) __alloc_type::allocate(__chunk(__n)); }
    12   static void  _STLP_CALL deallocate(_Tp * __p, size_t __n) {
    13     __alloc_type::deallocate((__alloc_value_type*)__p, __chunk(__n)); }
    14 };
    15 
    16 // Allocator adaptor to turn an SGI-style allocator (e.g. alloc, malloc_alloc)
    17 // into a standard-conforming allocator.   Note that this adaptor does
    18 // *not* assume that all objects of the underlying alloc class are
    19 // identical, nor does it assume that all of the underlying alloc's
    20 // member functions are static member functions.  Note, also, that
    21 // __allocator<_Tp, alloc> is essentially the same thing as allocator<_Tp>.
    22 
    23 template <class _Tp, class _Alloc>
    24 struct __allocator : public _Alloc {
    25   typedef _Alloc __underlying_alloc;
    26 
    27   typedef size_t    size_type;
    28   typedef ptrdiff_t difference_type;
    29   typedef _Tp*       pointer;
    30   typedef const _Tp* const_pointer;
    31   typedef _Tp&       reference;
    32   typedef const _Tp& const_reference;
    33   typedef _Tp        value_type;
    34 
    35 # if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
    36   template <class _Tp1> struct rebind {
    37     typedef __allocator<_Tp1, _Alloc> other;
    38   };
    39 # endif
    40   __allocator() _STLP_NOTHROW {}
    41   __allocator(const _Alloc& ) _STLP_NOTHROW {}
    42   __allocator(const __allocator<_Tp, _Alloc>& __a) _STLP_NOTHROW
    43     : _Alloc(__a) {}
    44 # if defined (_STLP_MEMBER_TEMPLATES) && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
    45   template <class _Tp1>
    46   __allocator(const __allocator<_Tp1, _Alloc>& __a) _STLP_NOTHROW
    47     : _Alloc(__a) {}
    48 # endif
    49 # ifdef _STLP_TRIVIAL_DESTRUCTOR_BUG
    50   ~__allocator() _STLP_NOTHROW {}
    51 # endif
    52   pointer address(reference __x) const { return &__x; }
    53 
    54 # if !defined (__WATCOM_CPLUSPLUS__)
    55   const_pointer address(const_reference __x) const { return &__x; }
    56 # endif
    57 
    58   // __n is permitted to be 0.
    59   _Tp* allocate(size_type __n, const void* = 0) {
    60     if (__n > max_size())
    61       __THROW_BAD_ALLOC;
    62     return __n != 0
    63         ? __STATIC_CAST(_Tp*,__underlying_alloc::allocate(__n * sizeof(_Tp)))
    64         : 0;
    65   }
    66 
    67   // __p is not permitted to be a null pointer.
    68   void deallocate(pointer __p, size_type __n)
    69     { if (__p) __underlying_alloc::deallocate(__p, __n * sizeof(_Tp)); }
    70 
    71   size_type max_size() const _STLP_NOTHROW
    72     { return size_t(-1) / sizeof(_Tp); }
    73 
    74   void construct(pointer __p, const_reference __val) { _STLP_STD::_Copy_Construct(__p, __val); }
    75   void destroy(pointer __p) { _STLP_STD::_Destroy(__p); }
    76 
    77   const __underlying_alloc& __get_underlying_alloc() const { return *this; }
    78 };
    79 
    80 #ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
    81 template <class _Alloc>
    82 class __allocator<void, _Alloc> {
    83   typedef size_t      size_type;
    84   typedef ptrdiff_t   difference_type;
    85   typedef void*       pointer;
    86   typedef const void* const_pointer;
    87   typedef void        value_type;
    88 #ifdef _STLP_MEMBER_TEMPLATE_CLASSES
    89   template <class _Tp1> struct rebind {
    90     typedef __allocator<_Tp1, _Alloc> other;
    91   };
    92 #endif
    93 };
    94 #endif
    95 
    96 template <class _Tp, class _Alloc>
    97 inline bool  _STLP_CALL operator==(const __allocator<_Tp, _Alloc>& __a1,
    98                                    const __allocator<_Tp, _Alloc>& __a2)
    99 {
   100   return __a1.__get_underlying_alloc() == __a2.__get_underlying_alloc();
   101 }
   102 
   103 #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
   104 template <class _Tp, class _Alloc>
   105 inline bool  _STLP_CALL operator!=(const __allocator<_Tp, _Alloc>& __a1,
   106                                    const __allocator<_Tp, _Alloc>& __a2)
   107 {
   108   return __a1.__get_underlying_alloc() != __a2.__get_underlying_alloc();
   109 }
   110 #endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
   111 
   112 
   113 // Comparison operators for all of the predifined SGI-style allocators.
   114 // This ensures that __allocator<malloc_alloc> (for example) will
   115 // work correctly.
   116 
   117 #ifndef _STLP_NON_TYPE_TMPL_PARAM_BUG
   118 inline bool  _STLP_CALL operator==(const __malloc_alloc&, const __malloc_alloc&)
   119 { return true; }
   120 
   121 #  ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
   122 inline bool  _STLP_CALL operator!=(const __malloc_alloc&, const __malloc_alloc&)
   123 { return false; }
   124 #  endif
   125 
   126 inline bool _STLP_CALL operator==(const __new_alloc&, const __new_alloc&) { return true; }
   127 
   128 #  ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
   129 inline bool _STLP_CALL operator!=(const __new_alloc&, const __new_alloc&) { return false; }
   130 #  endif
   131 
   132 #  if !defined (_STLP_USE_NO_IOSTREAMS)
   133 inline bool  _STLP_CALL operator==(const __node_alloc&,
   134                                    const __node_alloc&)
   135 { return true; }
   136 
   137 #    if defined( _STLP_FUNCTION_TMPL_PARTIAL_ORDER )
   138 
   139 inline bool  _STLP_CALL operator!=(const __node_alloc&,
   140                                    const __node_alloc&)
   141 { return false; }
   142 #    endif
   143 #  endif
   144 
   145 #endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
   146 
   147 template <class _Alloc>
   148 inline bool  _STLP_CALL operator==(const __debug_alloc<_Alloc>&, const __debug_alloc<_Alloc>&) {  return true; }
   149 # ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
   150 template <class _Alloc>
   151 inline bool  _STLP_CALL operator!=(const __debug_alloc<_Alloc>&, const __debug_alloc<_Alloc>&) {  return false; }
   152 # endif
   153 
   154 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
   155 
   156 // Versions for the predefined SGI-style allocators.
   157 template <class _Tp>
   158 struct _Alloc_traits<_Tp, __malloc_alloc> {
   159   typedef __allocator<_Tp, __malloc_alloc> allocator_type;
   160 };
   161 
   162 #  if !defined (_STLP_USE_NO_IOSTREAMS)
   163 template <class _Tp>
   164 struct _Alloc_traits<_Tp, __node_alloc> {
   165   typedef __allocator<_Tp, __node_alloc> allocator_type;
   166 };
   167 #  endif
   168 
   169 template <class _Tp, class _Alloc>
   170 struct _Alloc_traits<_Tp, __debug_alloc<_Alloc> > {
   171   typedef __allocator<_Tp, __debug_alloc<_Alloc> > allocator_type;
   172 };
   173 
   174 // Versions for the __allocator adaptor used with the predefined
   175 // SGI-style allocators.
   176 
   177 template <class _Tp, class _Tp1, class _Alloc>
   178 struct _Alloc_traits<_Tp, __allocator<_Tp1, _Alloc > > {
   179   typedef __allocator<_Tp, _Alloc > allocator_type;
   180 };
   181 
   182 #endif
   183 
   184 #if defined (_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE)
   185 
   186 // Versions for the predefined SGI-style allocators.
   187 
   188 
   189 #  if defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
   190 
   191 typedef __malloc_alloc __malloc_alloc_dfl;
   192 
   193 template <class _Tp>
   194 inline __allocator<_Tp, __malloc_alloc_dfl >& _STLP_CALL
   195 __stl_alloc_rebind(__malloc_alloc_dfl& __a, const _Tp*) {
   196   return (__allocator<_Tp, __malloc_alloc_dfl >&)__a;
   197 }
   198 
   199 #    if !defined (_STLP_USE_NO_IOSTREAMS)
   200 template <class _Tp>
   201 inline __allocator<_Tp, __node_alloc>& _STLP_CALL
   202 __stl_alloc_rebind(__node_alloc& __a, const _Tp*) {
   203   return (__allocator<_Tp, __node_alloc>&)__a;
   204 }
   205 #    endif
   206 
   207 template <class _Tp>
   208 inline __allocator<_Tp, __malloc_alloc_dfl > _STLP_CALL
   209 __stl_alloc_create(const __malloc_alloc_dfl&, const _Tp*) {
   210   return __allocator<_Tp, __malloc_alloc_dfl > ();
   211 }
   212 
   213 #    if !defined (_STLP_USE_NO_IOSTREAMS)
   214 template <class _Tp>
   215 inline __allocator<_Tp, __node_alloc> _STLP_CALL
   216 __stl_alloc_create(const __node_alloc&, const _Tp*) {
   217   return __allocator<_Tp, __node_alloc>();
   218 }
   219 
   220 #    endif
   221 
   222 #  else
   223 
   224 template <class _Tp>
   225 inline __allocator<_Tp, __malloc_alloc>& _STLP_CALL
   226 __stl_alloc_rebind(__malloc_alloc& __a, const _Tp*) {
   227   return (__allocator<_Tp, __malloc_alloc>&)__a;
   228 }
   229 
   230 #    if !defined (_STLP_USE_NO_IOSTREAMS)
   231 template <class _Tp>
   232 inline __allocator<_Tp, __node_alloc>& _STLP_CALL
   233 __stl_alloc_rebind(__node_alloc& __a, const _Tp*) {
   234   return (__allocator<_Tp, __node_alloc>&)__a;
   235 }
   236 #    endif
   237 
   238 template <class _Tp>
   239 inline __allocator<_Tp, __malloc_alloc> _STLP_CALL
   240 __stl_alloc_create(const __malloc_alloc&, const _Tp*) {
   241   return __allocator<_Tp, __malloc_alloc>();
   242 }
   243 
   244 #    if !defined (_STLP_USE_NO_IOSTREAMS)
   245 template <class _Tp>
   246 inline __allocator<_Tp, __node_alloc> _STLP_CALL
   247 __stl_alloc_create(const __node_alloc&, const _Tp*) {
   248   return __allocator<_Tp, __node_alloc>();
   249 }
   250 #    endif
   251 
   252 #  endif
   253 
   254 template <class _Tp, class _Alloc>
   255 inline __allocator<_Tp, __debug_alloc<_Alloc> > _STLP_CALL
   256 __stl_alloc_create(const __debug_alloc<_Alloc>&, const _Tp*) {
   257   return __allocator<_Tp, __debug_alloc<_Alloc> >();
   258 }
   259 template <class _Tp, class _Alloc>
   260 inline __allocator<_Tp, __debug_alloc<_Alloc> >& _STLP_CALL
   261 __stl_alloc_rebind(__debug_alloc<_Alloc>& __a, const _Tp*) {
   262   return (__allocator<_Tp, __debug_alloc<_Alloc> >&)__a;
   263 }
   264 
   265 template <class _Tp>
   266 inline __allocator<_Tp, __new_alloc > _STLP_CALL
   267 __stl_alloc_create(const __new_alloc&, const _Tp*) {
   268   return __allocator<_Tp, __new_alloc >();
   269 }
   270 template <class _Tp>
   271 inline __allocator<_Tp, __new_alloc >&  _STLP_CALL
   272 __stl_alloc_rebind(__new_alloc& __a, const _Tp*) {
   273   return (__allocator<_Tp, __new_alloc >&)__a;
   274 }
   275 
   276 template <class _Tp1, class _Alloc, class _Tp2>
   277 inline __allocator<_Tp2, _Alloc>& _STLP_CALL
   278 __stl_alloc_rebind(__allocator<_Tp1, _Alloc>& __a, const _Tp2*) {
   279   return (__allocator<_Tp2, _Alloc>&)__a;
   280 }
   281 
   282 template <class _Tp1, class _Alloc, class _Tp2>
   283 inline __allocator<_Tp2, _Alloc> _STLP_CALL
   284 __stl_alloc_create(const __allocator<_Tp1, _Alloc>&, const _Tp2*) {
   285   return __allocator<_Tp2, _Alloc>();
   286 }
   287 #endif