1 #ifndef JSON_ALLOCATOR_H
2 #define JSON_ALLOCATOR_H
5 #if defined(JSON_MEMORY_CALLBACKS) || defined(JSON_MEMORY_POOL)
10 #include "JSONDefs/Visual_C.h"
11 #include "JSONDefs/GNU_C.h"
12 #include "JSONDefs/Unknown_C.h"
14 class JSONAllocatorRelayer {
16 static void * alloc(
size_t bytes) json_nothrow json_hot;
17 static void dealloc(
void * ptr) json_nothrow json_hot;
20 template <
class T>
class json_allocator;
23 template <>
class json_allocator<void> {
25 typedef void* pointer;
26 typedef const void* const_pointer;
28 typedef void value_type;
29 template <
class U>
struct rebind {
typedef json_allocator<U> other; };
32 template <
class T>
class json_allocator {
34 typedef size_t size_type;
35 typedef ptrdiff_t difference_type;
37 typedef const T* const_pointer;
39 typedef const T& const_reference;
41 template <
class U>
struct rebind {
typedef json_allocator<U> other; };
45 inline json_allocator() json_nothrow {
48 inline json_allocator(
const json_allocator&) json_nothrow {
51 template <
class U>
inline json_allocator(
const json_allocator<U>&) json_nothrow {
54 inline ~json_allocator() json_nothrow {
58 inline pointer address(reference x)
const {
return &x; }
59 inline const_pointer address(const_reference x)
const {
return &x; }
61 inline pointer allocate(size_type n, json_allocator<void>::const_pointer = 0) json_hot {
62 return (pointer)JSONAllocatorRelayer::alloc(n *
sizeof(T));
64 inline void deallocate(pointer p, size_type) json_hot {
65 JSONAllocatorRelayer::dealloc(p);
68 inline size_type max_size() const json_nothrow {
return 0xEFFFFFFF; }
70 inline void construct(pointer p,
const T& val){
73 inline void destroy(pointer p){
78 template <
class T1,
class T2>
inline bool operator==(
const json_allocator<T1>&,
const json_allocator<T2>&) json_nothrow {
return true; }
79 template <
class T1,
class T2>
inline bool operator!=(
const json_allocator<T1>&,
const json_allocator<T2>&) json_nothrow {
return false; }
bool TTFOUNDATION_EXPORT operator!=(const TTObject &anObject, const TTObject &anotherObject)
Compare two objects for inequality.
bool TTFOUNDATION_EXPORT operator==(const TTObject &anObject, const TTObject &anotherObject)
Compare two objects for equality.