rippled
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 <ripple/json/JsonPropertyStream.h>
21 #include <ripple/json/json_value.h>
22 
23 namespace ripple {
24 
26 {
27  m_stack.reserve(64);
29 }
30 
31 Json::Value const&
33 {
34  return m_top;
35 }
36 
37 void
39 {
40  // top is array
43  m_stack.push_back(&map);
44 }
45 
46 void
48 {
49  // top is a map
51  Json::Value& map(top[key] = Json::objectValue);
52  m_stack.push_back(&map);
53 }
54 
55 void
57 {
58  m_stack.pop_back();
59 }
60 
61 void
63 {
64  (*m_stack.back())[key] = v;
65 }
66 
67 void
68 JsonPropertyStream::add(std::string const& key, unsigned short v)
69 {
70  (*m_stack.back())[key] = v;
71 }
72 
73 void
75 {
76  (*m_stack.back())[key] = v;
77 }
78 
79 void
80 JsonPropertyStream::add(std::string const& key, unsigned int v)
81 {
82  (*m_stack.back())[key] = v;
83 }
84 
85 void
87 {
88  (*m_stack.back())[key] = int(v);
89 }
90 
91 void
93 {
94  (*m_stack.back())[key] = v;
95 }
96 
97 void
98 JsonPropertyStream::add(std::string const& key, double v)
99 {
100  (*m_stack.back())[key] = v;
101 }
102 
103 void
105 {
106  (*m_stack.back())[key] = v;
107 }
108 
109 void
111 {
112  // top is array
115  m_stack.push_back(&vec);
116 }
117 
118 void
120 {
121  // top is a map
123  Json::Value& vec(top[key] = Json::arrayValue);
124  m_stack.push_back(&vec);
125 }
126 
127 void
129 {
130  m_stack.pop_back();
131 }
132 
133 void
135 {
136  m_stack.back()->append(v);
137 }
138 
139 void
140 JsonPropertyStream::add(unsigned short v)
141 {
142  m_stack.back()->append(v);
143 }
144 
145 void
147 {
148  m_stack.back()->append(v);
149 }
150 
151 void
152 JsonPropertyStream::add(unsigned int v)
153 {
154  m_stack.back()->append(v);
155 }
156 
157 void
159 {
160  m_stack.back()->append(int(v));
161 }
162 
163 void
165 {
166  m_stack.back()->append(v);
167 }
168 
169 void
171 {
172  m_stack.back()->append(v);
173 }
174 
175 void
177 {
178  m_stack.back()->append(v);
179 }
180 
181 } // namespace ripple
std::string
STL class.
ripple::JsonPropertyStream::top
Json::Value const & top() const
Definition: JsonPropertyStream.cpp:32
Json::arrayValue
@ arrayValue
array value (ordered list)
Definition: json_value.h:42
std::vector::reserve
T reserve(T... args)
ripple::JsonPropertyStream::add
void add(std::string const &key, short value) override
Definition: JsonPropertyStream.cpp:62
std::vector::back
T back(T... args)
std::vector::push_back
T push_back(T... args)
ripple::JsonPropertyStream::JsonPropertyStream
JsonPropertyStream()
Definition: JsonPropertyStream.cpp:25
Json
JSON (JavaScript Object Notation).
Definition: json_reader.cpp:27
Json::Value::append
Value & append(const Value &value)
Append value to array at the end.
Definition: json_value.cpp:882
Json::objectValue
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:43
ripple::JsonPropertyStream::map_begin
void map_begin() override
Definition: JsonPropertyStream.cpp:38
ripple::JsonPropertyStream::map_end
void map_end() override
Definition: JsonPropertyStream.cpp:56
std::vector::pop_back
T pop_back(T... args)
ripple::JsonPropertyStream::m_stack
std::vector< Json::Value * > m_stack
Definition: JsonPropertyStream.h:33
ripple::JsonPropertyStream::array_end
void array_end() override
Definition: JsonPropertyStream.cpp:128
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::JsonPropertyStream::array_begin
void array_begin() override
Definition: JsonPropertyStream.cpp:110
ripple::JsonPropertyStream::m_top
Json::Value m_top
Definition: JsonPropertyStream.h:32
Json::Value
Represents a JSON value.
Definition: json_value.h:145