25#ifndef JOIN_DATA_VALUE_HPP
26#define JOIN_DATA_VALUE_HPP
51 using Array = std::vector<Value>;
54 using Member = std::pair<Value, Value>;
63 :
public Variant<std::nullptr_t, bool, int32_t, uint32_t, int64_t, uint64_t, double, std::string, Array, Object>
90 using Variant::operator=;
200 throw std::bad_cast ();
208 explicit operator bool ()
const
252 return get<Integer> () >=
static_cast<int32_t
> (std::numeric_limits<int8_t>::min ()) &&
253 get<Integer> () <=
static_cast<int32_t
> (std::numeric_limits<int8_t>::max ());
256 return get<Unsigned> () <=
static_cast<uint32_t
> (std::numeric_limits<int8_t>::max ());
259 return get<Integer64> () >=
static_cast<int64_t
> (std::numeric_limits<int8_t>::min ()) &&
260 get<Integer64> () <=
static_cast<int64_t
> (std::numeric_limits<int8_t>::max ());
263 return get<Unsigned64> () <=
static_cast<uint64_t
> (std::numeric_limits<int8_t>::max ());
267 get<Real> () >=
static_cast<double> (std::numeric_limits<int8_t>::min ()) &&
268 get<Real> () <=
static_cast<double> (std::numeric_limits<int8_t>::max ());
301 return static_cast<int8_t
> (
get<Real> ());
305 throw std::bad_cast ();
313 explicit operator int8_t ()
const
328 get<Integer> () <=
static_cast<int32_t
> (std::numeric_limits<uint8_t>::max ());
331 return get<Unsigned> () <=
static_cast<uint32_t
> (std::numeric_limits<uint8_t>::max ());
335 get<Integer64> () <=
static_cast<int64_t
> (std::numeric_limits<uint8_t>::max ());
338 return get<Unsigned64> () <=
static_cast<uint64_t
> (std::numeric_limits<uint8_t>::max ());
342 get<Real> () <=
static_cast<double> (std::numeric_limits<uint8_t>::max ());
375 return static_cast<uint8_t
> (
get<Real> ());
379 throw std::bad_cast ();
387 explicit operator uint8_t ()
const
401 return get<Integer> () >=
static_cast<int32_t
> (std::numeric_limits<int16_t>::min ()) &&
402 get<Integer> () <=
static_cast<int32_t
> (std::numeric_limits<int16_t>::max ());
405 return get<Unsigned> () <=
static_cast<uint32_t
> (std::numeric_limits<int16_t>::max ());
408 return get<Integer64> () >=
static_cast<int64_t
> (std::numeric_limits<int16_t>::min ()) &&
409 get<Integer64> () <=
static_cast<int64_t
> (std::numeric_limits<int16_t>::max ());
412 return get<Unsigned64> () <=
static_cast<uint64_t
> (std::numeric_limits<int16_t>::max ());
416 get<Real> () >=
static_cast<double> (std::numeric_limits<int16_t>::min ()) &&
417 get<Real> () <=
static_cast<double> (std::numeric_limits<int16_t>::max ());
450 return static_cast<int16_t
> (
get<Real> ());
454 throw std::bad_cast ();
462 explicit operator int16_t ()
const
477 get<Integer> () <=
static_cast<int32_t
> (std::numeric_limits<uint16_t>::max ());
480 return get<Unsigned> () <=
static_cast<uint32_t
> (std::numeric_limits<uint16_t>::max ());
484 get<Integer64> () <=
static_cast<int64_t
> (std::numeric_limits<uint16_t>::max ());
487 return get<Unsigned64> () <=
static_cast<uint64_t
> (std::numeric_limits<uint16_t>::max ());
491 get<Real> () <=
static_cast<double> (std::numeric_limits<uint16_t>::max ());
524 return static_cast<uint16_t
> (
get<Real> ());
528 throw std::bad_cast ();
536 explicit operator uint16_t ()
const
553 return get<Unsigned> () <=
static_cast<uint32_t
> (std::numeric_limits<int32_t>::max ());
556 return get<Integer64> () >=
static_cast<int64_t
> (std::numeric_limits<int32_t>::min ()) &&
557 get<Integer64> () <=
static_cast<int64_t
> (std::numeric_limits<int32_t>::max ());
560 return get<Unsigned64> () <=
static_cast<uint64_t
> (std::numeric_limits<int32_t>::max ());
564 get<Real> () >=
static_cast<double> (std::numeric_limits<int32_t>::min ()) &&
565 get<Real> () <=
static_cast<double> (std::numeric_limits<int32_t>::max ());
598 return static_cast<int32_t
> (
get<Real> ());
602 throw std::bad_cast ();
610 explicit operator int32_t ()
const
631 get<Integer64> () <=
static_cast<int64_t
> (std::numeric_limits<uint32_t>::max ());
634 return get<Unsigned64> () <=
static_cast<uint64_t
> (std::numeric_limits<uint32_t>::max ());
638 get<Real> () <=
static_cast<double> (std::numeric_limits<uint32_t>::max ());
671 return static_cast<uint32_t
> (
get<Real> ());
675 throw std::bad_cast ();
683 explicit operator uint32_t ()
const
702 return get<Unsigned64> () <=
static_cast<uint64_t
> (std::numeric_limits<int64_t>::max ());
706 get<Real> () >=
static_cast<double> (std::numeric_limits<int64_t>::min ()) &&
707 get<Real> () <
static_cast<double> (std::numeric_limits<int64_t>::max ());
740 return static_cast<int64_t
> (
get<Real> ());
744 throw std::bad_cast ();
752 explicit operator int64_t ()
const
779 get<Real> () <
static_cast<double> (std::numeric_limits<uint64_t>::max ());
812 return static_cast<uint64_t
> (
get<Real> ());
816 throw std::bad_cast ();
824 explicit operator uint64_t ()
const
860 return static_cast<float> (
get<Real> ());
866 throw std::bad_cast ();
874 explicit operator float ()
const
916 throw std::bad_cast ();
924 explicit operator double ()
const
963 explicit operator const char* ()
const
1041 if (member.first ==
key)
1043 return member.second;
1047 throw std::out_of_range (
"invalid key");
1065 if (member.first ==
key)
1067 return member.second;
1071 throw std::out_of_range (
"invalid key");
1094 if (member.first ==
key)
1096 return member.second;
1127 throw std::bad_cast ();
1152 throw std::bad_cast ();
1180 throw std::bad_cast ();
1207 throw std::bad_cast ();
1245 for (
auto it = beg; it != end; ++it)
1247 if (it->first ==
key)
1263 template <
typename... Args>
1270 return get<ArrayValue> ().emplace_back (std::forward<Args> (args)...);
1328 if (member.first ==
key)
1343 Value temp (std::move (*
this));
1344 *
this = std::move (other);
1345 other = std::move (temp);
1354 template <
typename Reader>
1357 Reader reader (*
this);
1358 return reader.deserialize (document, length);
1367 template <
typename Reader>
1370 Reader reader (*
this);
1371 return reader.deserialize (first, last);
1379 template <
typename Reader>
1382 Reader reader (*
this);
1383 return reader.deserialize (document);
1391 template <
typename Reader>
1394 Reader reader (*
this);
1395 return reader.deserialize (document);
1403 template <
typename Reader>
1406 Reader reader (*
this);
1407 return reader.deserialize (document);
1415 template <
typename Reader>
1418 Reader reader (*
this);
1419 return reader.deserialize (document);
1427 template <
typename Reader>
1430 Reader reader (*
this);
1431 return reader.deserialize (document);
1439 template <
typename Reader>
1442 Reader reader (*
this);
1443 return reader.deserialize (document);
1451 template <
typename Reader>
1454 Reader reader (*
this);
1455 return reader.deserialize (document);
1463 template <
typename Writer>
1466 Writer writer (document);
1467 return writer.serialize (*
this);
1476 int jsonRead (
const char* document,
size_t length);
1484 int jsonRead (
const char* first,
const char* last);
1491 int jsonRead (
const std::string& document);
1498 int jsonRead (std::stringstream& document);
1505 int jsonRead (std::istringstream& document);
1512 int jsonRead (std::fstream& document);
1519 int jsonRead (std::ifstream& document);
1526 int jsonRead (std::iostream& document);
1533 int jsonRead (std::istream& document);
1540 int jsonWrite (std::ostream& document,
size_t indentation = 0)
const;
1555 int packRead (
const char* document,
size_t length);
1563 int packRead (
const char* first,
const char* last);
1570 int packRead (
const std::string& document);
1577 int packRead (std::stringstream& document);
1584 int packRead (std::istringstream& document);
1591 int packRead (std::fstream& document);
1598 int packRead (std::ifstream& document);
1605 int packRead (std::iostream& document);
1612 int packRead (std::istream& document);
1618 int packWrite (std::ostream& document)
const;
1651 return lhs.
equal (rhs);
1662 return !(lhs == rhs);
1689 return lhs.
lower (rhs);
1711 return !(rhs < lhs);
1722 return !(lhs < rhs);
value class.
Definition value.hpp:64
constexpr int32_t getInt() const
get variable held by value as a 32 bits integer.
Definition value.hpp:579
constexpr bool isFloat() const
check if the variable held by value is a float value.
Definition value.hpp:833
size_t size() const
returns the number of elements in the nested container.
Definition value.hpp:1135
void clear()
erases all elements in the nested container.
Definition value.hpp:1187
constexpr std::string & getString()
get variable held by value as a string value.
Definition value.hpp:953
void swap(Value &other)
exchanges the contents of the value with those of other.
Definition value.hpp:1341
constexpr bool isFalse() const
check if the content of the value is false.
Definition value.hpp:228
int deserialize(std::fstream &document)
deserialize a document.
Definition value.hpp:1416
const Value & at(const Value &key) const
returns a reference to the value at position pos or mapped to key.
Definition value.hpp:1056
int deserialize(std::iostream &document)
deserialize a document.
Definition value.hpp:1440
int serialize(std::ostream &document) const
serialize data.
Definition value.hpp:1464
constexpr int16_t getInt16() const
get variable held by value as a 16 bits integer.
Definition value.hpp:431
constexpr bool isInt() const
check if the variable held by value is a 32 bits integer value.
Definition value.hpp:545
friend constexpr bool operator<(const Value &lhs, const Value &rhs)
compare if lower than.
Definition value.hpp:1671
friend constexpr bool operator==(const Value &lhs, const Value &rhs)
compare if equal.
Definition value.hpp:1633
constexpr bool isInt64() const
check if the variable held by value is a 64 bits integer value.
Definition value.hpp:692
constexpr bool isUint16() const
check if the variable held by value is a 16 bits unsigned integer value.
Definition value.hpp:471
void popBack()
removes the last element of the nested container.
Definition value.hpp:1309
constexpr bool isTrue() const
check if the content of the value is true.
Definition value.hpp:218
Value & operator[](const Value &key)
returns a reference to the value at position pos or mapped to key.
Definition value.hpp:1080
constexpr const Array & getArray() const
get variable held by value as an array.
Definition value.hpp:982
Value & insert(Member &&member)
insert element in the nested container.
Definition value.hpp:1228
constexpr bool isArray() const
check if the variable held by value is an array.
Definition value.hpp:972
constexpr Value(const char *other)
constructs the value with the copy of the contents of a C-style string.
Definition value.hpp:101
constexpr const std::string & getString() const
get variable held by value as a string value.
Definition value.hpp:943
int deserialize(std::istringstream &document)
deserialize a document.
Definition value.hpp:1404
constexpr bool isUint64() const
check if the variable held by value is a 64 bits unsigned integer value.
Definition value.hpp:761
int deserialize(std::stringstream &document)
deserialize a document.
Definition value.hpp:1392
Value & pushBack(Value &&value)
appends element at the end of the nested container.
Definition value.hpp:1295
constexpr Object & getObject()
get variable held by value as an object.
Definition value.hpp:1021
int deserialize(std::ifstream &document)
deserialize a document.
Definition value.hpp:1428
constexpr bool isObject() const
check if the variable held by value is an object.
Definition value.hpp:1001
constexpr const Object & getObject() const
get variable held by value as an object.
Definition value.hpp:1011
void reserve(size_t cap)
increase the capacity of the nested container.
Definition value.hpp:1160
bool contains(const Value &key) const
checks if the nested container contains an element that is mapped to key.
Definition value.hpp:1319
constexpr uint8_t getUint8() const
get variable held by value as a 8 bits unsigned integer.
Definition value.hpp:356
size_t erase(const Value &key)
removes member with the key equivalent to key.
Definition value.hpp:1240
constexpr bool isUint() const
check if the variable held by value is a 32 bits unsigned integer value.
Definition value.hpp:619
Value & operator=(const char *other)
replaces the contents with a copy of a C-style string.
Definition value.hpp:111
constexpr bool isInt16() const
check if the variable held by value is a 16 bits integer value.
Definition value.hpp:396
int deserialize(const std::string &document)
deserialize a document.
Definition value.hpp:1380
constexpr bool getBool() const
get variable held by value as a boolean value.
Definition value.hpp:171
int jsonCanonicalize(std::ostream &document)
serialize canonicalized json data.
Definition value.cpp:133
int deserialize(const char *first, const char *last)
deserialize a document.
Definition value.hpp:1368
Index
nested value type index.
Definition value.hpp:70
@ Integer64
Definition value.hpp:75
@ Unsigned64
Definition value.hpp:76
@ Real
Definition value.hpp:77
@ Boolean
Definition value.hpp:72
@ String
Definition value.hpp:78
@ ArrayValue
Definition value.hpp:79
@ Integer
Definition value.hpp:73
@ Null
Definition value.hpp:71
@ Unsigned
Definition value.hpp:74
@ ObjectValue
Definition value.hpp:80
Value & pushBack(const Value &value)
appends element at the end of the nested container.
Definition value.hpp:1279
Value & at(const Value &key)
returns a reference to the value at position pos or mapped to key.
Definition value.hpp:1032
virtual ~Value()=default
destroy the Value instance.
int deserialize(const char *document, size_t length)
deserialize a document.
Definition value.hpp:1355
constexpr Value(Value &&other)=default
move constructor.
constexpr int8_t getInt8() const
get variable held by value as a 8 bits integer.
Definition value.hpp:282
constexpr double getDouble() const
get variable held by value as a double value.
Definition value.hpp:893
constexpr Value(const Value &other)=default
copy constructor.
constexpr uint32_t getUint() const
get variable held by value as a 32 bits unsigned integer value.
Definition value.hpp:652
constexpr bool isBool() const
check if the variable held by value is a boolean value.
Definition value.hpp:161
constexpr Value()=default
default constructor.
int jsonRead(const char *document, size_t length)
deserialize a json document.
Definition value.cpp:42
constexpr bool isString() const
check if the variable held by value is a string value.
Definition value.hpp:933
constexpr float getFloat() const
get variable held by value as a float value.
Definition value.hpp:843
constexpr bool isDouble() const
check if the variable held by value is a double value.
Definition value.hpp:883
Value & insert(const Member &member)
insert element in the nested container.
Definition value.hpp:1216
Value & emplaceBack(Args &&... args)
appends element at the end of the nested container.
Definition value.hpp:1264
constexpr uint64_t getUint64() const
get variable held by value as a 64 bits unsigned integer value.
Definition value.hpp:793
int packRead(const char *document, size_t length)
deserialize a msgpack document.
Definition value.cpp:142
bool empty() const
check if the nested container is empty.
Definition value.hpp:1110
constexpr bool isNumber() const
check if the variable held by value is a number value.
Definition value.hpp:237
int jsonWrite(std::ostream &document, size_t indentation=0) const
serialize json data.
Definition value.cpp:123
constexpr bool isNull() const
check if the variable held by value is a null value.
Definition value.hpp:152
constexpr uint16_t getUint16() const
get variable held by value as a 16 bits unsigned integer.
Definition value.hpp:505
constexpr bool isUint8() const
check if the variable held by value is a 8 bits unsigned integer value.
Definition value.hpp:322
constexpr int64_t getInt64() const
get variable held by value as a 64 bits integer value.
Definition value.hpp:721
int packWrite(std::ostream &document) const
serialize msgpack data.
Definition value.cpp:223
int deserialize(std::istream &document)
deserialize a document.
Definition value.hpp:1452
constexpr bool isInt8() const
check if the variable held by value is a 8 bits integer value.
Definition value.hpp:247
constexpr Array & getArray()
get variable held by value as an array.
Definition value.hpp:992
variant class.
Definition variant.hpp:352
constexpr bool lower(const Variant &rhs) const
check if lower than.
Definition variant.hpp:693
constexpr std::enable_if_t< is_unique< T, Ts... >::value, T & > get()
Definition variant.hpp:548
constexpr std::enable_if_t< is_unique< T, Ts... >::value &&std::is_constructible< T, Args &&... >::value, T & > set(Args &&... args)
Definition variant.hpp:496
constexpr std::size_t index() const noexcept
Definition variant.hpp:659
constexpr Variant()=default
default constructor.
constexpr Variant & operator=(const Variant &other)=default
copy assignment.
constexpr bool equal(const Variant &rhs) const
check if equal.
Definition variant.hpp:679
const std::string key(65, 'a')
key.
Definition acceptor.hpp:32
bool operator<(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoint is lower.
Definition endpoint.hpp:207
bool operator>(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoint is greater.
Definition endpoint.hpp:219
bool operator!=(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoints are not equal.
Definition endpoint.hpp:195
bool operator>=(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoint is greater or equal.
Definition endpoint.hpp:243
bool operator<=(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoint is lower or equal.
Definition endpoint.hpp:231
std::pair< Value, Value > Member
object member.
Definition value.hpp:54
std::vector< Value > Array
array.
Definition value.hpp:51
bool operator==(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoints are equal.
Definition endpoint.hpp:183
std::vector< Member > Object
object.
Definition value.hpp:57
disambiguation tag to indicate that the contained object should be constructed in-place.
Definition traits.hpp:57