rippled
Loading...
Searching...
No Matches
JsonPropertyStream.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpl/json/JsonPropertyStream.h>
21#include <xrpl/json/json_value.h>
22
23namespace ripple {
24
26{
27 m_stack.reserve(64);
29}
30
31Json::Value const&
33{
34 return m_top;
35}
36
37void
39{
40 // top is array
43 m_stack.push_back(&map);
44}
45
46void
48{
49 // top is a map
52 m_stack.push_back(&map);
53}
54
55void
57{
59}
60
61void
63{
64 (*m_stack.back())[key] = v;
65}
66
67void
68JsonPropertyStream::add(std::string const& key, unsigned short v)
69{
70 (*m_stack.back())[key] = v;
71}
72
73void
75{
76 (*m_stack.back())[key] = v;
77}
78
79void
80JsonPropertyStream::add(std::string const& key, unsigned int v)
81{
82 (*m_stack.back())[key] = v;
83}
84
85void
87{
88 (*m_stack.back())[key] = int(v);
89}
90
91void
93{
94 (*m_stack.back())[key] = v;
95}
96
97void
99{
100 (*m_stack.back())[key] = v;
101}
102
103void
105{
106 (*m_stack.back())[key] = v;
107}
108
109void
111{
112 // top is array
115 m_stack.push_back(&vec);
116}
117
118void
120{
121 // top is a map
123 Json::Value& vec(top[key] = Json::arrayValue);
124 m_stack.push_back(&vec);
125}
126
127void
129{
131}
132
133void
135{
136 m_stack.back()->append(v);
137}
138
139void
140JsonPropertyStream::add(unsigned short v)
141{
142 m_stack.back()->append(v);
143}
144
145void
147{
148 m_stack.back()->append(v);
149}
150
151void
153{
154 m_stack.back()->append(v);
155}
156
157void
159{
160 m_stack.back()->append(int(v));
161}
162
163void
165{
166 m_stack.back()->append(v);
167}
168
169void
171{
172 m_stack.back()->append(v);
173}
174
175void
177{
178 m_stack.back()->append(v);
179}
180
181} // namespace ripple
T back(T... args)
Represents a JSON value.
Definition: json_value.h:147
Value & append(const Value &value)
Append value to array at the end.
Definition: json_value.cpp:891
Json::Value const & top() const
void add(std::string const &key, short value) override
std::vector< Json::Value * > m_stack
JSON (JavaScript Object Notation).
Definition: json_errors.h:25
@ arrayValue
array value (ordered list)
Definition: json_value.h:42
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:43
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
T pop_back(T... args)
T push_back(T... args)
T reserve(T... args)