xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
json
JsonPropertyStream.cpp
1
#include <xrpl/json/JsonPropertyStream.h>
2
3
#include <xrpl/json/json_value.h>
4
5
#include <
string
>
6
7
namespace
xrpl
{
8
9
JsonPropertyStream::JsonPropertyStream
() :
topValue
(
json
::ValueType::Object)
10
{
11
stack
.reserve(64);
12
stack
.push_back(&
topValue
);
13
}
14
15
json::Value
const
&
16
JsonPropertyStream::top
()
const
17
{
18
return
topValue
;
19
}
20
21
void
22
JsonPropertyStream::mapBegin
()
23
{
24
// top is array
25
json::Value
&
top
(*
stack
.back());
26
json::Value
& map(
top
.append(
json::ValueType::Object
));
27
stack
.push_back(&map);
28
}
29
30
void
31
JsonPropertyStream::mapBegin
(
std::string
const
& key)
32
{
33
// top is a map
34
json::Value
&
top
(*
stack
.back());
35
json::Value
& map(
top
[key] =
json::ValueType::Object
);
36
stack
.push_back(&map);
37
}
38
39
void
40
JsonPropertyStream::mapEnd
()
41
{
42
stack
.pop_back();
43
}
44
45
void
46
JsonPropertyStream::add
(
std::string
const
& key,
short
v)
47
{
48
(*
stack
.back())[key] = v;
49
}
50
51
void
52
JsonPropertyStream::add
(
std::string
const
& key,
unsigned
short
v)
53
{
54
(*
stack
.back())[key] = v;
55
}
56
57
void
58
JsonPropertyStream::add
(
std::string
const
& key,
int
v)
59
{
60
(*
stack
.back())[key] = v;
61
}
62
63
void
64
JsonPropertyStream::add
(
std::string
const
& key,
unsigned
int
v)
65
{
66
(*
stack
.back())[key] = v;
67
}
68
69
void
70
JsonPropertyStream::add
(
std::string
const
& key,
long
v)
71
{
72
(*
stack
.back())[key] = int(v);
73
}
74
75
void
76
JsonPropertyStream::add
(
std::string
const
& key,
float
v)
77
{
78
(*
stack
.back())[key] = v;
79
}
80
81
void
82
JsonPropertyStream::add
(
std::string
const
& key,
double
v)
83
{
84
(*
stack
.back())[key] = v;
85
}
86
87
void
88
JsonPropertyStream::add
(
std::string
const
& key,
std::string
const
& v)
89
{
90
(*
stack
.back())[key] = v;
91
}
92
93
void
94
JsonPropertyStream::arrayBegin
()
95
{
96
// top is array
97
json::Value
&
top
(*
stack
.back());
98
json::Value
& vec(
top
.append(
json::ValueType::Array
));
99
stack
.push_back(&vec);
100
}
101
102
void
103
JsonPropertyStream::arrayBegin
(
std::string
const
& key)
104
{
105
// top is a map
106
json::Value
&
top
(*
stack
.back());
107
json::Value
& vec(
top
[key] =
json::ValueType::Array
);
108
stack
.push_back(&vec);
109
}
110
111
void
112
JsonPropertyStream::arrayEnd
()
113
{
114
stack
.pop_back();
115
}
116
117
void
118
JsonPropertyStream::add
(
short
v)
119
{
120
stack
.back()->append(v);
121
}
122
123
void
124
JsonPropertyStream::add
(
unsigned
short
v)
125
{
126
stack
.back()->append(v);
127
}
128
129
void
130
JsonPropertyStream::add
(
int
v)
131
{
132
stack
.back()->append(v);
133
}
134
135
void
136
JsonPropertyStream::add
(
unsigned
int
v)
137
{
138
stack
.back()->append(v);
139
}
140
141
void
142
JsonPropertyStream::add
(
long
v)
143
{
144
stack
.back()->append(
int
(v));
145
}
146
147
void
148
JsonPropertyStream::add
(
float
v)
149
{
150
stack
.back()->append(v);
151
}
152
153
void
154
JsonPropertyStream::add
(
double
v)
155
{
156
stack
.back()->append(v);
157
}
158
159
void
160
JsonPropertyStream::add
(
std::string
const
& v)
161
{
162
stack
.back()->append(v);
163
}
164
165
}
// namespace xrpl
std::string
json::Value
Represents a JSON value.
Definition
json_value.h:117
xrpl::JsonPropertyStream::JsonPropertyStream
JsonPropertyStream()
Definition
JsonPropertyStream.cpp:9
xrpl::JsonPropertyStream::top
json::Value const & top() const
Definition
JsonPropertyStream.cpp:16
xrpl::JsonPropertyStream::add
void add(std::string const &key, short value) override
Definition
JsonPropertyStream.cpp:46
xrpl::JsonPropertyStream::arrayEnd
void arrayEnd() override
Definition
JsonPropertyStream.cpp:112
xrpl::JsonPropertyStream::topValue
json::Value topValue
Definition
JsonPropertyStream.h:17
xrpl::JsonPropertyStream::mapBegin
void mapBegin() override
Definition
JsonPropertyStream.cpp:22
xrpl::JsonPropertyStream::stack
std::vector< json::Value * > stack
Definition
JsonPropertyStream.h:18
xrpl::JsonPropertyStream::arrayBegin
void arrayBegin() override
Definition
JsonPropertyStream.cpp:94
xrpl::JsonPropertyStream::mapEnd
void mapEnd() override
Definition
JsonPropertyStream.cpp:40
json
JSON (JavaScript Object Notation).
Definition
json_errors.h:5
json::ValueType::Array
@ Array
array value (ordered list)
Definition
json_value.h:28
json::ValueType::Object
@ Object
object value (collection of name/value pairs).
Definition
json_value.h:29
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
string
Generated by
1.17.0