epoc32/include/tools/stlport/stl/_alloc.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
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.
williamr@4
     1
/*
williamr@4
     2
 *
williamr@4
     3
 * Copyright (c) 1996,1997
williamr@4
     4
 * Silicon Graphics Computer Systems, Inc.
williamr@4
     5
 *
williamr@4
     6
 * Copyright (c) 1997
williamr@4
     7
 * Moscow Center for SPARC Technology
williamr@4
     8
 *
williamr@4
     9
 * Copyright (c) 1999
williamr@4
    10
 * Boris Fomitchev
williamr@4
    11
 *
williamr@4
    12
 * This material is provided "as is", with absolutely no warranty expressed
williamr@4
    13
 * or implied. Any use is at your own risk.
williamr@4
    14
 *
williamr@4
    15
 * Permission to use or copy this software for any purpose is hereby granted
williamr@4
    16
 * without fee, provided the above notices are retained on all copies.
williamr@4
    17
 * Permission to modify the code and to distribute modified code is granted,
williamr@4
    18
 * provided the above notices are retained, and a notice that the code was
williamr@4
    19
 * modified is included with the above copyright notice.
williamr@4
    20
 *
williamr@4
    21
 */
williamr@4
    22
williamr@4
    23
/* NOTE: This is an internal header file, included by other STL headers.
williamr@4
    24
 *   You should not attempt to use it directly.
williamr@4
    25
 */
williamr@4
    26
williamr@4
    27
#ifndef _STLP_INTERNAL_ALLOC_H
williamr@4
    28
#define _STLP_INTERNAL_ALLOC_H
williamr@4
    29
williamr@4
    30
#ifndef _STLP_INTERNAL_CSTDDEF
williamr@4
    31
#  include <stl/_cstddef.h>
williamr@4
    32
#endif
williamr@4
    33
williamr@4
    34
#if !defined (_STLP_DEBUG_H) && (defined(_STLP_DEBUG) || defined(_STLP_ASSERTIONS) || defined(_STLP_DEBUG_ALLOC))
williamr@4
    35
#  include <stl/debug/_debug.h>
williamr@4
    36
#endif
williamr@4
    37
williamr@4
    38
#ifndef _STLP_INTERNAL_CSTDLIB
williamr@4
    39
#  include <stl/_cstdlib.h>
williamr@4
    40
#endif
williamr@4
    41
williamr@4
    42
#ifndef _STLP_INTERNAL_CSTRING
williamr@4
    43
#  include <stl/_cstring.h>
williamr@4
    44
#endif
williamr@4
    45
williamr@4
    46
#ifndef _STLP_INTERNAL_ALGOBASE_H
williamr@4
    47
#  include <stl/_algobase.h>
williamr@4
    48
#endif
williamr@4
    49
williamr@4
    50
#ifndef __THROW_BAD_ALLOC
williamr@4
    51
#  if !defined(_STLP_USE_EXCEPTIONS)
williamr@4
    52
#    ifndef _STLP_INTERNAL_CSTDIO
williamr@4
    53
#      include <stl/_cstdio.h>
williamr@4
    54
#    endif
williamr@4
    55
#    define __THROW_BAD_ALLOC puts("out of memory\n"); exit(1)
williamr@4
    56
#  else
williamr@4
    57
#    define __THROW_BAD_ALLOC throw _STLP_STD::bad_alloc()
williamr@4
    58
#  endif
williamr@4
    59
#endif
williamr@4
    60
williamr@4
    61
#ifndef _STLP_INTERNAL_NEW_HEADER
williamr@4
    62
#  include <stl/_new.h>
williamr@4
    63
#endif
williamr@4
    64
williamr@4
    65
#ifndef _STLP_INTERNAL_CONSTRUCT_H
williamr@4
    66
#  include <stl/_construct.h>
williamr@4
    67
#endif
williamr@4
    68
williamr@4
    69
#if !defined (__ALLOC)
williamr@4
    70
#  define __ALLOC __sgi_alloc
williamr@4
    71
#endif
williamr@4
    72
williamr@4
    73
_STLP_BEGIN_NAMESPACE
williamr@4
    74
williamr@4
    75
#if defined (_STLP_USE_RAW_SGI_ALLOCATORS)
williamr@4
    76
template <class _Tp, class _Alloc> struct __allocator;
williamr@4
    77
#endif
williamr@4
    78
williamr@4
    79
// Malloc-based allocator.  Typically slower than default alloc below.
williamr@4
    80
// Typically thread-safe and more storage efficient.
williamr@4
    81
williamr@4
    82
#if !defined (_STLP_USE_NO_IOSTREAMS)
williamr@4
    83
typedef void (* __oom_handler_type)();
williamr@4
    84
#endif
williamr@4
    85
williamr@4
    86
