_alloc.h

来自「symbian上STL模板库的实现」· C头文件 代码 · 共 531 行 · 第 1/2 页

H
531
字号
//# if defined (_STLP_USE_PERTHREAD_ALLOC)//_STLP_END_NAMESPACE//// include additional header here//# include <stl/_pthread_alloc.h>_STLP_BEGIN_NAMESPACE////#  if defined ( _STLP_DEBUG_ALLOC )//typedef __debug_alloc<__pthread_alloc> __sgi_alloc;//#  else//typedef __pthread_alloc __sgi_alloc;//#  endif /* _STLP_DEBUG_ALLOC */////typedef __pthread_alloc __single_client_alloc;//typedef __pthread_alloc __multithreaded_alloc;////# else////# if defined ( _STLP_USE_NEWALLOC )////#  if defined ( _STLP_DEBUG_ALLOC )//typedef __debug_alloc<__new_alloc> __sgi_alloc;//#  else//typedef __new_alloc __sgi_alloc;//#  endif /* _STLP_DEBUG_ALLOC */////typedef __new_alloc __single_client_alloc;//typedef __new_alloc __multithreaded_alloc;////#  elif defined (_STLP_USE_MALLOC)////#   if defined ( _STLP_DEBUG_ALLOC )//typedef __debug_alloc<__malloc_alloc<0> > __sgi_alloc;//#   else//typedef __malloc_alloc<0> __sgi_alloc;//#   endif /* _STLP_DEBUG_ALLOC */////typedef __malloc_alloc<0> __single_client_alloc;//typedef __malloc_alloc<0> __multithreaded_alloc;////# else////#   if defined ( _STLP_DEBUG_ALLOC )//typedef __debug_alloc<_Node_alloc> __sgi_alloc;//#   else//typedef _Node_alloc __sgi_alloc;//#   endif////typedef __node_alloc<false, 0> __single_client_alloc;//typedef __node_alloc<true, 0>  __multithreaded_alloc;////#  endif /* _STLP_USE_NEWALLOC *///# endif /* PTHREAD_ALLOC */////// This implements allocators as specified in the C++ standard.  //////// Note that standard-conforming allocators use many language features//// that are not yet widely implemented.  In particular, they rely on//// member templates, partial specialization, partial ordering of function//// templates, the typename keyword, and the use of the template keyword//// to refer to a template member of a dependent type.////template <class _Tp>//class allocator {//public:////  typedef _Tp        value_type;//  typedef value_type *       pointer;//  typedef const _Tp* const_pointer;//  typedef _Tp&       reference;//  typedef const _Tp& const_reference;//  typedef size_t     size_type;//  typedef ptrdiff_t  difference_type;//# if defined (_STLP_MEMBER_TEMPLATE_CLASSES)//  template <class _Tp1> struct rebind {//    typedef allocator<_Tp1> other;//  };//# endif//  allocator() _STLP_NOTHROW {}// # if defined (_STLP_MEMBER_TEMPLATES)//  template <class _Tp1> allocator(const allocator<_Tp1>&) _STLP_NOTHROW {}// # endif    //  allocator(const allocator<_Tp>&) _STLP_NOTHROW {}//  ~allocator() _STLP_NOTHROW {}//  pointer address(reference __x) const { return &__x; }//  const_pointer address(const_reference __x) const { return &__x; }//  // __n is permitted to be 0.  The C++ standard says nothing about what the return value is when __n == 0.//  _Tp* allocate(size_type __n, const void* = 0) { //    return __n != 0 ? __REINTERPRET_CAST(value_type*,__sgi_alloc::allocate(__n * sizeof(value_type))) : 0;//  }//  // __p is permitted to be a null pointer, only if n==0.//  void deallocate(pointer __p, size_type __n) {//    _STLP_ASSERT( (__p == 0) == (__n == 0) )//      if (__p != 0) __sgi_alloc::deallocate((void*)__p, __n * sizeof(value_type));//  }//  // backwards compatibility//  void deallocate(pointer __p) const {  if (__p != 0) __sgi_alloc::deallocate((void*)__p, sizeof(value_type)); }//  size_type max_size() const _STLP_NOTHROW  { return size_t(-1) / sizeof(value_type); }//  void construct(pointer __p, const _Tp& __val) { _STLP_STD::_Construct(__p, __val); }//  void destroy(pointer __p) { _STLP_STD::_Destroy(__p); }//# if defined(__MRC__)||(defined(__SC__) && !defined(__DMC__))//  template <class _T2> bool operator==(const allocator<_T2>&) const  _STLP_NOTHROW { return true; }//  template <class _T2> bool operator!=(const allocator<_T2>&) const _STLP_NOTHROW { return false; }//# endif//};////_STLP_TEMPLATE_NULL//class _STLP_CLASS_DECLSPEC allocator<void> {//public://  typedef size_t      size_type;//  typedef ptrdiff_t   difference_type;//  typedef void*       pointer;//  typedef const void* const_pointer;//# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)//  typedef void        value_type;//# endif//# if defined (_STLP_MEMBER_TEMPLATE_CLASSES)//  template <class _Tp1> struct rebind {//    typedef allocator<_Tp1> other;//  };//# endif//# if defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__))		//*ty 03/24/2001 - MPW compilers get confused on these operator definitions//  template <class _T2> bool operator==(const allocator<_T2>&) const _STLP_NOTHROW { return true; }//  template <class _T2> bool operator!=(const allocator<_T2>&) const _STLP_NOTHROW { return false; }//# endif//};////#if !(defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__)))		//*ty 03/24/2001 - MPW compilers get confused on these operator definitions//template <class _T1, class _T2> inline bool  _STLP_CALL operator==(const allocator<_T1>&, const allocator<_T2>&) _STLP_NOTHROW { return true; }//template <class _T1, class _T2> inline bool  _STLP_CALL operator!=(const allocator<_T1>&, const allocator<_T2>&) _STLP_NOTHROW { return false; }//#endif////# if defined (_STLP_USE_TEMPLATE_EXPORT)//_STLP_EXPORT_TEMPLATE_CLASS allocator<char>;//#  if defined (_STLP_HAS_WCHAR_T)//_STLP_EXPORT_TEMPLATE_CLASS allocator<wchar_t>;//#  endif//# endif /* _STLP_USE_TEMPLATE_EXPORT */// Another allocator adaptor: _Alloc_traits.  This serves two// purposes.  First, make it possible to write containers that can use// either SGI-style allocators or standard-conforming allocator.// The fully general version.template <class _Tp, class _Allocator>struct _Alloc_traits{    typedef _Allocator _Orig;# if defined (_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM)     typedef typename _Allocator::_STLP_TEMPLATE rebind<_Tp> _Rebind_type;    typedef typename _Rebind_type::other  allocator_type;    static allocator_type create_allocator(const _Orig& __a) { return allocator_type(__a); }# else    // this is not actually true, used only to pass this type through    // to dynamic overload selection in _STLP_alloc_proxy methods    typedef _Allocator allocator_type;# endif /* _STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM */};#ifndef _STLP_FORCE_ALLOCATORS#define _STLP_FORCE_ALLOCATORS(a,y) #endif#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && ! defined (_STLP_MEMBER_TEMPLATE_CLASSES)// The version for the default allocator, for rare occasion when we have partial spec w/o member template classestemplate <class _Tp, class _Tp1>struct _Alloc_traits<_Tp, allocator<_Tp1> > {    typedef allocator<_Tp1> _Orig;    typedef allocator<_Tp> allocator_type;    static allocator_type create_allocator(const allocator<_Tp1 >& __a) { return allocator_type(__a); }};#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION *//* macro to convert the allocator for initialization * not using MEMBER_TEMPLATE_CLASSES as it should work given template constructor  */#if defined (_STLP_MEMBER_TEMPLATES) || ! defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)/* if _STLP_NO_TEMPLATE_CONVERSIONS is set, the member template constructor is * not used implicitly to convert allocator parameter, so let us do it explicitly */# if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_NO_TEMPLATE_CONVERSIONS)#  define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __stl_alloc_create(__a,(_Tp*)0)# else#  define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __a# endif/* else convert, but only if partial specialization works, since else * Container::allocator_type won't be different */#else #  define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __stl_alloc_create(__a,(_Tp*)0)#endif//# if defined (_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM) //template <class _Tp, class _Alloc>//inline _STLP_TYPENAME_ON_RETURN_TYPE _Alloc_traits<_Tp, _Alloc>::allocator_type  _STLP_CALL//__stl_alloc_create(const _Alloc& __a, const _Tp*) {//  typedef typename _Alloc::_STLP_TEMPLATE rebind<_Tp>::other _Rebound_type;//  return _Rebound_type(__a);//}//#else//// If custom allocators are being used without member template classes support ://// user (on purpose) is forced to define rebind/get operations !!!//template <class _Tp1, class _Tp2>//inline allocator<_Tp2>& _STLP_CALL//__stl_alloc_rebind(allocator<_Tp1>& __a, const _Tp2*) {  return (allocator<_Tp2>&)(__a); }//template <class _Tp1, class _Tp2>//inline allocator<_Tp2> _STLP_CALL//__stl_alloc_create(const allocator<_Tp1>&, const _Tp2*) { return allocator<_Tp2>(); }//#endif /* _STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM */////# ifdef _STLP_USE_RAW_SGI_ALLOCATORS//// move obsolete stuff out of the way//# include <stl/_alloc_old.h>//# endif//// inheritance is being used for EBO optimizationtemplate <class _Value, class _Tp, class _MaybeReboundAlloc>class _STLP_alloc_proxy : public _MaybeReboundAlloc {    private:        typedef _MaybeReboundAlloc _Base;        typedef _STLP_alloc_proxy<_Value, _Tp, _MaybeReboundAlloc> _Self;    public:        _Value _M_data;        inline _STLP_alloc_proxy(const _MaybeReboundAlloc& __a, _Value __p) : _MaybeReboundAlloc(__a), _M_data(__p) {}# if 0        inline _STLP_alloc_proxy(const _Self& __x) : _MaybeReboundAlloc(__x), _M_data(__x._M_data) {}         // construction/destruction        inline _Self& operator = (const _Self& __x) {             *(_MaybeReboundAlloc*)this = *(_MaybeReboundAlloc*)__x;            _M_data = __x._M_data; return *this;         }         inline _Self& operator = (const _Base& __x) { ((_Base&)*this) = __x; return *this; } # endif        // Unified interface to perform allocate()/deallocate() with limited        // language support#if ! defined (_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM)        // else it is rebound already, and allocate() member is accessible        inline _Tp* allocate(size_t __n) {             return __stl_alloc_rebind(__STATIC_CAST(_Base&,*this),(_Tp*)0).allocate(__n,0);         }        inline void deallocate(_Tp* __p, size_t __n) {             __stl_alloc_rebind(__STATIC_CAST(_Base&, *this),(_Tp*)0).deallocate(__p, __n);         }#endif /* !_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM */};# if defined (_STLP_USE_TEMPLATE_EXPORT)_STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<char *,char,allocator<char> >;#  if defined (_STLP_HAS_WCHAR_T)_STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<wchar_t *,wchar_t,allocator<wchar_t> >;#  endif# endif /* _STLP_USE_TEMPLATE_EXPORT *///# undef _STLP_NODE_ALLOCATOR_THREADS//_STLP_END_NAMESPACE////# if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)//#  include <stl/_alloc.c>//# endif#endif /* _STLP_INTERNAL_ALLOC_H */// Local Variables:// mode:C++// End:

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?