NIM PC Cross Platform SDK
allocator.h
1// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
2// Distributed under MIT license, or public domain if desired and
3// recognized in your jurisdiction.
4// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
5
6#ifndef NIM_CPP_WRAPPER_UTIL_JSON_ALLOCATOR_H_INCLUDED
7#define NIM_CPP_WRAPPER_UTIL_JSON_ALLOCATOR_H_INCLUDED
8
9#include <cstring>
10#include <memory>
11
12#pragma pack(push, 8)
13
15namespace Json {
16template <typename T>
18public:
19 // Type definitions
20 using value_type = T;
21 using pointer = T*;
22 using const_pointer = const T*;
23 using reference = T&;
24 using const_reference = const T&;
25 using size_type = std::size_t;
26 using difference_type = std::ptrdiff_t;
27
31 pointer allocate(size_type n) {
32 // allocate using "global operator new"
33 return static_cast<pointer>(::operator new(n * sizeof(T)));
34 }
35
43 void deallocate(volatile pointer p, size_type n) {
44 std::memset(p, 0, n * sizeof(T));
45 // free using "global operator delete"
46 ::operator delete(p);
47 }
48
52 template <typename... Args>
53 void construct(pointer p, Args&&... args) {
54 // construct using "placement new" and "perfect forwarding"
55 ::new (static_cast<void*>(p)) T(std::forward<Args>(args)...);
56 }
57
58 size_type max_size() const { return size_t(-1) / sizeof(T); }
59
60 pointer address(reference x) const { return std::addressof(x); }
61
62 const_pointer address(const_reference x) const { return std::addressof(x); }
63
67 void destroy(pointer p) {
68 // destroy using "explicit destructor"
69 p->~T();
70 }
71
72 // Boilerplate
74 template <typename U>
75 SecureAllocator(const SecureAllocator<U>&) {}
76 template <typename U>
77 struct rebind {
79 };
80};
81
82template <typename T, typename U>
84 return true;
85}
86
87template <typename T, typename U>
88bool operator!=(const SecureAllocator<T>&, const SecureAllocator<U>&) {
89 return false;
90}
91
92} // namespace Json
93} // namespace nim_cpp_wrapper_util
94
95#pragma pack(pop)
96
97#endif // JSON_ALLOCATOR_H_INCLUDED
pointer allocate(size_type n)
Definition: allocator.h:31
void construct(pointer p, Args &&... args)
Definition: allocator.h:53
void destroy(pointer p)
Definition: allocator.h:67
void deallocate(volatile pointer p, size_type n)
Definition: allocator.h:43
bool operator==(const NIMChatRoomExitReasonInfo &info, NIMChatRoomExitReason code)
Definition: nim_chatroom_helper.cpp:13
JSON (JavaScript Object Notation).
Definition: allocator.h:14