class _STLP_CLASS_DECLSPEC __malloc_alloc {
williamr@4
    87
public:
williamr@4
    88
  // this one is needed for proper simple_alloc wrapping
williamr@4
    89
  typedef char value_type;
williamr@4
    90
#if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_USE_RAW_SGI_ALLOCATORS)
williamr@4
    91
  template <class _Tp1> struct rebind {
williamr@4
    92
    typedef __allocator<_Tp1, __malloc_alloc> other;
williamr@4
    93
  };
williamr@4
    94
#endif
williamr@4
    95
  static void* _STLP_CALL allocate(size_t& __n)
williamr@4
    96
#if !defined (_STLP_USE_NO_IOSTREAMS)
williamr@4
    97
  ;
williamr@4
    98
#else
williamr@4
    99
  {
williamr@4
   100
    void *__result = malloc(__n);
williamr@4
   101
#  if defined (_STLP_MALLOC_USABLE_SIZE)
williamr@4
   102
    if (__result != 0) {
williamr@4
   103
      __n = _STLP_MALLOC_USABLE_SIZE(__result);
williamr@4
   104
    }
williamr@4
   105
#  endif
williamr@4
   106
    if (__result == 0) {
williamr@4
   107
      __THROW_BAD_ALLOC;
williamr@4
   108
    }
williamr@4
   109
    return __result;
williamr@4
   110
  }
williamr@4
   111
#endif
williamr@4
   112
williamr@4
   113
  static void _STLP_CALL deallocate(void* __p, size_t /* __n */) { free((char*)__p); }
williamr@4
   114
#if !defined (_STLP_USE_NO_IOSTREAMS)
williamr@4
   115
  static __oom_handler_type _STLP_CALL set_malloc_handler(__oom_handler_type __f);
williamr@4
   116
#endif
williamr@4
   117
};
williamr@4
   118
williamr@4
   119
// New-based allocator.  Typically slower than default alloc below.
williamr@4
   120
// Typically thread-safe and more storage efficient.
williamr@4
   121
class _STLP_CLASS_DECLSPEC __new_alloc {
williamr@4
   122
public:
williamr@4
   123
  // this one is needed for proper simple_alloc wrapping
williamr@4
   124
  typedef char value_type;
williamr@4
   125
#if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_USE_RAW_SGI_ALLOCATORS)
williamr@4
   126
  template <class _Tp1> struct rebind {
williamr@4
   127
    typedef __allocator<_Tp1, __new_alloc > other;
williamr@4
   128
  };
williamr@4
   129
#endif
williamr@4
   130
  static void* _STLP_CALL allocate(size_t __n) { return __stl_new(__n); }
williamr@4
   131
  static void _STLP_CALL deallocate(void* __p, size_t) { __stl_delete(__p); }
williamr@4
   132
};
williamr@4
   133
williamr@4
   134
williamr@4
   135
// Allocator adaptor to check size arguments for debugging.
williamr@4
   136
// Reports errors using assert.  Checking can be disabled with
williamr@4
   137
// NDEBUG, but it's far better to just use the underlying allocator
williamr@4
   138
// instead when no checking is desired.
williamr@4
   139
// There is some evidence that this can confuse Purify.
williamr@4
   140
// This adaptor can only be applied to raw allocators
williamr@4
   141
williamr@4
   142
template <class _Alloc>
williamr@4
   143
class __debug_alloc : public _Alloc {
williamr@4
   144
public:
williamr@4
   145
  typedef _Alloc __allocator_type;
williamr@4
   146
  typedef typename _Alloc::value_type value_type;
williamr@4
   147
private:
williamr@4
   148
  struct __alloc_header {
williamr@4
   149
    size_t __magic: 16;
williamr@4
   150
    size_t __type_size:16;
williamr@4
   151
    _STLP_UINT32_T _M_size;
williamr@4
   152
  }; // that is 8 bytes for sure
williamr@4
   153
  // Sunpro CC has bug on enums, so extra_before/after set explicitly
williamr@4
   154
  enum { __pad = 8, __magic = 0xdeba, __deleted_magic = 0xdebd,
williamr@4
   155
         __shred_byte = _STLP_SHRED_BYTE };
williamr@4
   156
williamr@4
   157
  enum { __extra_before = 16, __extra_after = 8 };
williamr@4
   158
  // Size of space used to store size.  Note
williamr@4
   159
  // that this must be large enough to preserve
williamr@4
   160
  // alignment.
williamr@4
   161
  static size_t _STLP_CALL __extra_before_chunk() {
williamr@4
   162
    return (long)__extra_before / sizeof(value_type) +
williamr@4
   163
      (size_t)((long)__extra_before % sizeof(value_type) > 0);
williamr@4
   164
  }
williamr@4
   165
  static size_t _STLP_CALL __extra_after_chunk() {
williamr@4
   166
    return (long)__extra_after / sizeof(value_type) +
williamr@4
   167
      (size_t)((long)__extra_after % sizeof(value_type) > 0);
williamr@4
   168
  }
williamr@4
   169
public:
williamr@4
   170
#if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_USE_RAW_SGI_ALLOCATORS)
williamr@4
   171
  template <class _Tp1> struct rebind {
williamr@4
   172
    typedef __allocator< _Tp1, __debug_alloc<_Alloc> > other;
williamr@4
   173
  };
williamr@4
   174
#endif
williamr@4
   175
  __debug_alloc() {}
williamr@4
   176
  ~__debug_alloc() {}
williamr@4
   177
  static void* _STLP_CALL allocate(size_t);
williamr@4
   178
  static void _STLP_CALL deallocate(void *, size_t);
williamr@4
   179
};
williamr@4
   180
