11 namespace launchdarkly {
50 using iterator_category = std::bidirectional_iterator_tag;
51 using difference_type = std::ptrdiff_t;
56 Iterator(std::vector<Value>::const_iterator iterator);
58 reference operator*()
const;
67 return lhs.iterator_ == rhs.iterator_;
71 return lhs.iterator_ != rhs.iterator_;
75 std::vector<Value>::const_iterator iterator_;
78 friend std::ostream& operator<<(std::ostream& out,
Array const& arr) {
81 for (
auto const& item : arr.vec_) {
97 Array(std::vector<Value> vec);
98 Array(std::initializer_list<Value> values) : vec_(values) {}
101 Value const& operator[](std::size_t index)
const;
103 [[nodiscard]] std::size_t Size()
const;
105 [[nodiscard]] Iterator begin()
const;
107 [[nodiscard]] Iterator end()
const;
110 std::vector<Value> vec_;
119 using iterator_category = std::forward_iterator_tag;
120 using difference_type = std::ptrdiff_t;
122 using value_type = std::pair<std::string const, Value>;
123 using pointer = value_type
const*;
124 using reference = value_type
const&;
126 Iterator(std::map<std::string, Value>::const_iterator iterator);
128 reference operator*()
const;
129 pointer operator->();
134 return rhs.it_ == lhs.it_;
137 return lhs.it_ != rhs.it_;
141 std::map<std::string, Value>::const_iterator it_;
144 friend std::ostream& operator<<(std::ostream& out,
Object const& obj) {
147 for (
auto const& pair : obj.map_) {
153 out <<
"{" << pair.first <<
", " << pair.second <<
"}";
163 Object(std::map<std::string, Value> map) : map_(std::move(map)) {}
165 Object(std::initializer_list<std::pair<std::string, Value>> values);
173 Value const& operator[](std::string
const& key)
const;
179 [[nodiscard]] std::size_t
Size()
const;
186 [[nodiscard]] std::size_t
Count(std::string
const& key)
const;
188 [[nodiscard]] Iterator begin()
const;
190 [[nodiscard]] Iterator end()
const;
197 [[nodiscard]] Iterator
Find(std::string
const& key)
const;
200 std::map<std::string, Value> map_;
207 Value(
char const* str);
209 enum class Type { kNull, kBool, kNumber, kString, kObject, kArray };
243 Value(std::string str);
249 Value(std::vector<Value> arr);
259 Value(std::map<std::string, Value> obj);
267 Value(std::initializer_list<Value> values);
273 Value(std::optional<std::string> opt_string);
278 [[nodiscard]] Type Type()
const;
287 [[nodiscard]]
bool IsNull()
const;
294 [[nodiscard]]
bool IsBool()
const;
303 [[nodiscard]]
bool IsNumber()
const;
310 [[nodiscard]]
bool IsString()
const;
317 [[nodiscard]]
bool IsArray()
const;
324 [[nodiscard]]
bool IsObject()
const;
332 [[nodiscard]]
bool AsBool()
const;
340 [[nodiscard]]
int AsInt()
const;
342 [[nodiscard]]
double AsDouble()
const;
350 [[nodiscard]] std::string
const&
AsString()
const;
358 [[nodiscard]] Array
const&
AsArray()
const;
366 [[nodiscard]] Object
const&
AsObject()
const;
376 friend std::ostream& operator<<(std::ostream& out,
Value const& value) {
377 switch (value.Type()) {
383 << (std::get<bool>(value.storage_) ?
"true" :
"false")
387 out <<
"number(" << std::get<double>(value.storage_) <<
")";
390 out <<
"string(" << std::get<std::string>(value.storage_)
394 out <<
"object(" << std::get<Object>(value.storage_) <<
")";
397 out <<
"array(" << std::get<Array>(value.storage_) <<
")";
403 operator bool()
const {
return AsBool(); }
405 operator std::string()
const {
return AsString(); }
407 operator double()
const {
return AsDouble(); }
409 operator int()
const {
return AsInt(); }
414 std::variant<null_type, bool, double, std::string, Array, Object> storage_;
419 static std::string
const empty_string_;
420 static Array
const empty_vector_;
421 static Object
const empty_map_;
422 static Value const null_value_;
425 bool operator==(Value
const& lhs, Value
const& rhs);
426 bool operator!=(Value
const& lhs, Value
const& rhs);
428 bool operator==(Value::Array
const& lhs, Value::Array
const& rhs);
429 bool operator!=(Value::Array
const& lhs, Value::Array
const& rhs);
431 bool operator==(Value::Object
const& lhs, Value::Object
const& rhs);
432 bool operator!=(Value::Object
const& lhs, Value::Object
const& rhs);
437 bool operator<(Value
const& lhs, Value
const& rhs);
442 bool operator>(Value
const& lhs, Value
const& rhs);
447 bool operator<=(Value
const& lhs, Value
const& rhs);
452 bool operator>=(Value
const& lhs, Value
const& rhs);
Array(std::vector< Value > vec)
Definition: value.cpp:191
Definition: value.hpp:116
Iterator Find(std::string const &key) const
Definition: value.cpp:228
Object(std::map< std::string, Value > map)
Definition: value.hpp:163
std::size_t Size() const
Definition: value.cpp:216
std::size_t Count(std::string const &key) const
Definition: value.cpp:232
Object const & AsObject() const
Definition: value.cpp:121
bool IsNumber() const
Definition: value.cpp:64
int AsInt() const
Definition: value.cpp:93
Value()
Definition: value.cpp:13
Array const & AsArray() const
Definition: value.cpp:114
bool IsArray() const
Definition: value.cpp:72
bool IsObject() const
Definition: value.cpp:76
std::string const & AsString() const
Definition: value.cpp:107
bool IsNull() const
Definition: value.cpp:56
bool IsBool() const
Definition: value.cpp:60
bool AsBool() const
Definition: value.cpp:86
bool IsString() const
Definition: value.cpp:68
static Value const & Null()
Definition: value.cpp:80
Definition: value.hpp:118