Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / xpcom / ds / nsCppSharedAllocator.h
blobd9095c0fa31b0bb6af8745f015c2101f3ad635d5
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
9 #ifdef __MWERKS__
10 #define HAVE_CPP_MEMBER_TEMPLATES
11 #define HAVE_CPP_NUMERIC_LIMITS
12 #endif
14 // under MSVC shut off copious warnings about unused in-lines
15 #ifdef _MSC_VER
16 #pragma warning( disable: 4514 )
17 #endif
19 #ifdef HAVE_CPP_NUMERIC_LIMITS
20 #include <limits>
21 #else
22 #include <limits.h>
23 #endif
26 template <class T>
27 class nsCppSharedAllocator
29 ...allows Standard Library containers, et al, to use our global shared
30 (XP)COM-aware allocator.
33 public:
34 typedef T value_type;
35 typedef size_t size_type;
36 typedef ptrdiff_t difference_type;
38 typedef T* pointer;
39 typedef const T* const_pointer;
41 typedef T& reference;
42 typedef const T& const_reference;
46 nsCppSharedAllocator() { }
48 #ifdef HAVE_CPP_MEMBER_TEMPLATES
49 template <class U>
50 nsCppSharedAllocator( const nsCppSharedAllocator<U>& ) { }
51 #endif
53 ~nsCppSharedAllocator() { }
56 pointer
57 address( reference r ) const
59 return &r;
62 const_pointer
63 address( const_reference r ) const
65 return &r;
68 pointer
69 allocate( size_type n, const void* /*hint*/=0 )
71 return reinterpret_cast<pointer>(nsMemory::Alloc(static_cast<PRUint32>(n*sizeof(T))));
74 void
75 deallocate( pointer p, size_type /*n*/ )
77 nsMemory::Free(p);
80 void
81 construct( pointer p, const T& val )
83 new (p) T(val);
86 void
87 destroy( pointer p )
89 p->~T();
92 size_type
93 max_size() const
95 #ifdef HAVE_CPP_NUMERIC_LIMITS
96 return numeric_limits<size_type>::max() / sizeof(T);
97 #else
98 return ULONG_MAX / sizeof(T);
99 #endif
102 #ifdef HAVE_CPP_MEMBER_TEMPLATES
103 template <class U>
104 struct rebind
106 typedef nsCppSharedAllocator<U> other;
108 #endif
112 template <class T>
113 PRBool
114 operator==( const nsCppSharedAllocator<T>&, const nsCppSharedAllocator<T>& )
116 return PR_TRUE;
119 template <class T>
120 PRBool
121 operator!=( const nsCppSharedAllocator<T>&, const nsCppSharedAllocator<T>& )
123 return PR_FALSE;
126 #endif /* !defined(nsCppSharedAllocator_h__) */