williamr@4
   181
#  if defined (__OS400__) || defined (_WIN64)
williamr@4
   182
enum {_ALIGN = 16, _ALIGN_SHIFT = 4, _MAX_BYTES = 256};
williamr@4
   183
#  else
williamr@4
   184
enum {_ALIGN = 8, _ALIGN_SHIFT = 3, _MAX_BYTES = 128};
williamr@4
   185
#  endif /* __OS400__ */
williamr@4
   186
williamr@4
   187
#if !defined (_STLP_USE_NO_IOSTREAMS)
williamr@4
   188
// Default node allocator.
williamr@4
   189
// With a reasonable compiler, this should be roughly as fast as the
williamr@4
   190
// original STL class-specific allocators, but with less fragmentation.
williamr@4
   191
class _STLP_CLASS_DECLSPEC __node_alloc {
williamr@4
   192
  static void * _STLP_CALL _M_allocate(size_t& __n);
williamr@4
   193
  /* __p may not be 0 */
williamr@4
   194
  static void _STLP_CALL _M_deallocate(void *__p, size_t __n);
williamr@4
   195
williamr@4
   196
public:
williamr@4
   197
  // this one is needed for proper simple_alloc wrapping
williamr@4
   198
  typedef char value_type;
williamr@4
   199
#  if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_USE_RAW_SGI_ALLOCATORS)
williamr@4
   200
  template <class _Tp1> struct rebind {
williamr@4
   201
    typedef __allocator<_Tp1, __node_alloc> other;
williamr@4
   202
  };
williamr@4
   203
#  endif
williamr@4
   204
  /* __n must be > 0      */
williamr@4
   205
  static void* _STLP_CALL allocate(size_t& __n)
williamr@4
   206
  { return (__n > (size_t)_MAX_BYTES) ? __stl_new(__n) : _M_allocate(__n); }
williamr@4
   207
  /* __p may not be 0 */
williamr@4
   208
  static void _STLP_CALL deallocate(void *__p, size_t __n)
williamr@4
   209
  { if (__n > (size_t)_MAX_BYTES) __stl_delete(__p); else _M_deallocate(__p, __n); }
williamr@4
   210
};
williamr@4
   211
williamr@4
   212
#  if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@4
   213
_STLP_EXPORT_TEMPLATE_CLASS __debug_alloc<__node_alloc>;
williamr@4
   214
#  endif
williamr@4
   215
williamr@4
   216
#endif /* _STLP_USE_NO_IOSTREAMS */
williamr@4
   217
williamr@4
   218
#if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@4
   219
_STLP_EXPORT_TEMPLATE_CLASS __debug_alloc<__new_alloc>;
williamr@4
   220
_STLP_EXPORT_TEMPLATE_CLASS __debug_alloc<__malloc_alloc>;
williamr@4
   221
#endif
williamr@4
   222
williamr@4
   223
/* macro to convert the allocator for initialization
williamr@4
   224
 * not using MEMBER_TEMPLATE_CLASSES as it should work given template constructor  */
williamr@4
   225
#if defined (_STLP_MEMBER_TEMPLATES) || ! defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
williamr@4
   226
/* if _STLP_NO_TEMPLATE_CONVERSIONS is set, the member template constructor is
williamr@4
   227
 * not used implicitly to convert allocator parameter, so let us do it explicitly */
williamr@4
   228
#  if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_NO_TEMPLATE_CONVERSIONS)
williamr@4
   229
#    define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __stl_alloc_create(__a,(_Tp*)0)
williamr@4
   230
#  else
williamr@4
   231
#    define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __a
williamr@4
   232
#  endif
williamr@4
   233
/* else convert, but only if partial specialization works, since else
williamr@4
   234
 * Container::allocator_type won't be different */
williamr@4
   235
#else
williamr@4
   236
#  define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __stl_alloc_create(__a,(_Tp*)0)
williamr@4
   237
#endif /* _STLP_MEMBER_TEMPLATES || !_STLP_CLASS_PARTIAL_SPECIALIZATION */
williamr@4
   238
williamr@4
   239
// Another allocator adaptor: _Alloc_traits.  This serves two
williamr@4
   240
// purposes.  First, make it possible to write containers that can use
williamr@4
   241
// either SGI-style allocators or standard-conforming allocator.
williamr@4
   242
williamr@4
   243
// The fully general version.
williamr@4
   244
template <class _Tp, class _Allocator>
williamr@4
   245
struct _Alloc_traits {
williamr@4
   246
  typedef _Allocator _Orig;
williamr@4
   247
#if !defined (_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE)
williamr@4
   248
  typedef typename _Allocator::_STLP_TEMPLATE rebind<_Tp> _Rebind_type;
williamr@4
   249
  typedef typename _Rebind_type::other  allocator_type;
williamr@4
   250
  static allocator_type create_allocator(const _Orig& __a)
williamr@4
   251
  { return allocator_type(_STLP_CONVERT_ALLOCATOR(__a, _Tp)); }
williamr@4
   252
#else
williamr@4
   253
  // this is not actually true, used only to pass this type through
williamr@4
   254
  // to dynamic overload selection in _STLP_alloc_proxy methods
williamr@4
   255
  typedef _Allocator allocator_type;
williamr@4
   256
#endif /* !_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE */
williamr@4
   257
};
williamr@4
   258
