epoc32/include/tools/stlport/stl/_alloc.h
branchSymbian3
changeset 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/tools/stlport/stl/_alloc.h	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -0,0 +1,648 @@
     1.4 +/*
     1.5 + *
     1.6 + * Copyright (c) 1996,1997
     1.7 + * Silicon Graphics Computer Systems, Inc.
     1.8 + *
     1.9 + * Copyright (c) 1997
    1.10 + * Moscow Center for SPARC Technology
    1.11 + *
    1.12 + * Copyright (c) 1999
    1.13 + * Boris Fomitchev
    1.14 + *
    1.15 + * This material is provided "as is", with absolutely no warranty expressed
    1.16 + * or implied. Any use is at your own risk.
    1.17 + *
    1.18 + * Permission to use or copy this software for any purpose is hereby granted
    1.19 + * without fee, provided the above notices are retained on all copies.
    1.20 + * Permission to modify the code and to distribute modified code is granted,
    1.21 + * provided the above notices are retained, and a notice that the code was
    1.22 + * modified is included with the above copyright notice.
    1.23 + *
    1.24 + */
    1.25 +
    1.26 +/* NOTE: This is an internal header file, included by other STL headers.
    1.27 + *   You should not attempt to use it directly.
    1.28 + */
    1.29 +
    1.30 +#ifndef _STLP_INTERNAL_ALLOC_H
    1.31 +#define _STLP_INTERNAL_ALLOC_H
    1.32 +
    1.33 +#ifndef _STLP_INTERNAL_CSTDDEF
    1.34 +#  include <stl/_cstddef.h>
    1.35 +#endif
    1.36 +
    1.37 +#if !defined (_STLP_DEBUG_H) && (defined(_STLP_DEBUG) || defined(_STLP_ASSERTIONS) || defined(_STLP_DEBUG_ALLOC))
    1.38 +#  include <stl/debug/_debug.h>
    1.39 +#endif
    1.40 +
    1.41 +#ifndef _STLP_INTERNAL_CSTDLIB
    1.42 +#  include <stl/_cstdlib.h>
    1.43 +#endif
    1.44 +
    1.45 +#ifndef _STLP_INTERNAL_CSTRING
    1.46 +#  include <stl/_cstring.h>
    1.47 +#endif
    1.48 +
    1.49 +#ifndef _STLP_INTERNAL_ALGOBASE_H
    1.50 +#  include <stl/_algobase.h>
    1.51 +#endif
    1.52 +
    1.53 +#ifndef __THROW_BAD_ALLOC
    1.54 +#  if !defined(_STLP_USE_EXCEPTIONS)
    1.55 +#    ifndef _STLP_INTERNAL_CSTDIO
    1.56 +#      include <stl/_cstdio.h>
    1.57 +#    endif
    1.58 +#    define __THROW_BAD_ALLOC puts("out of memory\n"); exit(1)
    1.59 +#  else
    1.60 +#    define __THROW_BAD_ALLOC throw _STLP_STD::bad_alloc()
    1.61 +#  endif
    1.62 +#endif
    1.63 +
    1.64 +#ifndef _STLP_INTERNAL_NEW_HEADER
    1.65 +#  include <stl/_new.h>
    1.66 +#endif
    1.67 +
    1.68 +#ifndef _STLP_INTERNAL_CONSTRUCT_H
    1.69 +#  include <stl/_construct.h>
    1.70 +#endif
    1.71 +
    1.72 +#if !defined (__ALLOC)
    1.73 +#  define __ALLOC __sgi_alloc
    1.74 +#endif
    1.75 +
    1.76 +_STLP_BEGIN_NAMESPACE
    1.77 +
    1.78 +#if defined (_STLP_USE_RAW_SGI_ALLOCATORS)
    1.79 +template <class _Tp, class _Alloc> struct __allocator;
    1.80 +#endif
    1.81 +
    1.82 +// Malloc-based allocator.  Typically slower than default alloc below.
    1.83 +// Typically thread-safe and more storage efficient.
    1.84 +
    1.85 +#if !defined (_STLP_USE_NO_IOSTREAMS)
    1.86 +typedef void (* __oom_handler_type)();
    1.87 +#endif
    1.88 +
    1.89 +class _STLP_CLASS_DECLSPEC __malloc_alloc {
    1.90 +public:
    1.91 +  // this one is needed for proper simple_alloc wrapping
    1.92 +  typedef char value_type;
    1.93 +#if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_USE_RAW_SGI_ALLOCATORS)
    1.94 +  template <class _Tp1> struct rebind {
    1.95 +    typedef __allocator<_Tp1, __malloc_alloc> other;
    1.96 +  };
    1.97 +#endif
    1.98 +  static void* _STLP_CALL allocate(size_t& __n)
    1.99 +#if !defined (_STLP_USE_NO_IOSTREAMS)
   1.100 +  ;
   1.101 +#else
   1.102 +  {
   1.103 +    void *__result = malloc(__n);
   1.104 +#  if defined (_STLP_MALLOC_USABLE_SIZE)
   1.105 +    if (__result != 0) {
   1.106 +      __n = _STLP_MALLOC_USABLE_SIZE(__result);
   1.107 +    }
   1.108 +#  endif
   1.109 +    if (__result == 0) {
   1.110 +      __THROW_BAD_ALLOC;
   1.111 +    }
   1.112 +    return __result;
   1.113 +  }
   1.114 +#endif
   1.115 +
   1.116 +  static void _STLP_CALL deallocate(void* __p, size_t /* __n */) { free((char*)__p); }
   1.117 +#if !defined (_STLP_USE_NO_IOSTREAMS)
   1.118 +  static __oom_handler_type _STLP_CALL set_malloc_handler(__oom_handler_type __f);
   1.119 +#endif
   1.120 +};
   1.121 +
   1.122 +// New-based allocator.  Typically slower than default alloc below.
   1.123 +// Typically thread-safe and more storage efficient.
   1.124 +class _STLP_CLASS_DECLSPEC __new_alloc {
   1.125 +public:
   1.126 +  // this one is needed for proper simple_alloc wrapping
   1.127 +  typedef char value_type;
   1.128 +#if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_USE_RAW_SGI_ALLOCATORS)
   1.129 +  template <class _Tp1> struct rebind {
   1.130 +    typedef __allocator<_Tp1, __new_alloc > other;
   1.131 +  };
   1.132 +#endif
   1.133 +  static void* _STLP_CALL allocate(size_t __n) { return __stl_new(__n); }
   1.134 +  static void _STLP_CALL deallocate(void* __p, size_t) { __stl_delete(__p); }
   1.135 +};
   1.136 +
   1.137 +
   1.138 +// Allocator adaptor to check size arguments for debugging.
   1.139 +// Reports errors using assert.  Checking can be disabled with
   1.140 +// NDEBUG, but it's far better to just use the underlying allocator
   1.141 +// instead when no checking is desired.
   1.142 +// There is some evidence that this can confuse Purify.
   1.143 +// This adaptor can only be applied to raw allocators
   1.144 +
   1.145 +template <class _Alloc>
   1.146 +class __debug_alloc : public _Alloc {
   1.147 +public:
   1.148 +  typedef _Alloc __allocator_type;
   1.149 +  typedef typename _Alloc::value_type value_type;
   1.150 +private:
   1.151 +  struct __alloc_header {
   1.152 +    size_t __magic: 16;
   1.153 +    size_t __type_size:16;
   1.154 +    _STLP_UINT32_T _M_size;
   1.155 +  }; // that is 8 bytes for sure
   1.156 +  // Sunpro CC has bug on enums, so extra_before/after set explicitly
   1.157 +  enum { __pad = 8, __magic = 0xdeba, __deleted_magic = 0xdebd,
   1.158 +         __shred_byte = _STLP_SHRED_BYTE };
   1.159 +
   1.160 +  enum { __extra_before = 16, __extra_after = 8 };
   1.161 +  // Size of space used to store size.  Note
   1.162 +  // that this must be large enough to preserve
   1.163 +  // alignment.
   1.164 +  static size_t _STLP_CALL __extra_before_chunk() {
   1.165 +    return (long)__extra_before / sizeof(value_type) +
   1.166 +      (size_t)((long)__extra_before % sizeof(value_type) > 0);
   1.167 +  }
   1.168 +  static size_t _STLP_CALL __extra_after_chunk() {
   1.169 +    return (long)__extra_after / sizeof(value_type) +
   1.170 +      (size_t)((long)__extra_after % sizeof(value_type) > 0);
   1.171 +  }
   1.172 +public:
   1.173 +#if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_USE_RAW_SGI_ALLOCATORS)
   1.174 +  template <class _Tp1> struct rebind {
   1.175 +    typedef __allocator< _Tp1, __debug_alloc<_Alloc> > other;
   1.176 +  };
   1.177 +#endif
   1.178 +  __debug_alloc() {}
   1.179 +  ~__debug_alloc() {}
   1.180 +  static void* _STLP_CALL allocate(size_t);
   1.181 +  static void _STLP_CALL deallocate(void *, size_t);
   1.182 +};
   1.183 +
   1.184 +#  if defined (__OS400__) || defined (_WIN64)
   1.185 +enum {_ALIGN = 16, _ALIGN_SHIFT = 4, _MAX_BYTES = 256};
   1.186 +#  else
   1.187 +enum {_ALIGN = 8, _ALIGN_SHIFT = 3, _MAX_BYTES = 128};
   1.188 +#  endif /* __OS400__ */
   1.189 +
   1.190 +#if !defined (_STLP_USE_NO_IOSTREAMS)
   1.191 +// Default node allocator.
   1.192 +// With a reasonable compiler, this should be roughly as fast as the
   1.193 +// original STL class-specific allocators, but with less fragmentation.
   1.194 +class _STLP_CLASS_DECLSPEC __node_alloc {
   1.195 +  static void * _STLP_CALL _M_allocate(size_t& __n);
   1.196 +  /* __p may not be 0 */
   1.197 +  static void _STLP_CALL _M_deallocate(void *__p, size_t __n);
   1.198 +
   1.199 +public:
   1.200 +  // this one is needed for proper simple_alloc wrapping
   1.201 +  typedef char value_type;
   1.202 +#  if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_USE_RAW_SGI_ALLOCATORS)
   1.203 +  template <class _Tp1> struct rebind {
   1.204 +    typedef __allocator<_Tp1, __node_alloc> other;
   1.205 +  };
   1.206 +#  endif
   1.207 +  /* __n must be > 0      */
   1.208 +  static void* _STLP_CALL allocate(size_t& __n)
   1.209 +  { return (__n > (size_t)_MAX_BYTES) ? __stl_new(__n) : _M_allocate(__n); }
   1.210 +  /* __p may not be 0 */
   1.211 +  static void _STLP_CALL deallocate(void *__p, size_t __n)
   1.212 +  { if (__n > (size_t)_MAX_BYTES) __stl_delete(__p); else _M_deallocate(__p, __n); }
   1.213 +};
   1.214 +
   1.215 +#  if defined (_STLP_USE_TEMPLATE_EXPORT)
   1.216 +_STLP_EXPORT_TEMPLATE_CLASS __debug_alloc<__node_alloc>;
   1.217 +#  endif
   1.218 +
   1.219 +#endif /* _STLP_USE_NO_IOSTREAMS */
   1.220 +
   1.221 +#if defined (_STLP_USE_TEMPLATE_EXPORT)
   1.222 +_STLP_EXPORT_TEMPLATE_CLASS __debug_alloc<__new_alloc>;
   1.223 +_STLP_EXPORT_TEMPLATE_CLASS __debug_alloc<__malloc_alloc>;
   1.224 +#endif
   1.225 +
   1.226 +/* macro to convert the allocator for initialization
   1.227 + * not using MEMBER_TEMPLATE_CLASSES as it should work given template constructor  */
   1.228 +#if defined (_STLP_MEMBER_TEMPLATES) || ! defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
   1.229 +/* if _STLP_NO_TEMPLATE_CONVERSIONS is set, the member template constructor is
   1.230 + * not used implicitly to convert allocator parameter, so let us do it explicitly */
   1.231 +#  if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_NO_TEMPLATE_CONVERSIONS)
   1.232 +#    define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __stl_alloc_create(__a,(_Tp*)0)
   1.233 +#  else
   1.234 +#    define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __a
   1.235 +#  endif
   1.236 +/* else convert, but only if partial specialization works, since else
   1.237 + * Container::allocator_type won't be different */
   1.238 +#else
   1.239 +#  define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __stl_alloc_create(__a,(_Tp*)0)
   1.240 +#endif /* _STLP_MEMBER_TEMPLATES || !_STLP_CLASS_PARTIAL_SPECIALIZATION */
   1.241 +
   1.242 +// Another allocator adaptor: _Alloc_traits.  This serves two
   1.243 +// purposes.  First, make it possible to write containers that can use
   1.244 +// either SGI-style allocators or standard-conforming allocator.
   1.245 +
   1.246 +// The fully general version.
   1.247 +template <class _Tp, class _Allocator>
   1.248 +struct _Alloc_traits {
   1.249 +  typedef _Allocator _Orig;
   1.250 +#if !defined (_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE)
   1.251 +  typedef typename _Allocator::_STLP_TEMPLATE rebind<_Tp> _Rebind_type;
   1.252 +  typedef typename _Rebind_type::other  allocator_type;
   1.253 +  static allocator_type create_allocator(const _Orig& __a)
   1.254 +  { return allocator_type(_STLP_CONVERT_ALLOCATOR(__a, _Tp)); }
   1.255 +#else
   1.256 +  // this is not actually true, used only to pass this type through
   1.257 +  // to dynamic overload selection in _STLP_alloc_proxy methods
   1.258 +  typedef _Allocator allocator_type;
   1.259 +#endif /* !_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE */
   1.260 +};
   1.261 +
   1.262 +#if defined (_STLP_USE_PERTHREAD_ALLOC)
   1.263 +
   1.264 +_STLP_END_NAMESPACE
   1.265 +
   1.266 +// include additional header here
   1.267 +#  include <stl/_pthread_alloc.h>
   1.268 +
   1.269 +_STLP_BEGIN_NAMESPACE
   1.270 +
   1.271 +#  if defined (_STLP_DEBUG_ALLOC)
   1.272 +typedef __debug_alloc<__pthread_alloc> __sgi_alloc;
   1.273 +#  else
   1.274 +typedef __pthread_alloc __sgi_alloc;
   1.275 +#  endif /* _STLP_DEBUG_ALLOC */
   1.276 +
   1.277 +typedef __pthread_alloc __single_client_alloc;
   1.278 +typedef __pthread_alloc __multithreaded_alloc;
   1.279 +
   1.280 +#else /* _STLP_USE_PERTHREAD_ALLOC */
   1.281 +
   1.282 +#  if defined (_STLP_USE_NEWALLOC)
   1.283 +
   1.284 +#    if defined (_STLP_DEBUG_ALLOC)
   1.285 +typedef __debug_alloc<__new_alloc> __sgi_alloc;
   1.286 +#    else
   1.287 +typedef __new_alloc __sgi_alloc;
   1.288 +#    endif /* _STLP_DEBUG_ALLOC */
   1.289 +
   1.290 +typedef __new_alloc __single_client_alloc;
   1.291 +typedef __new_alloc __multithreaded_alloc;
   1.292 +
   1.293 +#  elif defined (_STLP_USE_MALLOC)
   1.294 +
   1.295 +#    if defined (_STLP_DEBUG_ALLOC)
   1.296 +typedef __debug_alloc<__malloc_alloc> __sgi_alloc;
   1.297 +#    else
   1.298 +typedef __malloc_alloc __sgi_alloc;
   1.299 +#    endif /* _STLP_DEBUG_ALLOC */
   1.300 +
   1.301 +typedef __malloc_alloc __single_client_alloc;
   1.302 +typedef __malloc_alloc __multithreaded_alloc;
   1.303 +
   1.304 +#  else
   1.305 +
   1.306 +#    if defined (_STLP_DEBUG_ALLOC)
   1.307 +typedef __debug_alloc<__node_alloc> __sgi_alloc;
   1.308 +#    else
   1.309 +typedef __node_alloc __sgi_alloc;
   1.310 +#    endif
   1.311 +
   1.312 +typedef __node_alloc __single_client_alloc;
   1.313 +typedef __node_alloc __multithreaded_alloc;
   1.314 +
   1.315 +#  endif /* _STLP_USE_NEWALLOC */
   1.316 +#endif /* _STLP_USE_PERTHREAD_ALLOC */
   1.317 +
   1.318 +// This implements allocators as specified in the C++ standard.
   1.319 +//
   1.320 +// Note that standard-conforming allocators use many language features
   1.321 +// that are not yet widely implemented.  In particular, they rely on
   1.322 +// member templates, partial specialization, partial ordering of function
   1.323 +// templates, the typename keyword, and the use of the template keyword
   1.324 +// to refer to a template member of a dependent type.
   1.325 +
   1.326 +/*
   1.327 +template <class _Tp>
   1.328 +struct _AllocatorAux {
   1.329 +  typedef _Tp*       pointer;
   1.330 +  typedef const _Tp* const_pointer;
   1.331 +  typedef _Tp&       reference;
   1.332 +  typedef const _Tp& const_reference;
   1.333 +
   1.334 +  pointer address(reference __x) const {return &__x;}
   1.335 +  const_pointer address(const_reference __x) const { return &__x; }
   1.336 +};
   1.337 +
   1.338 +template <class _Tp>
   1.339 +struct _AllocatorAux<const _Tp> {
   1.340 +  typedef _Tp*       pointer;
   1.341 +  typedef const _Tp* const_pointer;
   1.342 +  typedef _Tp&       reference;
   1.343 +  typedef const _Tp& const_reference;
   1.344 +
   1.345 +  const_pointer address(const_reference __x) const { return &__x; }
   1.346 +};
   1.347 +*/
   1.348 +
   1.349 +template <class _Tp>
   1.350 +class allocator //: public _AllocatorAux<_Tp>
   1.351 +/* A small helper struct to recognize STLport allocator implementation
   1.352 + * from any user specialization one.
   1.353 + */
   1.354 +                : public __stlport_class<allocator<_Tp> > {
   1.355 +public:
   1.356 +  typedef _Tp        value_type;
   1.357 +  typedef _Tp*       pointer;
   1.358 +  typedef const _Tp* const_pointer;
   1.359 +  typedef _Tp&       reference;
   1.360 +  typedef const _Tp& const_reference;
   1.361 +  typedef size_t     size_type;
   1.362 +  typedef ptrdiff_t  difference_type;
   1.363 +#if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
   1.364 +  template <class _Tp1> struct rebind {
   1.365 +    typedef allocator<_Tp1> other;
   1.366 +  };
   1.367 +#endif
   1.368 +  allocator() _STLP_NOTHROW {}
   1.369 +#if defined (_STLP_MEMBER_TEMPLATES)
   1.370 +  template <class _Tp1> allocator(const allocator<_Tp1>&) _STLP_NOTHROW {}
   1.371 +#endif
   1.372 +  allocator(const allocator<_Tp>&) _STLP_NOTHROW {}
   1.373 +  allocator(__move_source<allocator<_Tp> > src) _STLP_NOTHROW {}
   1.374 +  ~allocator() _STLP_NOTHROW {}
   1.375 +  pointer address(reference __x) const {return &__x;}
   1.376 +  const_pointer address(const_reference __x) const { return &__x; }
   1.377 +  // __n is permitted to be 0.  The C++ standard says nothing about what the return value is when __n == 0.
   1.378 +  _Tp* allocate(size_type __n, const void* = 0) {
   1.379 +    if (__n > max_size()) {
   1.380 +      __THROW_BAD_ALLOC;
   1.381 +    }
   1.382 +    if (__n != 0) {
   1.383 +      size_type __buf_size = __n * sizeof(value_type);
   1.384 +      _Tp* __ret = __REINTERPRET_CAST(_Tp*, __sgi_alloc::allocate(__buf_size));
   1.385 +#if defined (_STLP_DEBUG_UNINITIALIZED) && !defined (_STLP_DEBUG_ALLOC)
   1.386 +      if (__ret != 0) {
   1.387 +        memset((char*)__ret, _STLP_SHRED_BYTE, __buf_size);
   1.388 +      }
   1.389 +#endif
   1.390 +      return __ret;
   1.391 +    }
   1.392 +    else
   1.393 +      return 0;
   1.394 +  }
   1.395 +  // __p is permitted to be a null pointer, only if n==0.
   1.396 +  void deallocate(pointer __p, size_type __n) {
   1.397 +    _STLP_ASSERT( (__p == 0) == (__n == 0) )
   1.398 +    if (__p != 0) {
   1.399 +#if defined (_STLP_DEBUG_UNINITIALIZED) && !defined (_STLP_DEBUG_ALLOC)
   1.400 +      memset((char*)__p, _STLP_SHRED_BYTE, __n * sizeof(value_type));
   1.401 +#endif
   1.402 +      __sgi_alloc::deallocate((void*)__p, __n * sizeof(value_type));
   1.403 +    }
   1.404 +  }
   1.405 +  // backwards compatibility
   1.406 +  void deallocate(pointer __p) const {  if (__p != 0) __sgi_alloc::deallocate((void*)__p, sizeof(value_type)); }
   1.407 +  size_type max_size() const _STLP_NOTHROW  { return size_t(-1) / sizeof(value_type); }
   1.408 +  void construct(pointer __p, const_reference __val) { _STLP_STD::_Copy_Construct(__p, __val); }
   1.409 +  void destroy(pointer __p) { _STLP_STD::_Destroy(__p); }
   1.410 +#if defined(__MRC__)||(defined(__SC__) && !defined(__DMC__))
   1.411 +  template <class _T2> bool operator==(const allocator<_T2>&) const _STLP_NOTHROW { return true; }
   1.412 +  template <class _T2> bool operator!=(const allocator<_T2>&) const _STLP_NOTHROW { return false; }
   1.413 +#endif
   1.414 +
   1.415 +#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
   1.416 +  //This is just to make swap workaround for compiler without template function partial
   1.417 +  //happy.
   1.418 +  void swap(allocator<_Tp>&) {}
   1.419 +#endif
   1.420 +
   1.421 +#if defined (_STLP_NO_EXTENSIONS)
   1.422 +  /* STLport extension giving rounded size of an allocated memory buffer
   1.423 +   * This method do not have to be part of a user defined allocator implementation
   1.424 +   * and won't even be called if such a function was granted.
   1.425 +   */
   1.426 +protected:
   1.427 +#endif
   1.428 +  _Tp* allocate(size_type __n, size_type& __allocated_n) {
   1.429 +    if (__n > max_size()) {
   1.430 +      __THROW_BAD_ALLOC;
   1.431 +    }
   1.432 +
   1.433 +    if (__n != 0) {
   1.434 +      size_type __buf_size = __n * sizeof(value_type);
   1.435 +      _Tp* __ret = __REINTERPRET_CAST(_Tp*, __sgi_alloc::allocate(__buf_size));
   1.436 +#if defined (_STLP_DEBUG_UNINITIALIZED) && !defined (_STLP_DEBUG_ALLOC)
   1.437 +      if (__ret != 0) {
   1.438 +        memset((char*)__ret, _STLP_SHRED_BYTE, __buf_size);
   1.439 +      }
   1.440 +#endif
   1.441 +      __allocated_n = __buf_size / sizeof(value_type);
   1.442 +      return __ret;
   1.443 +    }
   1.444 +    else
   1.445 +      return 0;
   1.446 +  }
   1.447 +};
   1.448 +
   1.449 +_STLP_TEMPLATE_NULL
   1.450 +class _STLP_CLASS_DECLSPEC allocator<void> {
   1.451 +public:
   1.452 +  typedef size_t      size_type;
   1.453 +  typedef ptrdiff_t   difference_type;
   1.454 +  typedef void*       pointer;
   1.455 +  typedef const void* const_pointer;
   1.456 +#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
   1.457 +  typedef void        value_type;
   1.458 +#endif
   1.459 +#if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
   1.460 +  template <class _Tp1> struct rebind {
   1.461 +    typedef allocator<_Tp1> other;
   1.462 +  };
   1.463 +#endif
   1.464 +#if defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__))  //*ty 03/24/2001 - MPW compilers get confused on these operator definitions
   1.465 +  template <class _T2> bool operator==(const allocator<_T2>&) const _STLP_NOTHROW { return true; }
   1.466 +  template <class _T2> bool operator!=(const allocator<_T2>&) const _STLP_NOTHROW { return false; }
   1.467 +#endif
   1.468 +};
   1.469 +
   1.470 +#if !(defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__)))  //*ty 03/24/2001 - MPW compilers get confused on these operator definitions
   1.471 +template <class _T1, class _T2> inline bool  _STLP_CALL operator==(const allocator<_T1>&, const allocator<_T2>&) _STLP_NOTHROW { return true; }
   1.472 +template <class _T1, class _T2> inline bool  _STLP_CALL operator!=(const allocator<_T1>&, const allocator<_T2>&) _STLP_NOTHROW { return false; }
   1.473 +#endif
   1.474 +
   1.475 +#if defined (_STLP_USE_TEMPLATE_EXPORT)
   1.476 +_STLP_EXPORT_TEMPLATE_CLASS allocator<char>;
   1.477 +#  if defined (_STLP_HAS_WCHAR_T)
   1.478 +_STLP_EXPORT_TEMPLATE_CLASS allocator<wchar_t>;
   1.479 +#  endif
   1.480 +#  if defined (_STLP_USE_PTR_SPECIALIZATIONS)
   1.481 +_STLP_EXPORT_TEMPLATE_CLASS allocator<void*>;
   1.482 +#  endif
   1.483 +#endif
   1.484 +
   1.485 +_STLP_MOVE_TO_PRIV_NAMESPACE
   1.486 +
   1.487 +template <class _Tp>
   1.488 +struct __alloc_type_traits {
   1.489 +#if !defined (__BORLANDC__)
   1.490 +  typedef typename _IsSTLportClass<allocator<_Tp> >::_Ret _STLportAlloc;
   1.491 +#else
   1.492 +  enum { _Is = _IsSTLportClass<allocator<_Tp> >::_Is };
   1.493 +  typedef typename __bool2type<_Is>::_Ret _STLportAlloc;
   1.494 +#endif
   1.495 +  //The default allocator implementation which is recognize thanks to the
   1.496 +  //__stlport_class inheritance is a stateless object so:
   1.497 +  typedef _STLportAlloc has_trivial_default_constructor;
   1.498 +  typedef _STLportAlloc has_trivial_copy_constructor;
   1.499 +  typedef _STLportAlloc has_trivial_assignment_operator;
   1.500 +  typedef _STLportAlloc has_trivial_destructor;
   1.501 +  typedef _STLportAlloc is_POD_type;
   1.502 +};
   1.503 +
   1.504 +_STLP_MOVE_TO_STD_NAMESPACE
   1.505 +
   1.506 +#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
   1.507 +template <class _Tp>
   1.508 +struct __type_traits<allocator<_Tp> > : _STLP_PRIV __alloc_type_traits<_Tp> {};
   1.509 +#else
   1.510 +_STLP_TEMPLATE_NULL
   1.511 +struct __type_traits<allocator<char> > : _STLP_PRIV __alloc_type_traits<char> {};
   1.512 +#  if defined (_STLP_HAS_WCHAR_T)
   1.513 +_STLP_TEMPLATE_NULL
   1.514 +struct __type_traits<allocator<wchar_t> > : _STLP_PRIV __alloc_type_traits<wchar_t> {};
   1.515 +#  endif
   1.516 +#  if defined (_STLP_USE_PTR_SPECIALIZATIONS)
   1.517 +_STLP_TEMPLATE_NULL
   1.518 +struct __type_traits<allocator<void*> > : _STLP_PRIV __alloc_type_traits<void*> {};
   1.519 +#  endif
   1.520 +#endif
   1.521 +
   1.522 +
   1.523 +#if !defined (_STLP_FORCE_ALLOCATORS)
   1.524 +#  define _STLP_FORCE_ALLOCATORS(a,y)
   1.525 +#endif
   1.526 +
   1.527 +#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_MEMBER_TEMPLATE_CLASSES)
   1.528 +// The version for the default allocator, for rare occasion when we have partial spec w/o member template classes
   1.529 +template <class _Tp, class _Tp1>
   1.530 +struct _Alloc_traits<_Tp, allocator<_Tp1> > {
   1.531 +  typedef allocator<_Tp1> _Orig;
   1.532 +  typedef allocator<_Tp> allocator_type;
   1.533 +  static allocator_type create_allocator(const allocator<_Tp1 >& __a)
   1.534 +  { return allocator_type(_STLP_CONVERT_ALLOCATOR(__a, _Tp)); }
   1.535 +};
   1.536 +#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
   1.537 +
   1.538 +#if !defined (_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE) && defined (_STLP_MEMBER_TEMPLATES)
   1.539 +template <class _Tp, class _Alloc>
   1.540 +inline _STLP_TYPENAME_ON_RETURN_TYPE _Alloc_traits<_Tp, _Alloc>::allocator_type  _STLP_CALL
   1.541 +__stl_alloc_create(const _Alloc& __a, const _Tp*) {
   1.542 +  typedef typename _Alloc::_STLP_TEMPLATE rebind<_Tp>::other _Rebound_type;
   1.543 +  return _Rebound_type(__a);
   1.544 +}
   1.545 +#else
   1.546 +// If custom allocators are being used without member template classes support :
   1.547 +// user (on purpose) is forced to define rebind/get operations !!!
   1.548 +template <class _Tp1, class _Tp2>
   1.549 +inline allocator<_Tp2>& _STLP_CALL
   1.550 +__stl_alloc_rebind(allocator<_Tp1>& __a, const _Tp2*) {  return (allocator<_Tp2>&)(__a); }
   1.551 +template <class _Tp1, class _Tp2>
   1.552 +inline allocator<_Tp2> _STLP_CALL
   1.553 +__stl_alloc_create(const allocator<_Tp1>&, const _Tp2*) { return allocator<_Tp2>(); }
   1.554 +#endif /* _STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE */
   1.555 +
   1.556 +#if defined (_STLP_USE_RAW_SGI_ALLOCATORS)
   1.557 +// move obsolete stuff out of the way
   1.558 +#  include <stl/_alloc_old.h>
   1.559 +#endif
   1.560 +
   1.561 +_STLP_MOVE_TO_PRIV_NAMESPACE
   1.562 +
   1.563 +// inheritance is being used for EBO optimization
   1.564 +template <class _Value, class _Tp, class _MaybeReboundAlloc>
   1.565 +class _STLP_alloc_proxy : public _MaybeReboundAlloc {
   1.566 +private:
   1.567 +  typedef _MaybeReboundAlloc _Base;
   1.568 +  typedef typename _Base::size_type size_type;
   1.569 +  typedef _STLP_alloc_proxy<_Value, _Tp, _MaybeReboundAlloc> _Self;
   1.570 +public:
   1.571 +  _Value _M_data;
   1.572 +
   1.573 +  _STLP_alloc_proxy (const _MaybeReboundAlloc& __a, _Value __p) :
   1.574 +    _MaybeReboundAlloc(__a), _M_data(__p) {}
   1.575 +
   1.576 +  _STLP_alloc_proxy (__move_source<_Self> src) :
   1.577 +    _MaybeReboundAlloc(_STLP_PRIV _AsMoveSource<_Base>(src.get())),
   1.578 +    _M_data(_STLP_PRIV _AsMoveSource<_Value>(src.get()._M_data)) {}
   1.579 +
   1.580 +  /* We need to define the following swap implementation for allocator with state
   1.581 +   * as those allocators might have implement a special swap function to correctly
   1.582 +   * move datas from an instance to the oher, _STLP_alloc_proxy should not break
   1.583 +   * this mecanism.
   1.584 +   */
   1.585 +  void _M_swap_alloc(_Self& __x) {
   1.586 +    _MaybeReboundAlloc &__base_this = *this;
   1.587 +    _MaybeReboundAlloc &__base_x = __x;
   1.588 +    _STLP_STD::swap(__base_this, __base_x);
   1.589 +  }
   1.590 +
   1.591 +  void swap(_Self& __x) {
   1.592 +    _M_swap_alloc(__x);
   1.593 +    _STLP_STD::swap(_M_data, __x._M_data);
   1.594 +  }
   1.595 +
   1.596 +  _Tp* allocate(size_type __n, size_type& __allocated_n) {
   1.597 +#if !defined (__BORLANDC__)
   1.598 +    typedef typename _IsSTLportClass<_MaybeReboundAlloc>::_Ret _STLportAlloc;
   1.599 +#else
   1.600 +    typedef typename __bool2type<_IsSTLportClass<_MaybeReboundAlloc>::_Is>::_Ret _STLportAlloc;
   1.601 +#endif
   1.602 +    return allocate(__n, __allocated_n, _STLportAlloc());
   1.603 +  }
   1.604 +
   1.605 +  // Unified interface to perform allocate()/deallocate() with limited
   1.606 +  // language support
   1.607 +#if defined (_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE)
   1.608 +  // else it is rebound already, and allocate() member is accessible
   1.609 +  _Tp* allocate(size_type __n)
   1.610 +  { return __stl_alloc_rebind(__STATIC_CAST(_Base&, *this), __STATIC_CAST(_Tp*, 0)).allocate(__n, 0); }
   1.611 +  void deallocate(_Tp* __p, size_type __n)
   1.612 +  { __stl_alloc_rebind(__STATIC_CAST(_Base&, *this), __STATIC_CAST(_Tp*, 0)).deallocate(__p, __n); }
   1.613 +private:
   1.614 +  _Tp* allocate(size_type __n, size_type& __allocated_n, const __true_type& /*STLport allocator*/)
   1.615 +  { return __stl_alloc_rebind(__STATIC_CAST(_Base&, *this), __STATIC_CAST(_Tp*, 0)).allocate(__n, __allocated_n); }
   1.616 +#else
   1.617 +  //Expose Standard allocate overload (using expression do not work for some compilers (Borland))
   1.618 +  _Tp* allocate(size_type __n)
   1.619 +  { return _Base::allocate(__n); }
   1.620 +private:
   1.621 +  _Tp* allocate(size_type __n, size_type& __allocated_n, const __true_type& /*STLport allocator*/)
   1.622 +  { return _Base::allocate(__n, __allocated_n); }
   1.623 +#endif
   1.624 +
   1.625 +  _Tp* allocate(size_type __n, size_type& __allocated_n, const __false_type& /*STLport allocator*/)
   1.626 +  { __allocated_n = __n; return allocate(__n); }
   1.627 +};
   1.628 +
   1.629 +#if defined (_STLP_USE_TEMPLATE_EXPORT)
   1.630 +_STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<char*, char, allocator<char> >;
   1.631 +#  if defined (_STLP_HAS_WCHAR_T)
   1.632 +_STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<wchar_t*, wchar_t, allocator<wchar_t> >;
   1.633 +#  endif
   1.634 +#  if defined (_STLP_USE_PTR_SPECIALIZATIONS)
   1.635 +_STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<void**, void*, allocator<void*> >;
   1.636 +#  endif
   1.637 +#endif
   1.638 +
   1.639 +_STLP_MOVE_TO_STD_NAMESPACE
   1.640 +_STLP_END_NAMESPACE
   1.641 +
   1.642 +#if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
   1.643 +#  include <stl/_alloc.c>
   1.644 +#endif
   1.645 +
   1.646 +#endif /* _STLP_INTERNAL_ALLOC_H */
   1.647 +
   1.648 +// Local Variables:
   1.649 +// mode:C++
   1.650 +// End:
   1.651 +