rippled
Loading...
Searching...
No Matches
json_valueiterator.cpp
1// included by json_value.cpp
2
3#include <xrpl/json/json_forwards.h>
4#include <xrpl/json/json_value.h>
5
6namespace Json {
7
8// //////////////////////////////////////////////////////////////////
9// //////////////////////////////////////////////////////////////////
10// //////////////////////////////////////////////////////////////////
11// class ValueIteratorBase
12// //////////////////////////////////////////////////////////////////
13// //////////////////////////////////////////////////////////////////
14// //////////////////////////////////////////////////////////////////
15
16ValueIteratorBase::ValueIteratorBase() : current_(), isNull_(true)
17{
18}
19
21 Value::ObjectValues::iterator const& current)
22 : current_(current), isNull_(false)
23{
24}
25
26Value&
28{
29 return current_->second;
30}
31
32void
37
38void
43
46{
47 // Iterator for null value are initialized using the default
48 // constructor, which initialize current_ to the default
49 // std::map::iterator. As begin() and end() are two instance
50 // of the default std::map::iterator, they can not be compared.
51 // To allow this, we handle this comparison specifically.
52 if (isNull_ && other.isNull_)
53 {
54 return 0;
55 }
56
57 // Usage of std::distance is not portable (does not compile with Sun Studio
58 // 12 RogueWave STL, which is the one used by default). Using a portable
59 // hand-made version for non random iterator instead:
60 // return difference_type( std::distance( current_, other.current_ ) );
61 difference_type myDistance = 0;
62
63 for (Value::ObjectValues::iterator it = current_; it != other.current_;
64 ++it)
65 {
66 ++myDistance;
67 }
68
69 return myDistance;
70}
71
72bool
74{
75 if (isNull_)
76 {
77 return other.isNull_;
78 }
79
80 return current_ == other.current_;
81}
82
83void
85{
86 current_ = other.current_;
87}
88
91{
92 Value::CZString const czstring = (*current_).first;
93
94 if (czstring.c_str())
95 {
96 if (czstring.isStaticString())
97 return Value(StaticString(czstring.c_str()));
98
99 return Value(czstring.c_str());
100 }
101
102 return Value(czstring.index());
103}
104
105UInt
107{
108 Value::CZString const czstring = (*current_).first;
109
110 if (!czstring.c_str())
111 return czstring.index();
112
113 return Value::UInt(-1);
114}
115
116char const*
118{
119 char const* name = (*current_).first.c_str();
120 return name ? name : "";
121}
122
123// //////////////////////////////////////////////////////////////////
124// //////////////////////////////////////////////////////////////////
125// //////////////////////////////////////////////////////////////////
126// class ValueConstIterator
127// //////////////////////////////////////////////////////////////////
128// //////////////////////////////////////////////////////////////////
129// //////////////////////////////////////////////////////////////////
130
132 Value::ObjectValues::iterator const& current)
133 : ValueIteratorBase(current)
134{
135}
136
139{
140 copy(other);
141 return *this;
142}
143
144// //////////////////////////////////////////////////////////////////
145// //////////////////////////////////////////////////////////////////
146// //////////////////////////////////////////////////////////////////
147// class ValueIterator
148// //////////////////////////////////////////////////////////////////
149// //////////////////////////////////////////////////////////////////
150// //////////////////////////////////////////////////////////////////
151
152ValueIterator::ValueIterator(Value::ObjectValues::iterator const& current)
153 : ValueIteratorBase(current)
154{
155}
156
161
166
169{
170 copy(other);
171 return *this;
172}
173
174} // namespace Json
T c_str(T... args)
Lightweight wrapper to tag static string.
Definition json_value.h:45
const iterator for object and array value.
Definition json_value.h:559
SelfType & operator=(ValueIteratorBase const &other)
base class for Value iterators.
Definition json_value.h:494
void copy(SelfType const &other)
Value key() const
Return either the index or the member name of the referenced value as a Value.
bool isEqual(SelfType const &other) const
char const * memberName() const
Return the member name of the referenced Value.
UInt index() const
Return the index of the referenced Value. -1 if it is not an arrayValue.
difference_type computeDistance(SelfType const &other) const
Value::ObjectValues::iterator current_
Definition json_value.h:550
Iterator for object and array value.
Definition json_value.h:620
SelfType & operator=(SelfType const &other)
ValueIterator()=default
bool isStaticString() const
char const * c_str() const
Represents a JSON value.
Definition json_value.h:131
Json::UInt UInt
Definition json_value.h:138
JSON (JavaScript Object Notation).
Definition json_errors.h:6
unsigned int UInt