williamr@4
   259
#if defined (_STLP_USE_PERTHREAD_ALLOC)
williamr@4
   260
williamr@4
   261
_STLP_END_NAMESPACE
williamr@4
   262
williamr@4
   263
// include additional header here
williamr@4
   264
#  include <stl/_pthread_alloc.h>
williamr@4
   265
williamr@4
   266
_STLP_BEGIN_NAMESPACE
williamr@4
   267
williamr@4
   268
#  if defined (_STLP_DEBUG_ALLOC)
williamr@4
   269
typedef __debug_alloc<__pthread_alloc> __sgi_alloc;
williamr@4
   270
#  else
williamr@4
   271
typedef __pthread_alloc __sgi_alloc;
williamr@4
   272
#  endif /* _STLP_DEBUG_ALLOC */
williamr@4
   273
williamr@4
   274
typedef __pthread_alloc __single_client_alloc;
williamr@4
   275
typedef __pthread_alloc __multithreaded_alloc;
williamr@4
   276
williamr@4
   277
#else /* _STLP_USE_PERTHREAD_ALLOC */
williamr@4
   278
williamr@4
   279
#  if defined (_STLP_USE_NEWALLOC)
williamr@4
   280
williamr@4
   281
#    if defined (_STLP_DEBUG_ALLOC)
williamr@4
   282
typedef __debug_alloc<__new_alloc> __sgi_alloc;
williamr@4
   283
#    else
williamr@4
   284
typedef __new_alloc __sgi_alloc;
williamr@4
   285
#    endif /* _STLP_DEBUG_ALLOC */
williamr@4
   286
williamr@4
   287
typedef __new_alloc __single_client_alloc;
williamr@4
   288
typedef __new_alloc __multithreaded_alloc;
williamr@4
   289
williamr@4
   290
#  elif defined (_STLP_USE_MALLOC)
williamr@4
   291
williamr@4
   292
#    if defined (_STLP_DEBUG_ALLOC)
williamr@4
   293
typedef __debug_alloc<__malloc_alloc> __sgi_alloc;
williamr@4
   294
#    else
williamr@4
   295
typedef __malloc_alloc __sgi_alloc;
williamr@4
   296
#    endif /* _STLP_DEBUG_ALLOC */
williamr@4
   297
williamr@4
   298
typedef __malloc_alloc __single_client_alloc;
williamr@4
   299
typedef __malloc_alloc __multithreaded_alloc;
williamr@4
   300
williamr@4
   301
#  else
williamr@4
   302
williamr@4
   303
#    if defined (_STLP_DEBUG_ALLOC)
williamr@4
   304
typedef __debug_alloc<__node_alloc> __sgi_alloc;
williamr@4
   305
#    else
williamr@4
   306
typedef __node_alloc __sgi_alloc;
williamr@4
   307
#    endif
williamr@4
   308
williamr@4
   309
typedef __node_alloc __single_client_alloc;
williamr@4
   310
typedef __node_alloc __multithreaded_alloc;
williamr@4
   311
williamr@4
   312
#  endif /* _STLP_USE_NEWALLOC */
williamr@4
   313
#endif /* _STLP_USE_PERTHREAD_ALLOC */
williamr@4
   314
williamr@4
   315
// This implements allocators as specified in the C++ standard.
williamr@4
   316
//
williamr@4
   317
// Note that standard-conforming allocators use many language features
williamr@4
   318
// that are not yet widely implemented.  In particular, they rely on
williamr@4
   319
// member templates, partial specialization, partial ordering of function
williamr@4
   320
// templates, the typename keyword, and the use of the template keyword
williamr@4
   321
// to refer to a template member of a dependent type.
williamr@4
   322
williamr@4
   323
/*
williamr@4
   324
template <class _Tp>
williamr@4
   325
struct _AllocatorAux {
williamr@4
   326
  typedef _Tp*       pointer;
williamr@4
   327
  typedef const _Tp* const_pointer;
williamr@4
   328
  typedef _Tp&       reference;
williamr@4
   329
  typedef const _Tp& const_reference;
williamr@4
   330
williamr@4
   331
  pointer address(reference __x) const {return &__x;}
williamr@4
   332
  const_pointer address(const_reference __x) const { return &__x; }
williamr@4
   333
};
williamr@4
   334
williamr@4
   335
template <class _Tp>
williamr@4
   336
struct _AllocatorAux<const _Tp> {
williamr@4
   337
  typedef _Tp*       pointer;
williamr@4
   338
  typedef const _Tp* const_pointer;
williamr@4
   339
  typedef _Tp&       reference;
williamr@4
   340
  typedef const _Tp& const_reference;
williamr@4
   341
williamr@4
   342
  const_pointer address(const_reference __x) const { return &__x; }
williamr@4
   343
};
williamr@4
   344
*/
williamr@4
   345
