#ifndef JSON_ALLOCATOR_H #define JSON_ALLOCATOR_H #include "JSONStats.h" #if defined(JSON_MEMORY_CALLBACKS) || defined(JSON_MEMORY_POOL) #include //need these for the json_nothrow #include "JSONDefs/Visual_C.h" #include "JSONDefs/GNU_C.h" #include "JSONDefs/Unknown_C.h" class JSONAllocatorRelayer { public: static void * alloc(size_t bytes) json_nothrow json_hot; static void dealloc(void * ptr) json_nothrow json_hot; }; template class json_allocator; // specialize for void: template <> class json_allocator { public: typedef void* pointer; typedef const void* const_pointer; // reference to void members are impossible. typedef void value_type; template struct rebind { typedef json_allocator other; }; }; template class json_allocator { public: typedef size_t size_type; typedef ptrdiff_t difference_type; typedef T* pointer; typedef const T* const_pointer; typedef T& reference; typedef const T& const_reference; typedef T value_type; template struct rebind { typedef json_allocator other; }; //LIBJSON_OBJECT(json_allocator); inline json_allocator() json_nothrow { //LIBJSON_CTOR; } inline json_allocator(const json_allocator&) json_nothrow { //LIBJSON_COPY_CTOR; } template inline json_allocator(const json_allocator&) json_nothrow { //LIBJSON_COPY_CTOR; } inline ~json_allocator() json_nothrow { //LIBJSON_DTOR; } inline pointer address(reference x) const { return &x; } inline const_pointer address(const_reference x) const { return &x; } inline pointer allocate(size_type n, json_allocator::const_pointer = 0) json_hot { return (pointer)JSONAllocatorRelayer::alloc(n * sizeof(T)); } inline void deallocate(pointer p, size_type) json_hot { JSONAllocatorRelayer::dealloc(p); } inline size_type max_size() const json_nothrow { return 0xEFFFFFFF; } inline void construct(pointer p, const T& val){ new(p)T(val); }; inline void destroy(pointer p){ ((T*)p) -> ~T(); } }; template inline bool operator==(const json_allocator&, const json_allocator&) json_nothrow { return true; } template inline bool operator!=(const json_allocator&, const json_allocator&) json_nothrow { return false; } #endif #endif