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