williamr@4
   346
template <class _Tp>
williamr@4
   347
class allocator //: public _AllocatorAux<_Tp>
williamr@4
   348
/* A small helper struct to recognize STLport allocator implementation
williamr@4
   349
 * from any user specialization one.
williamr@4
   350
 */
williamr@4
   351
                : public __stlport_class<allocator<_Tp> > {
williamr@4
   352
public:
williamr@4
   353
  typedef _Tp        value_type;
williamr@4
   354
  typedef _Tp*       pointer;
williamr@4
   355
  typedef const _Tp* const_pointer;
williamr@4
   356
  typedef _Tp&       reference;
williamr@4
   357
  typedef const _Tp& const_reference;
williamr@4
   358
  typedef size_t     size_type;
williamr@4
   359
  typedef ptrdiff_t  difference_type;
williamr@4
   360
#if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
williamr@4
   361
  template <class _Tp1> struct rebind {
williamr@4
   362
    typedef allocator<_Tp1> other;
williamr@4
   363
  };
williamr@4
   364
#endif
williamr@4
   365
  allocator() _STLP_NOTHROW {}
williamr@4
   366
#if defined (_STLP_MEMBER_TEMPLATES)
williamr@4
   367
  template <class _Tp1> allocator(const allocator<_Tp1>&) _STLP_NOTHROW {}
williamr@4
   368
#endif
williamr@4
   369
  allocator(const allocator<_Tp>&) _STLP_NOTHROW {}
williamr@4
   370
  allocator(__move_source<allocator<_Tp> > src) _STLP_NOTHROW {}
williamr@4
   371
  ~allocator() _STLP_NOTHROW {}
williamr@4
   372
  pointer address(reference __x) const {return &__x;}
williamr@4
   373
  const_pointer address(const_reference __x) const { return &__x; }
williamr@4
   374
  // __n is permitted to be 0.  The C++ standard says nothing about what the return value is when __n == 0.
williamr@4
   375
  _Tp* allocate(size_type __n, const void* = 0) {
williamr@4
   376
    if (__n > max_size()) {
williamr@4
   377
      __THROW_BAD_ALLOC;
williamr@4
   378
    }
williamr@4
   379
    if (__n != 0) {
williamr@4
   380
      size_type __buf_size = __n * sizeof(value_type);
williamr@4
   381
      _Tp* __ret = __REINTERPRET_CAST(_Tp*, __sgi_alloc::allocate(__buf_size));
williamr@4
   382
#if defined (_STLP_DEBUG_UNINITIALIZED) && !defined (_STLP_DEBUG_ALLOC)
williamr@4
   383
      if (__ret != 0) {
williamr@4
   384
        memset((char*)__ret, _STLP_SHRED_BYTE, __buf_size);
williamr@4
   385
      }
williamr@4
   386
#endif
williamr@4
   387
      return __ret;
williamr@4
   388
    }
williamr@4
   389
    else
williamr@4
   390
      return 0;
williamr@4
   391
  }
williamr@4
   392
  // __p is permitted to be a null pointer, only if n==0.
williamr@4
   393
  void deallocate(pointer __p, size_type __n) {
williamr@4
   394
    _STLP_ASSERT( (__p == 0) == (__n == 0) )
williamr@4
   395
    if (__p != 0) {
williamr@4
   396
#if defined (_STLP_DEBUG_UNINITIALIZED) && !defined (_STLP_DEBUG_ALLOC)
williamr@4
   397
      memset((char*)__p, _STLP_SHRED_BYTE, __n * sizeof(value_type));
williamr@4
   398
#endif
williamr@4
   399
      __sgi_alloc::deallocate((void*)__p, __n * sizeof(value_type));
williamr@4
   400
    }
williamr@4
   401
  }
williamr@4
   402
  // backwards compatibility
williamr@4
   403
  void deallocate(pointer __p) const {  if (__p != 0) __sgi_alloc::deallocate((void*)__p, sizeof(value_type)); }
williamr@4
   404
  size_type max_size() const _STLP_NOTHROW  { return size_t(-1) / sizeof(value_type); }
williamr@4
   405
  void construct(pointer __p, const_reference __val) { _STLP_STD::_Copy_Construct(__p, __val); }
williamr@4
   406
  void destroy(pointer __p) { _STLP_STD::_Destroy(__p); }
williamr@4
   407
#if defined(__MRC__)||(defined(__SC__) && !defined(__DMC__))
williamr@4
   408
  template <class _T2> bool operator==(const allocator<_T2>&) const _STLP_NOTHROW { return true; }
williamr@4
   409
  template <class _T2> bool operator!=(const allocator<_T2>&) const _STLP_NOTHROW { return false; }
williamr@4
   410
#endif
williamr@4
   411
williamr@4
   412
#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
williamr@4
   413
  //This is just to make swap workaround for compiler without template function partial
williamr@4
   414
  //happy.
williamr@4
   415
  void swap(allocator<_Tp>&) {}
williamr@4
   416
#endif
williamr@4
   417
williamr@4
   418
#if defined (_STLP_NO_EXTENSIONS)
williamr@4
   419
  /* STLport extension giving rounded size of an allocated memory buffer
williamr@4
   420
   * This method do not have to be part of a user defined allocator implementation
williamr@4
   421
   * and won't even be called if such a function was granted.
williamr@4
   422
   */
williamr@4
   423
protected:
williamr@4
   424
#endif
williamr@4
   425
  _Tp* allocate(size_type __n, size_type& __allocated_n) {
williamr@4
   426
    if (__n > max_size()) {
williamr@4
   427
      __THROW_BAD_ALLOC;
williamr@4
   428
    }
williamr@4
   429
williamr@4
   430
    if (__n != 0) {
williamr@4
   431
      size_type __buf_size = __n * sizeof(value_type);
williamr@4
   432
      _Tp* __ret = __REINTERPRET_CAST(_Tp*, __sgi_alloc::allocate(__buf_size));
williamr@4
   433
#if defined (_STLP_DEBUG_UNINITIALIZED) && !defined (_STLP_DEBUG_ALLOC)
williamr@4
   434
      if (__ret != 0) {
williamr@4
   435
        memset((char*)__ret, _STLP_SHRED_BYTE, __buf_size);
williamr@4
   436
      }
williamr@4
   437
#endif
williamr@4
   438
      __allocated_n = __buf_size / sizeof(value_type);
williamr@4
   439
      return __ret;
williamr@4
   440
    }
williamr@4
   441
    else
williamr@4
   442
      return 0;
williamr@4
   443
  }
williamr@4
   444
};
williamr@4
   445
