epoc32/include/tools/stlport/stl/_alloc_old.h
branchSymbian2
changeset 2 2fe1408b6811
child 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/tools/stlport/stl/_alloc_old.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,287 @@
     1.4 +template<class _Tp, class _Alloc>
     1.5 +class __simple_alloc {
     1.6 +  typedef _Alloc __alloc_type;
     1.7 +public:
     1.8 +  typedef typename _Alloc::value_type __alloc_value_type;
     1.9 +  typedef _Tp value_type;
    1.10 +  static size_t  _STLP_CALL __chunk(size_t __n) {
    1.11 +    return (sizeof(__alloc_value_type)==sizeof(value_type)) ? __n :
    1.12 +      ((__n*sizeof(value_type)+sizeof(__alloc_value_type)-1)/sizeof(__alloc_value_type));
    1.13 +  }
    1.14 +  static _Tp*  _STLP_CALL allocate(size_t __n) { return 0 == __n ? 0 : (_Tp*) __alloc_type::allocate(__chunk(__n)); }
    1.15 +  static void  _STLP_CALL deallocate(_Tp * __p, size_t __n) {
    1.16 +    __alloc_type::deallocate((__alloc_value_type*)__p, __chunk(__n)); }
    1.17 +};
    1.18 +
    1.19 +// Allocator adaptor to turn an SGI-style allocator (e.g. alloc, malloc_alloc)
    1.20 +// into a standard-conforming allocator.   Note that this adaptor does
    1.21 +// *not* assume that all objects of the underlying alloc class are
    1.22 +// identical, nor does it assume that all of the underlying alloc's
    1.23 +// member functions are static member functions.  Note, also, that
    1.24 +// __allocator<_Tp, alloc> is essentially the same thing as allocator<_Tp>.
    1.25 +
    1.26 +template <class _Tp, class _Alloc>
    1.27 +struct __allocator : public _Alloc {
    1.28 +  typedef _Alloc __underlying_alloc;
    1.29 +
    1.30 +  typedef size_t    size_type;
    1.31 +  typedef ptrdiff_t difference_type;
    1.32 +  typedef _Tp*       pointer;
    1.33 +  typedef const _Tp* const_pointer;
    1.34 +  typedef _Tp&       reference;
    1.35 +  typedef const _Tp& const_reference;
    1.36 +  typedef _Tp        value_type;
    1.37 +
    1.38 +# if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
    1.39 +  template <class _Tp1> struct rebind {
    1.40 +    typedef __allocator<_Tp1, _Alloc> other;
    1.41 +  };
    1.42 +# endif
    1.43 +  __allocator() _STLP_NOTHROW {}
    1.44 +  __allocator(const _Alloc& ) _STLP_NOTHROW {}
    1.45 +  __allocator(const __allocator<_Tp, _Alloc>& __a) _STLP_NOTHROW
    1.46 +    : _Alloc(__a) {}
    1.47 +# if defined (_STLP_MEMBER_TEMPLATES) && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
    1.48 +  template <class _Tp1>
    1.49 +  __allocator(const __allocator<_Tp1, _Alloc>& __a) _STLP_NOTHROW
    1.50 +    : _Alloc(__a) {}
    1.51 +# endif
    1.52 +# ifdef _STLP_TRIVIAL_DESTRUCTOR_BUG
    1.53 +  ~__allocator() _STLP_NOTHROW {}
    1.54 +# endif
    1.55 +  pointer address(reference __x) const { return &__x; }
    1.56 +
    1.57 +# if !defined (__WATCOM_CPLUSPLUS__)
    1.58 +  const_pointer address(const_reference __x) const { return &__x; }
    1.59 +# endif
    1.60 +
    1.61 +  // __n is permitted to be 0.
    1.62 +  _Tp* allocate(size_type __n, const void* = 0) {
    1.63 +    if (__n > max_size())
    1.64 +      __THROW_BAD_ALLOC;
    1.65 +    return __n != 0
    1.66 +        ? __STATIC_CAST(_Tp*,__underlying_alloc::allocate(__n * sizeof(_Tp)))
    1.67 +        : 0;
    1.68 +  }
    1.69 +
    1.70 +  // __p is not permitted to be a null pointer.
    1.71 +  void deallocate(pointer __p, size_type __n)
    1.72 +    { if (__p) __underlying_alloc::deallocate(__p, __n * sizeof(_Tp)); }
    1.73 +
    1.74 +  size_type max_size() const _STLP_NOTHROW
    1.75 +    { return size_t(-1) / sizeof(_Tp); }
    1.76 +
    1.77 +  void construct(pointer __p, const_reference __val) { _STLP_STD::_Copy_Construct(__p, __val); }
    1.78 +  void destroy(pointer __p) { _STLP_STD::_Destroy(__p); }
    1.79 +
    1.80 +  const __underlying_alloc& __get_underlying_alloc() const { return *this; }
    1.81 +};
    1.82 +
    1.83 +#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
    1.84 +template <class _Alloc>
    1.85 +class __allocator<void, _Alloc> {
    1.86 +  typedef size_t      size_type;
    1.87 +  typedef ptrdiff_t   difference_type;
    1.88 +  typedef void*       pointer;
    1.89 +  typedef const void* const_pointer;
    1.90 +  typedef void        value_type;
    1.91 +#ifdef _STLP_MEMBER_TEMPLATE_CLASSES
    1.92 +  template <class _Tp1> struct rebind {
    1.93 +    typedef __allocator<_Tp1, _Alloc> other;
    1.94 +  };
    1.95 +#endif
    1.96 +};
    1.97 +#endif
    1.98 +
    1.99 +template <class _Tp, class _Alloc>
   1.100 +inline bool  _STLP_CALL operator==(const __allocator<_Tp, _Alloc>& __a1,
   1.101 +                                   const __allocator<_Tp, _Alloc>& __a2)
   1.102 +{
   1.103 +  return __a1.__get_underlying_alloc() == __a2.__get_underlying_alloc();
   1.104 +}
   1.105 +
   1.106 +#ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
   1.107 +template <class _Tp, class _Alloc>
   1.108 +inline bool  _STLP_CALL operator!=(const __allocator<_Tp, _Alloc>& __a1,
   1.109 +                                   const __allocator<_Tp, _Alloc>& __a2)
   1.110 +{
   1.111 +  return __a1.__get_underlying_alloc() != __a2.__get_underlying_alloc();
   1.112 +}
   1.113 +#endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
   1.114 +
   1.115 +
   1.116 +// Comparison operators for all of the predifined SGI-style allocators.
   1.117 +// This ensures that __allocator<malloc_alloc> (for example) will
   1.118 +// work correctly.
   1.119 +
   1.120 +#ifndef _STLP_NON_TYPE_TMPL_PARAM_BUG
   1.121 +inline bool  _STLP_CALL operator==(const __malloc_alloc&, const __malloc_alloc&)
   1.122 +{ return true; }
   1.123 +
   1.124 +#  ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
   1.125 +inline bool  _STLP_CALL operator!=(const __malloc_alloc&, const __malloc_alloc&)
   1.126 +{ return false; }
   1.127 +#  endif
   1.128 +
   1.129 +inline bool _STLP_CALL operator==(const __new_alloc&, const __new_alloc&) { return true; }
   1.130 +
   1.131 +#  ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
   1.132 +inline bool _STLP_CALL operator!=(const __new_alloc&, const __new_alloc&) { return false; }
   1.133 +#  endif
   1.134 +
   1.135 +#  if !defined (_STLP_USE_NO_IOSTREAMS)
   1.136 +inline bool  _STLP_CALL operator==(const __node_alloc&,
   1.137 +                                   const __node_alloc&)
   1.138 +{ return true; }
   1.139 +
   1.140 +#    if defined( _STLP_FUNCTION_TMPL_PARTIAL_ORDER )
   1.141 +
   1.142 +inline bool  _STLP_CALL operator!=(const __node_alloc&,
   1.143 +                                   const __node_alloc&)
   1.144 +{ return false; }
   1.145 +#    endif
   1.146 +#  endif
   1.147 +
   1.148 +#endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
   1.149 +
   1.150 +template <class _Alloc>
   1.151 +inline bool  _STLP_CALL operator==(const __debug_alloc<_Alloc>&, const __debug_alloc<_Alloc>&) {  return true; }
   1.152 +# ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
   1.153 +template <class _Alloc>
   1.154 +inline bool  _STLP_CALL operator!=(const __debug_alloc<_Alloc>&, const __debug_alloc<_Alloc>&) {  return false; }
   1.155 +# endif
   1.156 +
   1.157 +#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
   1.158 +
   1.159 +// Versions for the predefined SGI-style allocators.
   1.160 +template <class _Tp>
   1.161 +struct _Alloc_traits<_Tp, __malloc_alloc> {
   1.162 +  typedef __allocator<_Tp, __malloc_alloc> allocator_type;
   1.163 +};
   1.164 +
   1.165 +#  if !defined (_STLP_USE_NO_IOSTREAMS)
   1.166 +template <class _Tp>
   1.167 +struct _Alloc_traits<_Tp, __node_alloc> {
   1.168 +  typedef __allocator<_Tp, __node_alloc> allocator_type;
   1.169 +};
   1.170 +#  endif
   1.171 +
   1.172 +template <class _Tp, class _Alloc>
   1.173 +struct _Alloc_traits<_Tp, __debug_alloc<_Alloc> > {
   1.174 +  typedef __allocator<_Tp, __debug_alloc<_Alloc> > allocator_type;
   1.175 +};
   1.176 +
   1.177 +// Versions for the __allocator adaptor used with the predefined
   1.178 +// SGI-style allocators.
   1.179 +
   1.180 +template <class _Tp, class _Tp1, class _Alloc>
   1.181 +struct _Alloc_traits<_Tp, __allocator<_Tp1, _Alloc > > {
   1.182 +  typedef __allocator<_Tp, _Alloc > allocator_type;
   1.183 +};
   1.184 +
   1.185 +#endif
   1.186 +
   1.187 +#if defined (_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE)
   1.188 +
   1.189 +// Versions for the predefined SGI-style allocators.
   1.190 +
   1.191 +
   1.192 +#  if defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
   1.193 +
   1.194 +typedef __malloc_alloc __malloc_alloc_dfl;
   1.195 +
   1.196 +template <class _Tp>
   1.197 +inline __allocator<_Tp, __malloc_alloc_dfl >& _STLP_CALL
   1.198 +__stl_alloc_rebind(__malloc_alloc_dfl& __a, const _Tp*) {
   1.199 +  return (__allocator<_Tp, __malloc_alloc_dfl >&)__a;
   1.200 +}
   1.201 +
   1.202 +#    if !defined (_STLP_USE_NO_IOSTREAMS)
   1.203 +template <class _Tp>
   1.204 +inline __allocator<_Tp, __node_alloc>& _STLP_CALL
   1.205 +__stl_alloc_rebind(__node_alloc& __a, const _Tp*) {
   1.206 +  return (__allocator<_Tp, __node_alloc>&)__a;
   1.207 +}
   1.208 +#    endif
   1.209 +
   1.210 +template <class _Tp>
   1.211 +inline __allocator<_Tp, __malloc_alloc_dfl > _STLP_CALL
   1.212 +__stl_alloc_create(const __malloc_alloc_dfl&, const _Tp*) {
   1.213 +  return __allocator<_Tp, __malloc_alloc_dfl > ();
   1.214 +}
   1.215 +
   1.216 +#    if !defined (_STLP_USE_NO_IOSTREAMS)
   1.217 +template <class _Tp>
   1.218 +inline __allocator<_Tp, __node_alloc> _STLP_CALL
   1.219 +__stl_alloc_create(const __node_alloc&, const _Tp*) {
   1.220 +  return __allocator<_Tp, __node_alloc>();
   1.221 +}
   1.222 +
   1.223 +#    endif
   1.224 +
   1.225 +#  else
   1.226 +
   1.227 +template <class _Tp>
   1.228 +inline __allocator<_Tp, __malloc_alloc>& _STLP_CALL
   1.229 +__stl_alloc_rebind(__malloc_alloc& __a, const _Tp*) {
   1.230 +  return (__allocator<_Tp, __malloc_alloc>&)__a;
   1.231 +}
   1.232 +
   1.233 +#    if !defined (_STLP_USE_NO_IOSTREAMS)
   1.234 +template <class _Tp>
   1.235 +inline __allocator<_Tp, __node_alloc>& _STLP_CALL
   1.236 +__stl_alloc_rebind(__node_alloc& __a, const _Tp*) {
   1.237 +  return (__allocator<_Tp, __node_alloc>&)__a;
   1.238 +}
   1.239 +#    endif
   1.240 +
   1.241 +template <class _Tp>
   1.242 +inline __allocator<_Tp, __malloc_alloc> _STLP_CALL
   1.243 +__stl_alloc_create(const __malloc_alloc&, const _Tp*) {
   1.244 +  return __allocator<_Tp, __malloc_alloc>();
   1.245 +}
   1.246 +
   1.247 +#    if !defined (_STLP_USE_NO_IOSTREAMS)
   1.248 +template <class _Tp>
   1.249 +inline __allocator<_Tp, __node_alloc> _STLP_CALL
   1.250 +__stl_alloc_create(const __node_alloc&, const _Tp*) {
   1.251 +  return __allocator<_Tp, __node_alloc>();
   1.252 +}
   1.253 +#    endif
   1.254 +
   1.255 +#  endif
   1.256 +
   1.257 +template <class _Tp, class _Alloc>
   1.258 +inline __allocator<_Tp, __debug_alloc<_Alloc> > _STLP_CALL
   1.259 +__stl_alloc_create(const __debug_alloc<_Alloc>&, const _Tp*) {
   1.260 +  return __allocator<_Tp, __debug_alloc<_Alloc> >();
   1.261 +}
   1.262 +template <class _Tp, class _Alloc>
   1.263 +inline __allocator<_Tp, __debug_alloc<_Alloc> >& _STLP_CALL
   1.264 +__stl_alloc_rebind(__debug_alloc<_Alloc>& __a, const _Tp*) {
   1.265 +  return (__allocator<_Tp, __debug_alloc<_Alloc> >&)__a;
   1.266 +}
   1.267 +
   1.268 +template <class _Tp>
   1.269 +inline __allocator<_Tp, __new_alloc > _STLP_CALL
   1.270 +__stl_alloc_create(const __new_alloc&, const _Tp*) {
   1.271 +  return __allocator<_Tp, __new_alloc >();
   1.272 +}
   1.273 +template <class _Tp>
   1.274 +inline __allocator<_Tp, __new_alloc >&  _STLP_CALL
   1.275 +__stl_alloc_rebind(__new_alloc& __a, const _Tp*) {
   1.276 +  return (__allocator<_Tp, __new_alloc >&)__a;
   1.277 +}
   1.278 +
   1.279 +template <class _Tp1, class _Alloc, class _Tp2>
   1.280 +inline __allocator<_Tp2, _Alloc>& _STLP_CALL
   1.281 +__stl_alloc_rebind(__allocator<_Tp1, _Alloc>& __a, const _Tp2*) {
   1.282 +  return (__allocator<_Tp2, _Alloc>&)__a;
   1.283 +}
   1.284 +
   1.285 +template <class _Tp1, class _Alloc, class _Tp2>
   1.286 +inline __allocator<_Tp2, _Alloc> _STLP_CALL
   1.287 +__stl_alloc_create(const __allocator<_Tp1, _Alloc>&, const _Tp2*) {
   1.288 +  return __allocator<_Tp2, _Alloc>();
   1.289 +}
   1.290 +#endif