25#ifndef __JOIN_VALUE_HPP__
26#define __JOIN_VALUE_HPP__
51 using Array = std::vector <Value>;
54 using Member = std::pair <std::string, Value>;
62 class Value :
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
250 return get <Integer> () >=
static_cast <int32_t
> (std::numeric_limits <int8_t>::min ()) &&
251 get <Integer> () <=
static_cast <int32_t
> (std::numeric_limits <int8_t>::max ());
254 return get <Unsigned> () <=
static_cast <uint32_t
> (std::numeric_limits <int8_t>::max ());
257 return get <Integer64> () >=
static_cast <int64_t
> (std::numeric_limits <int8_t>::min ()) &&
258 get <Integer64> () <=
static_cast <int64_t
> (std::numeric_limits <int8_t>::max ());
261 return get <Unsigned64> () <=
static_cast <uint64_t
> (std::numeric_limits <int8_t>::max ());
265 get <Real> () >=
static_cast <double> (std::numeric_limits <int8_t>::min ()) &&
266 get <Real> () <=
static_cast <double> (std::numeric_limits <int8_t>::max ());
303 throw std::bad_cast ();
311 explicit operator int8_t ()
const
326 get <Integer> () <=
static_cast <int32_t
> (std::numeric_limits <uint8_t>::max ());
329 return get <Unsigned> () <=
static_cast <uint32_t
> (std::numeric_limits <uint8_t>::max ());
333 get <Integer64> () <=
static_cast <int64_t
> (std::numeric_limits <uint8_t>::max ());
336 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 ());
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 ());
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 ());
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 ());
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 ());
639 get <Real> () <=
static_cast <double> (std::numeric_limits <uint32_t>::max ());
672 return static_cast <uint32_t
> (
get <Real> ());
676 throw std::bad_cast ();
684 explicit operator uint32_t ()
const
703 return get <Unsigned64> () <=
static_cast <uint64_t
> (std::numeric_limits <int64_t>::max ());
707 get <Real> () >=
static_cast <double> (std::numeric_limits <int64_t>::min ()) &&
708 get <Real> () <
static_cast <double> (std::numeric_limits <int64_t>::max ());
745 throw std::bad_cast ();
753 explicit operator int64_t ()
const
781 get <Real> () <
static_cast <double> (std::numeric_limits <uint64_t>::max ());
814 return static_cast <uint64_t
> (
get <Real> ());
818 throw std::bad_cast ();
826 explicit operator uint64_t ()
const
868 throw std::bad_cast ();
876 explicit operator float ()
const
918 throw std::bad_cast ();
926 explicit operator double ()
const
965 explicit operator const char * ()
const
1060 if (member.first ==
key)
1062 return member.second;
1066 throw std::out_of_range (
"invalid key");
1079 if (member.first ==
key)
1081 return member.second;
1085 throw std::out_of_range (
"invalid key");
1114 if (member.first ==
key)
1116 return member.second;
1147 throw std::bad_cast ();
1172 throw std::bad_cast ();
1200 throw std::bad_cast ();
1227 throw std::bad_cast ();
1265 for (
auto it = beg; it != end; ++it)
1267 if (it->first ==
key)
1283 template <
typename... Args>
1353 if (member.first ==
key)
1368 Value temp (std::move (*
this));
1369 *
this = std::move (other);
1370 other = std::move (temp);
1379 template <
typename Reader>
1382 Reader reader (*
this);
1383 return reader.deserialize (document, length);
1392 template <
typename Reader>
1395 Reader reader (*
this);
1396 return reader.deserialize (first, last);
1404 template <
typename Reader>
1407 Reader reader (*
this);
1408 return reader.deserialize (document);
1416 template <
typename Reader>
1419 Reader reader (*
this);
1420 return reader.deserialize (document);
1428 template <
typename Reader>
1431 Reader reader (*
this);
1432 return reader.deserialize (document);
1440 template <
typename Reader>
1443 Reader reader (*
this);
1444 return reader.deserialize (document);
1452 template <
typename Reader>
1455 Reader reader (*
this);
1456 return reader.deserialize (document);
1464 template <
typename Reader>
1467 Reader reader (*
this);
1468 return reader.deserialize (document);
1476 template <
typename Reader>
1479 Reader reader (*
this);
1480 return reader.deserialize (document);
1488 template <
typename Writer>
1491 Writer writer (document);
1492 return writer.serialize (*
this);
1501 int jsonRead (
const char* document,
size_t length);
1509 int jsonRead (
const char* first,
const char* last);
1516 int jsonRead (
const std::string& document);
1523 int jsonRead (std::stringstream& document);
1530 int jsonRead (std::istringstream& document);
1537 int jsonRead (std::fstream& document);
1544 int jsonRead (std::ifstream& document);
1551 int jsonRead (std::iostream& document);
1558 int jsonRead (std::istream& document);
1565 int jsonWrite (std::ostream& document,
size_t indentation = 0)
const;
1580 int packRead (
const char* document,
size_t length);
1588 int packRead (
const char* first,
const char* last);
1595 int packRead (
const std::string& document);
1602 int packRead (std::stringstream& document);
1609 int packRead (std::istringstream& document);
1616 int packRead (std::fstream& document);
1623 int packRead (std::ifstream& document);
1630 int packRead (std::iostream& document);
1637 int packRead (std::istream& document);
1643 int packWrite (std::ostream& document)
const;
1676 return lhs.
equal (rhs);
1687 return !(lhs == rhs);
1714 return lhs.
lower (rhs);
1736 return !(rhs < lhs);
1747 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:579
constexpr bool isFloat() const
check if the variable held by value is a float value.
Definition value.hpp:835
size_t size() const
returns the number of elements in the nested container.
Definition value.hpp:1155
void clear()
erases all elements in the nested container.
Definition value.hpp:1207
constexpr std::string & getString()
get variable held by value as a string value.
Definition value.hpp:955
void swap(Value &other)
exchanges the contents of the value with those of other.
Definition value.hpp:1366
constexpr bool isFalse() const
check if the content of the value is false.
Definition value.hpp:227
const Value & at(size_t pos) const
returns a reference to the element at specified location pos.
Definition value.hpp:1045
int deserialize(std::fstream &document)
deserialize a document.
Definition value.hpp:1441
int deserialize(std::iostream &document)
deserialize a document.
Definition value.hpp:1465
int serialize(std::ostream &document) const
serialize data.
Definition value.hpp:1489
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:545
size_t erase(const std::string &key)
removes member with the key equivalent to key.
Definition value.hpp:1260
friend constexpr bool operator<(const Value &lhs, const Value &rhs)
compare if lower than.
Definition value.hpp:1696
friend constexpr bool operator==(const Value &lhs, const Value &rhs)
compare if equal.
Definition value.hpp:1658
constexpr bool isInt64() const
check if the variable held by value is a 64 bits integer value.
Definition value.hpp:693
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:1329
constexpr bool isTrue() const
check if the content of the value is true.
Definition value.hpp:217
constexpr const Array & getArray() const
get variable held by value as an array.
Definition value.hpp:984
Value & insert(Member &&member)
insert element in the nested container.
Definition value.hpp:1248
constexpr bool isArray() const
check if the variable held by value is an array.
Definition value.hpp:974
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:945
int deserialize(std::istringstream &document)
deserialize a document.
Definition value.hpp:1429
constexpr bool isUint64() const
check if the variable held by value is a 64 bits unsigned integer value.
Definition value.hpp:762
int deserialize(std::stringstream &document)
deserialize a document.
Definition value.hpp:1417
Value & pushBack(Value &&value)
appends element at the end of the nested container.
Definition value.hpp:1315
constexpr Object & getObject()
get variable held by value as an object.
Definition value.hpp:1023
int deserialize(std::ifstream &document)
deserialize a document.
Definition value.hpp:1453
constexpr bool isObject() const
check if the variable held by value is an object.
Definition value.hpp:1003
constexpr const Object & getObject() const
get variable held by value as an object.
Definition value.hpp:1013
void reserve(size_t cap)
increase the capacity of the nested container.
Definition value.hpp:1180
constexpr uint8_t getUint8() const
get variable held by value as a 8 bits unsigned integer.
Definition value.hpp:355
Value & operator[](size_t pos)
returns a reference to the element at specified location pos.
Definition value.hpp:1094
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: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:1405
const Value & at(const std::string &key) const
returns a reference to the value that is mapped to a key.
Definition value.hpp:1075
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:1393
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:1299
virtual ~Value()=default
destroy the Value instance.
int deserialize(const char *document, size_t length)
deserialize a document.
Definition value.hpp:1380
Value & at(size_t pos)
returns a reference to the element at specified location pos.
Definition value.hpp:1034
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:280
bool contains(size_t pos) const
checks if the nested container contains an element at position pos.
Definition value.hpp:1339
constexpr double getDouble() const
get variable held by value as a double value.
Definition value.hpp:895
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:653
constexpr bool isBool() const
check if the variable held by value is a boolean value.
Definition value.hpp:160
Value & at(const std::string &key)
returns a reference to the value that is mapped to a key.
Definition value.hpp:1056
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:935
constexpr float getFloat() const
get variable held by value as a float value.
Definition value.hpp:845
constexpr bool isDouble() const
check if the variable held by value is a double value.
Definition value.hpp:885
Value & insert(const Member &member)
insert element in the nested container.
Definition value.hpp:1236
Value & emplaceBack(Args &&... args)
appends element at the end of the nested container.
Definition value.hpp:1284
constexpr uint64_t getUint64() const
get variable held by value as a 64 bits unsigned integer value.
Definition value.hpp:795
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:1130
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:505
constexpr bool isUint8() const
check if the variable held by value is a 8 bits unsigned integer value.
Definition value.hpp:320
bool contains(const std::string &key) const
checks if the nested container contains an element that is mapped to key.
Definition value.hpp:1349
constexpr int64_t getInt64() const
get variable held by value as a 64 bits integer value.
Definition value.hpp:722
int packWrite(std::ostream &document) const
serialize msgpack data.
Definition value.cpp:223
int deserialize(std::istream &document)
deserialize a document.
Definition value.hpp:1477
constexpr bool isInt8() const
check if the variable held by value is a 8 bits integer value.
Definition value.hpp:245
constexpr Array & getArray()
get variable held by value as an array.
Definition value.hpp:994
variant class.
Definition variant.hpp:375
constexpr bool lower(const Variant &rhs) const
check if lower than.
Definition variant.hpp:729
constexpr std::enable_if_t< is_unique< T, Ts... >::value, T & > get()
Definition variant.hpp:584
constexpr std::size_t index() const noexcept
Definition variant.hpp:704
constexpr Variant()=default
default constructor.
constexpr Variant & operator=(const Variant &other)=default
copy assignment.
constexpr std::enable_if_t< is_unique< T, Ts... >::value &&std::is_constructible< T, Args &&... >::value, T & > set(Args &&...args)
Definition variant.hpp:532
constexpr bool equal(const Variant &rhs) const
check if equal.
Definition variant.hpp:715
const std::string key(65, 'a')
key.
Definition acceptor.hpp:32
std::pair< std::string, Value > Member
object member.
Definition value.hpp:54
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::vector< Value > Array
array.
Definition value.hpp:51
std::vector< Member > Object
object.
Definition value.hpp:57
bool operator==(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoints are equal.
Definition endpoint.hpp:183
disambiguation tag to indicate that the contained object should be constructed in-place.
Definition traits.hpp:57