williamr@4
   446
_STLP_TEMPLATE_NULL
williamr@4
   447
class _STLP_CLASS_DECLSPEC allocator<void> {
williamr@4
   448
public:
williamr@4
   449
  typedef size_t      size_type;
williamr@4
   450
  typedef ptrdiff_t   difference_type;
williamr@4
   451
  typedef void*       pointer;
williamr@4
   452
  typedef const void* const_pointer;
williamr@4
   453
#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
williamr@4
   454
  typedef void        value_type;
williamr@4
   455
#endif
williamr@4
   456
#if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
williamr@4
   457
  template <class _Tp1> struct rebind {
williamr@4
   458
    typedef allocator<_Tp1> other;
williamr@4
   459
  };
williamr@4
   460
#endif
williamr@4
   461
#if defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__))  //*ty 03/24/2001 - MPW compilers get confused on these operator definitions
williamr@4
   462
  template <class _T2> bool operator==(const allocator<_T2>&) const _STLP_NOTHROW { return true; }
williamr@4
   463
  template <class _T2> bool operator!=(const allocator<_T2>&) const _STLP_NOTHROW { return false; }
williamr@4
   464
#endif
williamr@4
   465
};
williamr@4
   466
williamr@4
   467
#if !(defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__)))  //*ty 03/24/2001 - MPW compilers get confused on these operator definitions
williamr@4
   468
template <class _T1, class _T2> inline bool  _STLP_CALL operator==(const allocator<_T1>&, const allocator<_T2>&) _STLP_NOTHROW { return true; }
williamr@4
   469
template <class _T1, class _T2> inline bool  _STLP_CALL operator!=(const allocator<_T1>&, const allocator<_T2>&) _STLP_NOTHROW { return false; }
williamr@4
   470
#endif
williamr@4
   471
williamr@4
   472
#if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@4
   473
_STLP_EXPORT_TEMPLATE_CLASS allocator<char>;
williamr@4
   474
#  if defined (_STLP_HAS_WCHAR_T)
williamr@4
   475
_STLP_EXPORT_TEMPLATE_CLASS allocator<wchar_t>;
williamr@4
   476
#  endif
williamr@4
   477
#  if defined (_STLP_USE_PTR_SPECIALIZATIONS)
williamr@4
   478
_STLP_EXPORT_TEMPLATE_CLASS allocator<void*>;
williamr@4
   479
#  endif
williamr@4
   480
#endif
williamr@4
   481
williamr@4
   482
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@4
   483
williamr@4
   484
template <class _Tp>
williamr@4
   485
struct __alloc_type_traits {
williamr@4
   486
#if !defined (__BORLANDC__)
williamr@4
   487
  typedef typename _IsSTLportClass<allocator<_Tp> >::_Ret _STLportAlloc;
williamr@4
   488
#else
williamr@4
   489
  enum { _Is = _IsSTLportClass<allocator<_Tp> >::_Is };
williamr@4
   490
  typedef typename __bool2type<_Is>::_Ret _STLportAlloc;
williamr@4
   491
#endif
williamr@4
   492
  //The default allocator implementation which is recognize thanks to the
williamr@4
   493
  //__stlport_class inheritance is a stateless object so:
williamr@4
   494
  typedef _STLportAlloc has_trivial_default_constructor;
williamr@4
   495
  typedef _STLportAlloc has_trivial_copy_constructor;
williamr@4
   496
  typedef _STLportAlloc has_trivial_assignment_operator;
williamr@4
   497
  typedef _STLportAlloc has_trivial_destructor;
williamr@4
   498
  typedef _STLportAlloc is_POD_type;
williamr@4
   499
};
williamr@4
   500
