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
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>
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>
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
SecureAllocator(const SecureAllocator< U > &)
Definition: allocator.h:75
size_type max_size() const
Definition: allocator.h:58
T value_type
Definition: allocator.h:20
pointer address(reference x) const
Definition: allocator.h:60
pointer allocate(size_type n)
Definition: allocator.h:31
T & reference
Definition: allocator.h:23
const T & const_reference
Definition: allocator.h:24
std::ptrdiff_t difference_type
Definition: allocator.h:26
const_pointer address(const_reference x) const
Definition: allocator.h:62
const T * const_pointer
Definition: allocator.h:22
std::size_t size_type
Definition: allocator.h:25
T * pointer
Definition: allocator.h:21
void construct(pointer p, Args &&... args)
Definition: allocator.h:53
SecureAllocator()
Definition: allocator.h:73
void destroy(pointer p)
Definition: allocator.h:67
void deallocate(volatile pointer p, size_type n)
Definition: allocator.h:43
bool operator==(const SecureAllocator< T > &, const SecureAllocator< U > &)
Definition: allocator.h:83
bool operator!=(const SecureAllocator< T > &, const SecureAllocator< U > &)
Definition: allocator.h:88
JSON (JavaScript Object Notation).
Definition: allocator.h:14