JsonCpp
1.10.0
JSON data format manipulation library
Toggle main menu visibility
Loading...
Searching...
No Matches
allocator.h
Go to the documentation of this file.
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 JSON_ALLOCATOR_H_INCLUDED
7
#define JSON_ALLOCATOR_H_INCLUDED
8
9
#include <algorithm>
10
#include <cstring>
11
#include <memory>
12
13
#pragma pack(push)
14
#pragma pack()
15
16
namespace
Json
{
17
template
<
typename
T>
class
SecureAllocator
{
18
public
:
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
41
void
deallocate
(
pointer
p,
size_type
n) {
42
// These constructs will not be removed by the compiler during optimization,
43
// unlike memset.
44
#if defined(HAVE_MEMSET_S)
45
memset_s(p, n *
sizeof
(T), 0, n *
sizeof
(T));
46
#else
47
std::fill_n(
reinterpret_cast<
volatile
unsigned
char
*
>
(p), n *
sizeof
(T),
48
static_cast<
unsigned
char
>
(0));
49
#endif
50
51
// free using "global operator delete"
52
::operator
delete
(p);
53
}
54
58
template
<
typename
... Args>
void
construct
(
pointer
p, Args&&... args) {
59
// construct using "placement new" and "perfect forwarding"
60
::new (
static_cast<
void
*
>
(p)) T(std::forward<Args>(args)...);
61
}
62
63
size_type
max_size
()
const
{
return
size_t(-1) /
sizeof
(T); }
64
65
pointer
address
(
reference
x)
const
{
return
std::addressof(x); }
66
67
const_pointer
address
(
const_reference
x)
const
{
return
std::addressof(x); }
68
72
void
destroy
(
pointer
p) {
73
// destroy using "explicit destructor"
74
p->~T();
75
}
76
77
// Boilerplate
78
SecureAllocator
() {}
79
template
<
typename
U>
SecureAllocator
(
const
SecureAllocator<U>
&) {}
80
template
<
typename
U>
struct
rebind
{
81
using
other
=
SecureAllocator<U>
;
82
};
83
};
84
85
template
<
typename
T,
typename
U>
86
bool
operator==
(
const
SecureAllocator<T>
&,
const
SecureAllocator<U>
&) {
87
return
true
;
88
}
89
90
template
<
typename
T,
typename
U>
91
bool
operator!=
(
const
SecureAllocator<T>
&,
const
SecureAllocator<U>
&) {
92
return
false
;
93
}
94
95
}
// namespace Json
96
97
#pragma pack(pop)
98
99
#endif
// JSON_ALLOCATOR_H_INCLUDED
Json::SecureAllocator
Definition
allocator.h:17
Json::SecureAllocator::max_size
size_type max_size() const
Definition
allocator.h:63
Json::SecureAllocator::address
const_pointer address(const_reference x) const
Definition
allocator.h:67
Json::SecureAllocator::address
pointer address(reference x) const
Definition
allocator.h:65
Json::SecureAllocator::const_reference
const T & const_reference
Definition
allocator.h:24
Json::SecureAllocator::difference_type
std::ptrdiff_t difference_type
Definition
allocator.h:26
Json::SecureAllocator::pointer
T * pointer
Definition
allocator.h:21
Json::SecureAllocator::const_pointer
const T * const_pointer
Definition
allocator.h:22
Json::SecureAllocator::reference
T & reference
Definition
allocator.h:23
Json::SecureAllocator::size_type
std::size_t size_type
Definition
allocator.h:25
Json::SecureAllocator::destroy
void destroy(pointer p)
Destroy an item in-place at pointer P.
Definition
allocator.h:72
Json::SecureAllocator::deallocate
void deallocate(pointer p, size_type n)
Release memory which was allocated for N items at pointer P.
Definition
allocator.h:41
Json::SecureAllocator::allocate
pointer allocate(size_type n)
Allocate memory for N items using the standard allocator.
Definition
allocator.h:31
Json::SecureAllocator::SecureAllocator
SecureAllocator()
Definition
allocator.h:78
Json::SecureAllocator::construct
void construct(pointer p, Args &&... args)
Construct an item in-place at pointer P.
Definition
allocator.h:58
Json::SecureAllocator::value_type
T value_type
Definition
allocator.h:20
Json::SecureAllocator::SecureAllocator
SecureAllocator(const SecureAllocator< U > &)
Definition
allocator.h:79
Json
JSON (JavaScript Object Notation).
Definition
allocator.h:16
Json::operator==
bool operator==(const SecureAllocator< T > &, const SecureAllocator< U > &)
Definition
allocator.h:86
Json::operator!=
bool operator!=(const SecureAllocator< T > &, const SecureAllocator< U > &)
Definition
allocator.h:91
Json::SecureAllocator::rebind
Definition
allocator.h:80
Json::SecureAllocator::rebind::other
SecureAllocator< U > other
Definition
allocator.h:81
include
json
allocator.h
Generated by
1.18.0