williamr@4
   501
_STLP_MOVE_TO_STD_NAMESPACE
williamr@4
   502
williamr@4
   503
#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
williamr@4
   504
template <class _Tp>
williamr@4
   505
struct __type_traits<allocator<_Tp> > : _STLP_PRIV __alloc_type_traits<_Tp> {};
williamr@4
   506
#else
williamr@4
   507
_STLP_TEMPLATE_NULL
williamr@4
   508
struct __type_traits<allocator<char> > : _STLP_PRIV __alloc_type_traits<char> {};
williamr@4
   509
#  if defined (_STLP_HAS_WCHAR_T)
williamr@4
   510
_STLP_TEMPLATE_NULL
williamr@4
   511
struct __type_traits<allocator<wchar_t> > : _STLP_PRIV __alloc_type_traits<wchar_t> {};
williamr@4
   512
#  endif
williamr@4
   513
#  if defined (_STLP_USE_PTR_SPECIALIZATIONS)
williamr@4
   514
_STLP_TEMPLATE_NULL
williamr@4
   515
struct __type_traits<allocator<void*> > : _STLP_PRIV __alloc_type_traits<void*> {};
williamr@4
   516
#  endif
williamr@4
   517
#endif
williamr@4
   518
williamr@4
   519
williamr@4
   520
#if !defined (_STLP_FORCE_ALLOCATORS)
williamr@4
   521
#  define _STLP_FORCE_ALLOCATORS(a,y)
williamr@4
   522
#endif
williamr@4
   523
williamr@4
   524
#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_MEMBER_TEMPLATE_CLASSES)
williamr@4
   525
// The version for the default allocator, for rare occasion when we have partial spec w/o member template classes
williamr@4
   526
template <class _Tp, class _Tp1>
williamr@4
   527
struct _Alloc_traits<_Tp, allocator<_Tp1> > {
williamr@4
   528
  typedef allocator<_Tp1> _Orig;
williamr@4
   529
  typedef allocator<_Tp> allocator_type;
williamr@4
   530
  static allocator_type create_allocator(const allocator<_Tp1 >& __a)
williamr@4
   531
  { return allocator_type(_STLP_CONVERT_ALLOCATOR(__a, _Tp)); }
williamr@4
   532
};
williamr@4
   533
#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
williamr@4
   534
williamr@4
   535
#if !defined (_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE) && defined (_STLP_MEMBER_TEMPLATES)
williamr@4
   536
template <class _Tp, class _Alloc>
williamr@4
   537
inline _STLP_TYPENAME_ON_RETURN_TYPE _Alloc_traits<_Tp, _Alloc>::allocator_type  _STLP_CALL
williamr@4
   538
__stl_alloc_create(const _Alloc& __a, const _Tp*) {
williamr@4
   539
  typedef typename _Alloc::_STLP_TEMPLATE rebind<_Tp>::other _Rebound_type;
williamr@4
   540
  return _Rebound_type(__a);
williamr@4
   541
}
williamr@4
   542
#else
williamr@4
   543
// If custom allocators are being used without member template classes support :
williamr@4
   544
// user (on purpose) is forced to define rebind/get operations !!!
williamr@4
   545
template <class _Tp1, class _Tp2>
williamr@4
   546
inline allocator<_Tp2>& _STLP_CALL
williamr@4
   547
__stl_alloc_rebind(allocator<_Tp1>& __a, const _Tp2*) {  return (allocator<_Tp2>&)(__a); }
williamr@4
   548
template <class _Tp1, class _Tp2>
williamr@4
   549
inline allocator<_Tp2> _STLP_CALL
williamr@4
   550
__stl_alloc_create(const allocator<_Tp1>&, const _Tp2*) { return allocator<_Tp2>(); }
williamr@4
   551
#endif /* _STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE */
williamr@4
   552
williamr@4
   553
#if defined (_STLP_USE_RAW_SGI_ALLOCATORS)
williamr@4
   554
// move obsolete stuff out of the way
williamr@4
   555
#  include <stl/_alloc_old.h>
williamr@4
   556
#endif
williamr@4
   557
williamr@4
   558
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@4
   559
williamr@4
   560
// inheritance is being used for EBO optimization
williamr@4
   561
template <class _Value, class _Tp, class _MaybeReboundAlloc>
williamr@4
   562
