25#ifndef JOIN_DATA_VALUE_HPP
26#define JOIN_DATA_VALUE_HPP
50 using Array = std::vector<Value>;
53 using Member = std::pair<Value, Value>;
62 :
public Variant<std::nullptr_t, bool, int32_t, uint32_t, int64_t, uint64_t, double, std::string, Array, Object>
89 using Variant::operator=;
199 throw std::bad_cast ();
207 explicit operator bool ()
const
251 return get<Integer> () >=
static_cast<int32_t
> (std::numeric_limits<int8_t>::min ()) &&
252 get<Integer> () <=
static_cast<int32_t
> (std::numeric_limits<int8_t>::max ());
255 return get<Unsigned> () <=
static_cast<uint32_t
> (std::numeric_limits<int8_t>::max ());
258 return get<Integer64> () >=
static_cast<int64_t
> (std::numeric_limits<int8_t>::min ()) &&
259 get<Integer64> () <=
static_cast<int64_t
> (std::numeric_limits<int8_t>::max ());
262 return get<Unsigned64> () <=
static_cast<uint64_t
> (std::numeric_limits<int8_t>::max ());
266 get<Real> () >=
static_cast<double> (std::numeric_limits<int8_t>::min ()) &&
267 get<Real> () <=
static_cast<double> (std::numeric_limits<int8_t>::max ());
300 return static_cast<int8_t
> (
get<Real> ());
304 throw std::bad_cast ();
312 explicit operator int8_t ()
const
327 get<Integer> () <=
static_cast<int32_t
> (std::numeric_limits<uint8_t>::max ());
330 return get<Unsigned> () <=
static_cast<uint32_t
> (std::numeric_limits<uint8_t>::max ());
334 get<Integer64> () <=
static_cast<int64_t
> (std::numeric_limits<uint8_t>::max ());
337 return get<Unsigned64> () <=
static_cast<uint64_t
> (std::numeric_limits<uint8_t>::max ());
341 get<Real> () <=
static_cast<double> (std::numeric_limits<uint8_t>::max ());
374 return static_cast<uint8_t
> (
get<Real> ());
378 throw std::bad_cast ();
386 explicit operator uint8_t ()
const
400 return get<Integer> () >=
static_cast<int32_t
> (std::numeric_limits<int16_t>::min ()) &&
401 get<Integer> () <=
static_cast<int32_t
> (std::numeric_limits<int16_t>::max ());
404 return get<Unsigned> () <=
static_cast<uint32_t
> (std::numeric_limits<int16_t>::max ());
407 return get<Integer64> () >=
static_cast<int64_t
> (std::numeric_limits<int16_t>::min ()) &&
408 get<Integer64> () <=
static_cast<int64_t
> (std::numeric_limits<int16_t>::max ());
411 return get<Unsigned64> () <=
static_cast<uint64_t
> (std::numeric_limits<int16_t>::max ());
415 get<Real> () >=
static_cast<double> (std::numeric_limits<int16_t>::min ()) &&
416 get<Real> () <=
static_cast<double> (std::numeric_limits<int16_t>::max ());
449 return static_cast<int16_t
> (
get<Real> ());
453 throw std::bad_cast ();
461 explicit operator int16_t ()
const
476 get<Integer> () <=
static_cast<int32_t
> (std::numeric_limits<uint16_t>::max ());
479 return get<Unsigned> () <=
static_cast<uint32_t
> (std::numeric_limits<uint16_t>::max ());
483 get<Integer64> () <=
static_cast<int64_t
> (std::numeric_limits<uint16_t>::max ());
486 return get<Unsigned64> () <=
static_cast<uint64_t
> (std::numeric_limits<uint16_t>::max ());
490 get<Real> () <=
static_cast<double> (std::numeric_limits<uint16_t>::max ());
523 return static_cast<uint16_t
> (
get<Real> ());
527 throw std::bad_cast ();
535 explicit operator uint16_t ()
const
552 return get<Unsigned> () <=
static_cast<uint32_t
> (std::numeric_limits<int32_t>::max ());
555 return get<Integer64> () >=
static_cast<int64_t
> (std::numeric_limits<int32_t>::min ()) &&
556 get<Integer64> () <=
static_cast<int64_t
> (std::numeric_limits<int32_t>::max ());
559 return get<Unsigned64> () <=
static_cast<uint64_t
> (std::numeric_limits<int32_t>::max ());
563 get<Real> () >=
static_cast<double> (std::numeric_limits<int32_t>::min ()) &&
564 get<Real> () <=
static_cast<double> (std::numeric_limits<int32_t>::max ());
597 return static_cast<int32_t
> (
get<Real> ());
601 throw std::bad_cast ();
609 explicit operator int32_t ()
const
630 get<Integer64> () <=
static_cast<int64_t
> (std::numeric_limits<uint32_t>::max ());
633 return get<Unsigned64> () <=
static_cast<uint64_t
> (std::numeric_limits<uint32_t>::max ());
637 get<Real> () <=
static_cast<double> (std::numeric_limits<uint32_t>::max ());
670 return static_cast<uint32_t
> (
get<Real> ());
674 throw std::bad_cast ();
682 explicit operator uint32_t ()
const
701 return get<Unsigned64> () <=
static_cast<uint64_t
> (std::numeric_limits<int64_t>::max ());
705 get<Real> () >=
static_cast<double> (std::numeric_limits<int64_t>::min ()) &&
706 get<Real> () <
static_cast<double> (std::numeric_limits<int64_t>::max ());
739 return static_cast<int64_t
> (
get<Real> ());
743 throw std::bad_cast ();
751 explicit operator int64_t ()
const
778 get<Real> () <
static_cast<double> (std::numeric_limits<uint64_t>::max ());
811 return static_cast<uint64_t
> (
get<Real> ());
815 throw std::bad_cast ();
823 explicit operator uint64_t ()
const
859 return static_cast<float> (
get<Real> ());
865 throw std::bad_cast ();
873 explicit operator float ()
const
915 throw std::bad_cast ();
923 explicit operator double ()
const
962 explicit operator const char* ()
const
1040 if (member.first ==
key)
1042 return member.second;
1046 throw std::out_of_range (
"invalid key");
1064 if (member.first ==
key)
1066 return member.second;
1070 throw std::out_of_range (
"invalid key");
1093 if (member.first ==
key)
1095 return member.second;
1126 throw std::bad_cast ();
1151 throw std::bad_cast ();
1179 throw std::bad_cast ();
1206 throw std::bad_cast ();
1244 for (
auto it = beg; it != end; ++it)
1246 if (it->first ==
key)
1262 template <
typename... Args>
1269 return get<ArrayValue> ().emplace_back (std::forward<Args> (args)...);
1327 if (member.first ==
key)
1342 Value temp (std::move (*
this));
1343 *
this = std::move (other);
1344 other = std::move (temp);
1353 template <
typename Reader>
1356 Reader reader (*
this);
1357 return reader.deserialize (document, length);
1366 template <
typename Reader>
1369 Reader reader (*
this);
1370 return reader.deserialize (first, last);
1378 template <
typename Reader>
1381 Reader reader (*
this);
1382 return reader.deserialize (document);
1390 template <
typename Reader>
1393 Reader reader (*
this);
1394 return reader.deserialize (document);
1402 template <
typename Reader>
1405 Reader reader (*
this);
1406 return reader.deserialize (document);
1414 template <
typename Reader>
1417 Reader reader (*
this);
1418 return reader.deserialize (document);
1426 template <
typename Reader>
1429 Reader reader (*
this);
1430 return reader.deserialize (document);
1438 template <
typename Reader>
1441 Reader reader (*
this);
1442 return reader.deserialize (document);
1450 template <
typename Reader>
1453 Reader reader (*
this);
1454 return reader.deserialize (document);
1462 template <
typename Writer>
1465 Writer writer (document);
1466 return writer.serialize (*
this);
1475 int jsonRead (
const char* document,
size_t length);
1483 int jsonRead (
const char* first,
const char* last);
1490 int jsonRead (
const std::string& document);
1497 int jsonRead (std::stringstream& document);
1504 int jsonRead (std::istringstream& document);
1511 int jsonRead (std::fstream& document);
1518 int jsonRead (std::ifstream& document);
1525 int jsonRead (std::iostream& document);
1532 int jsonRead (std::istream& document);
1539 int jsonWrite (std::ostream& document,
size_t indentation = 0)
const;
1554 int packRead (
const char* document,
size_t length);
1562 int packRead (
const char* first,
const char* last);
1569 int packRead (
const std::string& document);
1576 int packRead (std::stringstream& document);
1583 int packRead (std::istringstream& document);
1590 int packRead (std::fstream& document);
1597 int packRead (std::ifstream& document);
1604 int packRead (std::iostream& document);
1611 int packRead (std::istream& document);
1617 int packWrite (std::ostream& document)
const;
1650 return lhs.
equal (rhs);
1661 return !(lhs == rhs);
1688 return lhs.
lower (rhs);
1710 return !(rhs < lhs);
1721 return !(lhs < rhs);
value class.
Definition value.hpp:63
constexpr int32_t getInt() const
get variable held by value as a 32 bits integer.
Definition value.hpp:578
constexpr bool isFloat() const
check if the variable held by value is a float value.
Definition value.hpp:832
size_t size() const
returns the number of elements in the nested container.
Definition value.hpp:1134
void clear()
erases all elements in the nested container.
Definition value.hpp:1186
constexpr std::string & getString()
get variable held by value as a string value.
Definition value.hpp:952
void swap(Value &other)
exchanges the contents of the value with those of other.
Definition value.hpp:1340
constexpr bool isFalse() const
check if the content of the value is false.
Definition value.hpp:227
int deserialize(std::fstream &document)
deserialize a document.
Definition value.hpp:1415
const Value & at(const Value &key) const
returns a reference to the value at position pos or mapped to key.
Definition value.hpp:1055
int deserialize(std::iostream &document)
deserialize a document.
Definition value.hpp:1439
int serialize(std::ostream &document) const
serialize data.
Definition value.hpp:1463
constexpr int16_t getInt16() const
get variable held by value as a 16 bits integer.
Definition value.hpp:430
constexpr bool isInt() const
check if the variable held by value is a 32 bits integer value.
Definition value.hpp:544
friend constexpr bool operator<(const Value &lhs, const Value &rhs)
compare if lower than.
Definition value.hpp:1670
friend constexpr bool operator==(const Value &lhs, const Value &rhs)
compare if equal.
Definition value.hpp:1632
constexpr bool isInt64() const
check if the variable held by value is a 64 bits integer value.
Definition value.hpp:691
constexpr bool isUint16() const
check if the variable held by value is a 16 bits unsigned integer value.
Definition value.hpp:470
void popBack()
removes the last element of the nested container.
Definition value.hpp:1308
constexpr bool isTrue() const
check if the content of the value is true.
Definition value.hpp:217
Value & operator[](const Value &key)
returns a reference to the value at position pos or mapped to key.
Definition value.hpp:1079
constexpr const Array & getArray() const
get variable held by value as an array.
Definition value.hpp:981
Value & insert(Member &&member)
insert element in the nested container.
Definition value.hpp:1227
constexpr bool isArray() const
check if the variable held by value is an array.
Definition value.hpp:971
constexpr Value(const char *other)
constructs the value with the copy of the contents of a C-style string.
Definition value.hpp:100
constexpr const std::string & getString() const
get variable held by value as a string value.
Definition value.hpp:942
int deserialize(std::istringstream &document)
deserialize a document.
Definition value.hpp:1403
constexpr bool isUint64() const
check if the variable held by value is a 64 bits unsigned integer value.
Definition value.hpp:760
int deserialize(std::stringstream &document)
deserialize a document.
Definition value.hpp:1391
Value & pushBack(Value &&value)
appends element at the end of the nested container.
Definition value.hpp:1294
constexpr Object & getObject()
get variable held by value as an object.
Definition value.hpp:1020
int deserialize(std::ifstream &document)
deserialize a document.
Definition value.hpp:1427
constexpr bool isObject() const
check if the variable held by value is an object.
Definition value.hpp:1000
constexpr const Object & getObject() const
get variable held by value as an object.
Definition value.hpp:1010
void reserve(size_t cap)
increase the capacity of the nested container.
Definition value.hpp:1159
bool contains(const Value &key) const
checks if the nested container contains an element that is mapped to key.
Definition value.hpp:1318
constexpr uint8_t getUint8() const
get variable held by value as a 8 bits unsigned integer.
Definition value.hpp:355
size_t erase(const Value &key)
removes member with the key equivalent to key.
Definition value.hpp:1239
constexpr bool isUint() const
check if the variable held by value is a 32 bits unsigned integer value.
Definition value.hpp:618
Value & operator=(const char *other)
replaces the contents with a copy of a C-style string.
Definition value.hpp:110
constexpr bool isInt16() const
check if the variable held by value is a 16 bits integer value.
Definition value.hpp:395
int deserialize(const std::string &document)
deserialize a document.
Definition value.hpp:1379
constexpr bool getBool() const
get variable held by value as a boolean value.
Definition value.hpp:170
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:1367
Index
nested value type index.
Definition value.hpp:69
@ Integer64
Definition value.hpp:74
@ Unsigned64
Definition value.hpp:75
@ Real
Definition value.hpp:76
@ Boolean
Definition value.hpp:71
@ String
Definition value.hpp:77
@ ArrayValue
Definition value.hpp:78
@ Integer
Definition value.hpp:72
@ Null
Definition value.hpp:70
@ Unsigned
Definition value.hpp:73
@ ObjectValue
Definition value.hpp:79
Value & pushBack(const Value &value)
appends element at the end of the nested container.
Definition value.hpp:1278
Value & at(const Value &key)
returns a reference to the value at position pos or mapped to key.
Definition value.hpp:1031
virtual ~Value()=default
destroy the Value instance.
int deserialize(const char *document, size_t length)
deserialize a document.
Definition value.hpp:1354
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:281
constexpr double getDouble() const
get variable held by value as a double value.
Definition value.hpp:892
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:651
constexpr bool isBool() const
check if the variable held by value is a boolean value.
Definition value.hpp:160
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:932
constexpr float getFloat() const
get variable held by value as a float value.
Definition value.hpp:842
constexpr bool isDouble() const
check if the variable held by value is a double value.
Definition value.hpp:882
Value & insert(const Member &member)
insert element in the nested container.
Definition value.hpp:1215
Value & emplaceBack(Args &&... args)
appends element at the end of the nested container.
Definition value.hpp:1263
constexpr uint64_t getUint64() const
get variable held by value as a 64 bits unsigned integer value.
Definition value.hpp:792
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:1109
constexpr bool isNumber() const
check if the variable held by value is a number value.
Definition value.hpp:236
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:151
constexpr uint16_t getUint16() const
get variable held by value as a 16 bits unsigned integer.
Definition value.hpp:504
constexpr bool isUint8() const
check if the variable held by value is a 8 bits unsigned integer value.
Definition value.hpp:321
constexpr int64_t getInt64() const
get variable held by value as a 64 bits integer value.
Definition value.hpp:720
int packWrite(std::ostream &document) const
serialize msgpack data.
Definition value.cpp:223
int deserialize(std::istream &document)
deserialize a document.
Definition value.hpp:1451
constexpr bool isInt8() const
check if the variable held by value is a 8 bits integer value.
Definition value.hpp:246
constexpr Array & getArray()
get variable held by value as an array.
Definition value.hpp:991
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 BasicLinkLayerEndpoint< Protocol > &a, const BasicLinkLayerEndpoint< Protocol > &b) noexcept
compare if endpoint is lower or equal.
Definition endpoint.hpp:234
bool operator==(const BasicLinkLayerEndpoint< Protocol > &a, const BasicLinkLayerEndpoint< Protocol > &b) noexcept
compare if endpoints are equal.
Definition endpoint.hpp:186
bool operator!=(const BasicLinkLayerEndpoint< Protocol > &a, const BasicLinkLayerEndpoint< Protocol > &b) noexcept
compare if endpoints are not equal.
Definition endpoint.hpp:198
bool operator>=(const BasicLinkLayerEndpoint< Protocol > &a, const BasicLinkLayerEndpoint< Protocol > &b) noexcept
compare if endpoint is greater or equal.
Definition endpoint.hpp:246
std::pair< Value, Value > Member
object member.
Definition value.hpp:53
bool operator<(const BasicDatagramSocket< Protocol > &a, const BasicDatagramSocket< Protocol > &b) noexcept
compare if socket handle is inferior.
Definition datagram_socket.hpp:394
std::vector< Value > Array
array.
Definition value.hpp:50
std::vector< Member > Object
object.
Definition value.hpp:56
bool operator>(const BasicLinkLayerEndpoint< Protocol > &a, const BasicLinkLayerEndpoint< Protocol > &b) noexcept
compare if endpoint is greater.
Definition endpoint.hpp:222
disambiguation tag to indicate that the contained object should be constructed in-place.
Definition traits.hpp:57