Jamoma API  0.6.0.a19
JSONAllocator.h
1 #ifndef JSON_ALLOCATOR_H
2 #define JSON_ALLOCATOR_H
3 
4 #include "JSONStats.h"
5 #if defined(JSON_MEMORY_CALLBACKS) || defined(JSON_MEMORY_POOL)
6 
7 #include <cstddef>
8 
9 //need these for the json_nothrow
10 #include "JSONDefs/Visual_C.h"
11 #include "JSONDefs/GNU_C.h"
12 #include "JSONDefs/Unknown_C.h"
13 
14 class JSONAllocatorRelayer {
15 public:
16  static void * alloc(size_t bytes) json_nothrow json_hot;
17  static void dealloc(void * ptr) json_nothrow json_hot;
18 };
19 
20 template <class T> class json_allocator;
21 
22 // specialize for void:
23 template <> class json_allocator<void> {
24 public:
25  typedef void* pointer;
26  typedef const void* const_pointer;
27  // reference to void members are impossible.
28  typedef void value_type;
29  template <class U> struct rebind { typedef json_allocator<U> other; };
30 };
31 
32 template <class T> class json_allocator {
33 public:
34  typedef size_t size_type;
35  typedef ptrdiff_t difference_type;
36  typedef T* pointer;
37  typedef const T* const_pointer;
38  typedef T& reference;
39  typedef const T& const_reference;
40  typedef T value_type;
41  template <class U> struct rebind { typedef json_allocator<U> other; };
42 
43  //LIBJSON_OBJECT(json_allocator);
44 
45  inline json_allocator() json_nothrow {
46  //LIBJSON_CTOR;
47  }
48  inline json_allocator(const json_allocator&) json_nothrow {
49  //LIBJSON_COPY_CTOR;
50  }
51  template <class U> inline json_allocator(const json_allocator<U>&) json_nothrow {
52  //LIBJSON_COPY_CTOR;
53  }
54  inline ~json_allocator() json_nothrow {
55  //LIBJSON_DTOR;
56  }
57 
58  inline pointer address(reference x) const { return &x; }
59  inline const_pointer address(const_reference x) const { return &x; }
60 
61  inline pointer allocate(size_type n, json_allocator<void>::const_pointer = 0) json_hot {
62  return (pointer)JSONAllocatorRelayer::alloc(n * sizeof(T));
63  }
64  inline void deallocate(pointer p, size_type) json_hot {
65  JSONAllocatorRelayer::dealloc(p);
66  }
67 
68  inline size_type max_size() const json_nothrow { return 0xEFFFFFFF; }
69 
70  inline void construct(pointer p, const T& val){
71  new(p)T(val);
72  };
73  inline void destroy(pointer p){
74  ((T*)p) -> ~T();
75  }
76 };
77 
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; }
80 
81 #endif
82 #endif
bool TTFOUNDATION_EXPORT operator!=(const TTObject &anObject, const TTObject &anotherObject)
Compare two objects for inequality.
Definition: TTObject.cpp:173
bool TTFOUNDATION_EXPORT operator==(const TTObject &anObject, const TTObject &anotherObject)
Compare two objects for equality.
Definition: TTObject.cpp:167