class _STLP_alloc_proxy : public _MaybeReboundAlloc {
williamr@4
   563
private:
williamr@4
   564
  typedef _MaybeReboundAlloc _Base;
williamr@4
   565
  typedef typename _Base::size_type size_type;
williamr@4
   566
  typedef _STLP_alloc_proxy<_Value, _Tp, _MaybeReboundAlloc> _Self;
williamr@4
   567
public:
williamr@4
   568
  _Value _M_data;
williamr@4
   569
williamr@4
   570
  _STLP_alloc_proxy (const _MaybeReboundAlloc& __a, _Value __p) :
williamr@4
   571
    _MaybeReboundAlloc(__a), _M_data(__p) {}
williamr@4
   572
williamr@4
   573
  _STLP_alloc_proxy (__move_source<_Self> src) :
williamr@4
   574
    _MaybeReboundAlloc(_STLP_PRIV _AsMoveSource<_Base>(src.get())),
williamr@4
   575
    _M_data(_STLP_PRIV _AsMoveSource<_Value>(src.get()._M_data)) {}
williamr@4
   576
williamr@4
   577
  /* We need to define the following swap implementation for allocator with state
williamr@4
   578
   * as those allocators might have implement a special swap function to correctly
williamr@4
   579
   * move datas from an instance to the oher, _STLP_alloc_proxy should not break
williamr@4
   580
   * this mecanism.
williamr@4
   581
   */
williamr@4
   582
  void _M_swap_alloc(_Self& __x) {
williamr@4
   583
    _MaybeReboundAlloc &__base_this = *this;
williamr@4
   584
    _MaybeReboundAlloc &__base_x = __x;
williamr@4
   585
    _STLP_STD::swap(__base_this, __base_x);
williamr@4
   586
  }
williamr@4
   587
williamr@4
   588
  void swap(_Self& __x) {
williamr@4
   589
    _M_swap_alloc(__x);
williamr@4
   590
    _STLP_STD::swap(_M_data, __x._M_data);
williamr@4
   591
  }
williamr@4
   592
williamr@4
   593
  _Tp* allocate(size_type __n, size_type& __allocated_n) {
williamr@4
   594
#if !defined (__BORLANDC__)
williamr@4
   595
    typedef typename _IsSTLportClass<_MaybeReboundAlloc>::_Ret _STLportAlloc;
williamr@4
   596
#else
williamr@4
   597
    typedef typename __bool2type<_IsSTLportClass<_MaybeReboundAlloc>::_Is>::_Ret _STLportAlloc;
williamr@4
   598
#endif
williamr@4
   599
    return allocate(__n, __allocated_n, _STLportAlloc());
williamr@4
   600
  }
williamr@4
   601
williamr@4
   602
  // Unified interface to perform allocate()/deallocate() with limited
williamr@4
   603
  // language support
williamr@4
   604
#if defined (_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE)
williamr@4
   605
  // else it is rebound already, and allocate() member is accessible
williamr@4
   606
  _Tp* allocate(size_type __n)
williamr@4
   607
  { return __stl_alloc_rebind(__STATIC_CAST(_Base&, *this), __STATIC_CAST(_Tp*, 0)).allocate(__n, 0); }
williamr@4
   608
  void deallocate(_Tp* __p, size_type __n)
williamr@4
   609
  { __stl_alloc_rebind(__STATIC_CAST(_Base&, *this), __STATIC_CAST(_Tp*, 0)).deallocate(__p, __n); }
williamr@4
   610
private:
williamr@4
   611
  _Tp* allocate(size_type __n, size_type& __allocated_n, const __true_type& /*STLport allocator*/)
williamr@4
   612
  { return __stl_alloc_rebind(__STATIC_CAST(_Base&, *this), __STATIC_CAST(_Tp*, 0)).allocate(__n, __allocated_n); }
williamr@4
   613
#else
williamr@4
   614
  //Expose Standard allocate overload (using expression do not work for some compilers (Borland))
williamr@4
   615
  _Tp* allocate(size_type __n)
williamr@4
   616
  { return _Base::allocate(__n); }
williamr@4
   617
private:
williamr@4
   618
  _Tp* allocate(size_type __n, size_type& __allocated_n, const __true_type& /*STLport allocator*/)
williamr@4
   619
  { return _Base::allocate(__n, __allocated_n); }
williamr@4
   620
#endif
williamr@4
   621
williamr@4
   622
  _Tp* allocate(size_type __n, size_type& __allocated_n, const __false_type& /*STLport allocator*/)
williamr@4
   623
  { __allocated_n = __n; return allocate(__n); }
williamr@4
   624
};
williamr@4
   625
williamr@4
   626
#if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@4
   627
_STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<char*, char, allocator<char> >;
williamr@4
   628
#  if defined (_STLP_HAS_WCHAR_T)
williamr@4
   629
_STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<wchar_t*, wchar_t, allocator<wchar_t> >;
williamr@4
   630
#  endif
williamr@4
   631
#  if defined (_STLP_USE_PTR_SPECIALIZATIONS)
williamr@4
   632
_STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<void**, void*, allocator<void*> >;
williamr@4
   633
#  endif
williamr@4
   634
#endif
williamr@4
   635
williamr@4
   636
_STLP_MOVE_TO_STD_NAMESPACE
williamr@4
   637
_STLP_END_NAMESPACE
williamr@4
   638
williamr@4
   639
#if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
williamr@4
   640
#  include <stl/_alloc.c>
williamr@4
   641
#endif
williamr@4
   642
williamr@4
   643
#endif /* _STLP_INTERNAL_ALLOC_H */
williamr@4
   644
williamr@4
   645
// Local Variables:
williamr@4
   646
// mode:C++
williamr@4
   647
// End:
williamr@4
   648