1 #ifndef nsCppSharedAllocator_h__
2 #define nsCppSharedAllocator_h__
4 #include "nsMemory.h" // for |nsMemory|
5 #include NEW_H // to allow placement |new|
8 // under Metrowerks (Mac), we don't have autoconf yet
10 #define HAVE_CPP_MEMBER_TEMPLATES
11 #define HAVE_CPP_NUMERIC_LIMITS
14 // under MSVC shut off copious warnings about unused in-lines
16 #pragma warning( disable: 4514 )
19 #ifdef HAVE_CPP_NUMERIC_LIMITS
27 class nsCppSharedAllocator
29 ...allows Standard Library containers, et al, to use our global shared
30 (XP)COM-aware allocator.
35 typedef size_t size_type
;
36 typedef ptrdiff_t difference_type
;
39 typedef const T
* const_pointer
;
42 typedef const T
& const_reference
;
46 nsCppSharedAllocator() { }
48 #ifdef HAVE_CPP_MEMBER_TEMPLATES
50 nsCppSharedAllocator( const nsCppSharedAllocator
<U
>& ) { }
53 ~nsCppSharedAllocator() { }
57 address( reference r
) const
63 address( const_reference r
) const
69 allocate( size_type n
, const void* /*hint*/=0 )
71 return reinterpret_cast<pointer
>(nsMemory::Alloc(static_cast<PRUint32
>(n
*sizeof(T
))));
75 deallocate( pointer p
, size_type
/*n*/ )
81 construct( pointer p
, const T
& val
)
95 #ifdef HAVE_CPP_NUMERIC_LIMITS
96 return numeric_limits
<size_type
>::max() / sizeof(T
);
98 return ULONG_MAX
/ sizeof(T
);
102 #ifdef HAVE_CPP_MEMBER_TEMPLATES
106 typedef nsCppSharedAllocator
<U
> other
;
114 operator==( const nsCppSharedAllocator
<T
>&, const nsCppSharedAllocator
<T
>& )
121 operator!=( const nsCppSharedAllocator
<T
>&, const nsCppSharedAllocator
<T
>& )
126 #endif /* !defined(nsCppSharedAllocator_h__) */