• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

open-source-parsers / jsoncpp / 10821526037

11 Sep 2024 11:59PM UTC coverage: 95.295%. Remained the same
10821526037

Pull #1566

github

baylesj
Merge branch '1.9.7' of github.com:open-source-parsers/jsoncpp into 1.9.7
Pull Request #1566: Release 1.9.6 and move versions to 1.9.7

5306 of 5568 relevant lines covered (95.29%)

11935.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.48
/src/lib_json/json_valueiterator.inl
1
// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
2
// Distributed under MIT license, or public domain if desired and
3
// recognized in your jurisdiction.
4
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
5

6
// included by json_value.cpp
7

8
namespace Json {
9

10
// //////////////////////////////////////////////////////////////////
11
// //////////////////////////////////////////////////////////////////
12
// //////////////////////////////////////////////////////////////////
13
// class ValueIteratorBase
14
// //////////////////////////////////////////////////////////////////
15
// //////////////////////////////////////////////////////////////////
16
// //////////////////////////////////////////////////////////////////
17

18
ValueIteratorBase::ValueIteratorBase() : current_() {}
54✔
19

20
ValueIteratorBase::ValueIteratorBase(
111✔
21
    const Value::ObjectValues::iterator& current)
111✔
22
    : current_(current), isNull_(false) {}
111✔
23

24
Value& ValueIteratorBase::deref() { return current_->second; }
×
25
const Value& ValueIteratorBase::deref() const { return current_->second; }
33✔
26

27
void ValueIteratorBase::increment() { ++current_; }
75✔
28

29
void ValueIteratorBase::decrement() { --current_; }
13✔
30

31
ValueIteratorBase::difference_type
32
ValueIteratorBase::computeDistance(const SelfType& other) const {
5✔
33
  // Iterator for null value are initialized using the default
34
  // constructor, which initialize current_ to the default
35
  // std::map::iterator. As begin() and end() are two instance
36
  // of the default std::map::iterator, they can not be compared.
37
  // To allow this, we handle this comparison specifically.
38
  if (isNull_ && other.isNull_) {
5✔
39
    return 0;
40
  }
41

42
  // Usage of std::distance is not portable (does not compile with Sun Studio 12
43
  // RogueWave STL,
44
  // which is the one used by default).
45
  // Using a portable hand-made version for non random iterator instead:
46
  //   return difference_type( std::distance( current_, other.current_ ) );
47
  difference_type myDistance = 0;
48
  for (Value::ObjectValues::iterator it = current_; it != other.current_;
6✔
49
       ++it) {
50
    ++myDistance;
3✔
51
  }
52
  return myDistance;
53
}
54

55
bool ValueIteratorBase::isEqual(const SelfType& other) const {
126✔
56
  if (isNull_) {
126✔
57
    return other.isNull_;
27✔
58
  }
59
  return current_ == other.current_;
99✔
60
}
61

62
void ValueIteratorBase::copy(const SelfType& other) {
2✔
63
  current_ = other.current_;
2✔
64
  isNull_ = other.isNull_;
2✔
65
}
2✔
66

67
Value ValueIteratorBase::key() const {
5✔
68
  const Value::CZString czstring = (*current_).first;
5✔
69
  if (czstring.data()) {
5✔
70
    if (czstring.isStaticString())
3✔
71
      return Value(StaticString(czstring.data()));
1✔
72
    return Value(czstring.data(), czstring.data() + czstring.length());
2✔
73
  }
74
  return Value(czstring.index());
2✔
75
}
5✔
76

77
UInt ValueIteratorBase::index() const {
4✔
78
  const Value::CZString czstring = (*current_).first;
4✔
79
  if (!czstring.data())
4✔
80
    return czstring.index();
2✔
81
  return Value::UInt(-1);
82
}
4✔
83

84
String ValueIteratorBase::name() const {
46✔
85
  char const* keey;
86
  char const* end;
87
  keey = memberName(&end);
46✔
88
  if (!keey)
46✔
89
    return String();
90
  return String(keey, end);
44✔
91
}
92

93
char const* ValueIteratorBase::memberName() const {
2✔
94
  const char* cname = (*current_).first.data();
2✔
95
  return cname ? cname : "";
2✔
96
}
97

98
char const* ValueIteratorBase::memberName(char const** end) const {
46✔
99
  const char* cname = (*current_).first.data();
46✔
100
  if (!cname) {
46✔
101
    *end = nullptr;
2✔
102
    return nullptr;
2✔
103
  }
104
  *end = cname + (*current_).first.length();
44✔
105
  return cname;
44✔
106
}
107

108
// //////////////////////////////////////////////////////////////////
109
// //////////////////////////////////////////////////////////////////
110
// //////////////////////////////////////////////////////////////////
111
// class ValueConstIterator
112
// //////////////////////////////////////////////////////////////////
113
// //////////////////////////////////////////////////////////////////
114
// //////////////////////////////////////////////////////////////////
115

116
ValueConstIterator::ValueConstIterator() = default;
26✔
117

118
ValueConstIterator::ValueConstIterator(
60✔
119
    const Value::ObjectValues::iterator& current)
60✔
120
    : ValueIteratorBase(current) {}
60✔
121

122
ValueConstIterator::ValueConstIterator(ValueIterator const& other)
1✔
123
    : ValueIteratorBase(other) {}
1✔
124

125
ValueConstIterator& ValueConstIterator::
1✔
126
operator=(const ValueIteratorBase& other) {
127
  copy(other);
1✔
128
  return *this;
1✔
129
}
130

131
// //////////////////////////////////////////////////////////////////
132
// //////////////////////////////////////////////////////////////////
133
// //////////////////////////////////////////////////////////////////
134
// class ValueIterator
135
// //////////////////////////////////////////////////////////////////
136
// //////////////////////////////////////////////////////////////////
137
// //////////////////////////////////////////////////////////////////
138

139
ValueIterator::ValueIterator() = default;
28✔
140

141
ValueIterator::ValueIterator(const Value::ObjectValues::iterator& current)
51✔
142
    : ValueIteratorBase(current) {}
51✔
143

144
ValueIterator::ValueIterator(const ValueConstIterator& other)
1✔
145
    : ValueIteratorBase(other) {
1✔
146
  throwRuntimeError("ConstIterator to Iterator should never be allowed.");
1✔
147
}
148

149
ValueIterator::ValueIterator(const ValueIterator& other) = default;
15✔
150

151
ValueIterator& ValueIterator::operator=(const SelfType& other) {
1✔
152
  copy(other);
1✔
153
  return *this;
1✔
154
}
155

156
} // namespace Json
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc