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/json_value.h>
21 #include <ripple/json/JsonPropertyStream.h>
22 
23 namespace ripple {
24 
26  : m_top (Json::objectValue)
27 {
28  m_stack.reserve (64);
30 }
31 
33 {
34  return m_top;
35 }
36 
38 {
39  // top is array
42  m_stack.push_back (&map);
43 }
44 
46 {
47  // top is a map
49  Json::Value& map (top [key] = Json::objectValue);
50  m_stack.push_back (&map);
51 }
52 
54 {
55  m_stack.pop_back ();
56 }
57 
58 void JsonPropertyStream::add (std::string const& key, short v)
59 {
60  (*m_stack.back())[key] = v;
61 }
62 
63 void JsonPropertyStream::add (std::string const& key, unsigned short v)
64 {
65  (*m_stack.back())[key] = v;
66 }
67 
68 void JsonPropertyStream::add (std::string const& key, int v)
69 {
70  (*m_stack.back())[key] = v;
71 }
72 
73 void JsonPropertyStream::add (std::string const& key, unsigned int v)
74 {
75  (*m_stack.back())[key] = v;
76 }
77 
78 void JsonPropertyStream::add (std::string const& key, long v)
79 {
80  (*m_stack.back())[key] = int(v);
81 }
82 
83 void JsonPropertyStream::add (std::string const& key, float v)
84 {
85  (*m_stack.back())[key] = v;
86 }
87 
88 void JsonPropertyStream::add (std::string const& key, double v)
89 {
90  (*m_stack.back())[key] = v;
91 }
92 
93 void JsonPropertyStream::add (std::string const& key, std::string const& v)
94 {
95  (*m_stack.back())[key] = v;
96 }
97 
99 {
100  // top is array
101  Json::Value& top (*m_stack.back());
103  m_stack.push_back (&vec);
104 }
105 
107 {
108  // top is a map
109  Json::Value& top (*m_stack.back());
110  Json::Value& vec (top [key] = Json::arrayValue);
111  m_stack.push_back (&vec);
112 }
113 
115 {
116  m_stack.pop_back ();
117 }
118 
120 {
121  m_stack.back()->append (v);
122 }
123 
124 void JsonPropertyStream::add (unsigned short v)
125 {
126  m_stack.back()->append (v);
127 }
128 
130 {
131  m_stack.back()->append (v);
132 }
133 
134 void JsonPropertyStream::add (unsigned int v)
135 {
136  m_stack.back()->append (v);
137 }
138 
140 {
141  m_stack.back()->append (int (v));
142 }
143 
145 {
146  m_stack.back()->append (v);
147 }
148 
149 void JsonPropertyStream::add (double v)
150 {
151  m_stack.back()->append (v);
152 }
153 
155 {
156  m_stack.back()->append (v);
157 }
158 
159 }
160 
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:44
std::vector::reserve
T reserve(T... args)
ripple::JsonPropertyStream::add
void add(std::string const &key, short value) override
Definition: JsonPropertyStream.cpp:58
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:26
Json::Value::append
Value & append(const Value &value)
Append value to array at the end.
Definition: json_value.cpp:907
Json::objectValue
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:45
ripple::JsonPropertyStream::map_begin
void map_begin() override
Definition: JsonPropertyStream.cpp:37
ripple::JsonPropertyStream::map_end
void map_end() override
Definition: JsonPropertyStream.cpp:53
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:114
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:98
ripple::JsonPropertyStream::m_top
Json::Value m_top
Definition: JsonPropertyStream.h:32
Json::Value
Represents a JSON value.
Definition: json_value.h:141