|
constexpr | datum (datum const &other) noexcept |
|
constexpr | datum (datum &&other) noexcept |
|
constexpr | datum (std::monostate) noexcept |
|
constexpr | datum (nullptr_t) noexcept |
|
constexpr | datum (continue_type) noexcept |
|
constexpr | datum (break_type) noexcept |
|
constexpr | datum (bool value) noexcept |
|
constexpr | datum (std::floating_point auto value) noexcept |
|
constexpr | datum (numeric_integral auto value) noexcept |
|
constexpr | datum (std::chrono::year_month_day value) noexcept |
|
| datum (std::string value) noexcept |
|
| datum (std::string_view value) noexcept |
|
| datum (char const *value) noexcept |
|
| datum (vector_type value) noexcept |
|
| datum (map_type value) noexcept |
|
| datum (bstring value) noexcept |
|
constexpr datum & | operator= (datum const &other) noexcept |
|
constexpr datum & | operator= (datum &&other) noexcept |
|
constexpr datum & | operator= (std::floating_point auto value) noexcept(sizeof(value)<=4) |
|
constexpr datum & | operator= (numeric_integral auto value) noexcept(sizeof(value)<=4) |
|
constexpr datum & | operator= (bool value) noexcept |
|
constexpr datum & | operator= (std::chrono::year_month_day value) noexcept |
|
constexpr datum & | operator= (std::monostate) noexcept |
|
constexpr datum & | operator= (nullptr_t) noexcept |
|
datum & | operator= (std::string value) noexcept |
|
datum & | operator= (char const *value) noexcept |
|
datum & | operator= (std::string_view value) noexcept |
|
datum & | operator= (vector_type value) noexcept |
|
datum & | operator= (map_type value) noexcept |
|
datum & | operator= (bstring value) noexcept |
|
constexpr | operator bool () const noexcept |
|
constexpr bool | empty () const |
|
template<std::floating_point T> |
constexpr | operator T () const |
|
template<numeric_integral T> |
constexpr | operator T () const |
|
constexpr | operator std::chrono::year_month_day () const |
|
| operator std::string () const noexcept |
|
| operator std::string_view () const |
|
| operator vector_type () const |
|
| operator map_type () const |
|
| operator bstring () const |
|
constexpr char const * | type_name () const noexcept |
|
constexpr bool | is_undefined () const noexcept |
| Check if the datum has an undefined value.
|
|
constexpr bool | is_break () const noexcept |
| Check if the result of a expression was a break flow control statement.
|
|
constexpr bool | is_continue () const noexcept |
| Check if the result of a expression was a continue flow control statement.
|
|
std::size_t | hash () const noexcept |
|
constexpr std::size_t | size () const |
|
constexpr datum const & | back () const |
|
constexpr datum & | back () |
|
constexpr datum const & | front () const |
|
constexpr datum & | front () |
|
constexpr auto | cbegin () const |
|
constexpr auto | begin () const |
|
constexpr auto | begin () |
|
constexpr auto | cend () const |
|
constexpr auto | end () const |
|
constexpr auto | end () |
|
vector_type | keys () const |
| Get the sorted list of keys of a map.
|
|
vector_type | values () const |
| Get the list of values of a map.
|
|
vector_type | items () const |
| Get key value pairs of items of a map sorted by the key.
|
|
constexpr void | push_back (datum const &rhs) |
|
constexpr void | push_back (datum &&rhs) |
|
template<typename Arg > |
constexpr void | push_back (Arg &&arg) |
|
constexpr void | pop_back () |
|
constexpr bool | contains (datum const &rhs) const |
|
template<typename Arg > |
constexpr bool | contains (Arg const &arg) const |
|
std::vector< datum * > | find (jsonpath const &path) noexcept |
|
std::vector< datum const * > | find (jsonpath const &path) const noexcept |
|
bool | remove (jsonpath const &path) noexcept |
| Remove the object by path.
|
|
datum * | find_one (jsonpath const &path) noexcept |
| Find a object by path.
|
|
datum * | find_one_or_create (jsonpath const &path) noexcept |
| Find a object by path potentially creating intermediate objects.
|
|
datum const * | find_one (jsonpath const &path) const noexcept |
| Find a object by path.
|
|
datum const & | operator[] (datum const &rhs) const |
|
constexpr datum & | operator[] (datum const &rhs) |
|
constexpr datum const & | operator[] (auto const &rhs) const |
|
constexpr datum & | operator[] (auto const &rhs) |
|
constexpr datum & | operator++ () |
|
constexpr datum & | operator-- () |
|
constexpr datum | operator++ (int) |
|
constexpr datum | operator-- (int) |
|
constexpr datum & | operator+= (auto const &rhs) |
|
| X (-=, -) X(* |
|
* | X (/=,/) X(% |
|
X(& | X (|=,|) X(^=, ^) X(<<=,<<) X(> >=, > >) friend constexpr bool operator==(datum const &lhs, datum const &rhs) noexcept { if(auto const doubles=promote_if< double >(lhs, rhs)) { return doubles.lhs()==doubles.rhs();} else if(auto const long_longs=promote_if< long long >(lhs, rhs)) { return long_longs.lhs()==long_longs.rhs();} else if(auto const bools=promote_if< bool >(lhs, rhs)) { return bools.lhs()==bools.rhs();} else if(auto const ymds=promote_if< std::chrono::year_month_day >(lhs, rhs)) { return ymds.lhs()==ymds.rhs();} else if(auto const strings=promote_if< std::string >(lhs, rhs)) { return strings.lhs()==strings.rhs();} else if(auto const vectors=promote_if< vector_type >(lhs, rhs)) { return vectors.lhs()==vectors.rhs();} else if(auto const maps=promote_if< map_type >(lhs, rhs)) { return maps.lhs()==maps.rhs();} else { return lhs._tag==rhs._tag;} } friend constexpr std::partial_ordering operator<=>(datum const &lhs, datum const &rhs) noexcept { if(auto const doubles=promote_if< double >(lhs, rhs)) { return doubles.lhs()<=> doubles.rhs();} else if(auto const long_longs=promote_if< long long >(lhs, rhs)) { return long_longs.lhs()<=> long_longs.rhs();} else if(auto const bools=promote_if< bool >(lhs, rhs)) { return bools.lhs()<=> bools.rhs();} else if(auto const year_month_days=promote_if< std::chrono::year_month_day >(lhs, rhs)) { return year_month_days.lhs()<=> year_month_days.rhs();} else if(auto const strings=promote_if< std::string >(lhs, rhs)) { return strings.lhs()<=> strings.rhs();} else if(auto const vectors=promote_if< vector_type >(lhs, rhs)) { return vectors.lhs()<=> vectors.rhs();} else if(auto const maps=promote_if< map_type >(lhs, rhs)) { return maps.lhs()<=> maps.rhs();} else if(auto const bstrings=promote_if< bstring >(lhs, rhs)) { return bstrings.lhs()<=> bstrings.rhs();} else { return lhs._tag<=> rhs._tag;} } friend constexpr datum operator-(datum const &rhs) { if(auto const rhs_double=get_if< double >(rhs)) { return datum{- *rhs_double};} else if(auto const rhs_long_long=get_if< long long >(rhs)) { return datum{- *rhs_long_long};} else { throw std::domain_error(std::format("Can not evaluate -{}", repr(rhs)));} } friend constexpr datum operator~(datum const &rhs) { if(auto const rhs_long_long=get_if< long long >(rhs)) { return datum{~ *rhs_long_long};} else { throw std::domain_error(std::format("Can not evaluate ~{}", repr(rhs)));} } friend constexpr datum operator+(datum const &lhs, datum const &rhs) { if(auto const doubles=promote_if< double >(lhs, rhs)) { return datum{doubles.lhs()+doubles.rhs()};} else if(auto const long_longs=promote_if< long long >(lhs, rhs)) { return datum{long_longs.lhs()+long_longs.rhs()};} else if(auto const strings=promote_if< std::string >(lhs, rhs)) { return datum{strings.lhs()+strings.rhs()};} else if(auto const vectors=promote_if< vector_type >(lhs, rhs)) { auto r=vectors.lhs();r.insert(r.end(), vectors.rhs().begin(), vectors.rhs().end());return datum{std::move(r)};} else { throw std::domain_error(std::format("Can not evaluate {} '+' {}", repr(lhs), repr(rhs)));} } friend constexpr datum operator-(datum const &lhs, datum const &rhs) { if(auto const doubles=promote_if< double >(lhs, rhs)) { return datum{doubles.lhs() - doubles.rhs()};} else if(auto const long_longs=promote_if< long long >(lhs, rhs)) { return datum{long_longs.lhs() - long_longs.rhs()};} else { throw std::domain_error(std::format("Can not evaluate {} '-' {}", repr(lhs), repr(rhs)));} } friend constexpr datum operator*(datum const &lhs, datum const &rhs) { if(auto const doubles=promote_if< double >(lhs, rhs)) { return datum{doubles.lhs() *doubles.rhs()};} else if(auto const long_longs=promote_if< long long >(lhs, rhs)) { return datum{long_longs.lhs() *long_longs.rhs()};} else { throw std::domain_error(std::format("Can not evaluate {} '*' {}", repr(lhs), repr(rhs)));} } friend constexpr datum operator/(datum const &lhs, datum const &rhs) { if(auto const doubles=promote_if< double >(lhs, rhs)) { if(doubles.rhs()==0) { throw std::domain_error(std::format("Divide by zero {} '/' {}", repr(lhs), repr(rhs)));} return datum{doubles.lhs()/doubles.rhs()};} else if(auto const long_longs=promote_if< long long >(lhs, rhs)) { if(long_longs.rhs()==0) { throw std::domain_error(std::format("Divide by zero {} '/' {}", repr(lhs), repr(rhs)));} return datum{long_longs.lhs()/long_longs.rhs()};} else { throw std::domain_error(std::format("Can not evaluate {} '/' {}", repr(lhs), repr(rhs)));} } friend constexpr datum operator%(datum const &lhs, datum const &rhs) { if(auto const long_longs=promote_if< long long >(lhs, rhs)) { if(long_longs.rhs()==0) { throw std::domain_error(std::format("Divide by zero {} '%' {}", repr(lhs), repr(rhs)));} return datum{long_longs.lhs() % long_longs.rhs()};} else { throw std::domain_error(std::format("Can not evaluate {} '%' {}", repr(lhs), repr(rhs)));} } friend constexpr datum pow(datum const &lhs, datum const &rhs) { if(auto const doubles=promote_if< double >(lhs, rhs)) { return datum{pow(doubles.lhs(), doubles.rhs())};} else if(auto const long_longs=promote_if< long long >(lhs, rhs)) { return datum{pow(long_longs.lhs(), long_longs.rhs())};} else { throw std::domain_error(std::format("Can not evaluate pow({}, {})", repr(lhs), repr(rhs)));} } friend constexpr datum operator&(datum const &lhs, datum const &rhs) { if(auto const long_longs=promote_if< long long >(lhs, rhs)) { return datum{long_longs.lhs() &long_longs.rhs()};} else if(auto const bools=promote_if< bool >(lhs, rhs)) { return datum{bools.lhs() and bools.rhs()};} else { throw std::domain_error(std::format("Can not evaluate {} '&' {}", repr(lhs), repr(rhs)));} } friend constexpr datum operator|(datum const &lhs, datum const &rhs) { if(auto const long_longs=promote_if< long long >(lhs, rhs)) { return datum{long_longs.lhs()|long_longs.rhs()};} else if(auto const bools=promote_if< bool >(lhs, rhs)) { return datum{bools.lhs() or bools.rhs()};} else { throw std::domain_error(std::format("Can not evaluate {} '|' {}", repr(lhs), repr(rhs)));} } friend constexpr datum operator^(datum const &lhs, datum const &rhs) { if(auto const long_longs=promote_if< long long >(lhs, rhs)) { return datum{long_longs.lhs() ^ long_longs.rhs()};} else if(auto const bools=promote_if< bool >(lhs, rhs)) { return datum{bools.lhs() !=bools.rhs()};} else { throw std::domain_error(std::format("Can not evaluate {} '^' {}", repr(lhs), repr(rhs)));} } friend constexpr datum operator<<(datum const &lhs, datum const &rhs) { if(auto const long_longs=promote_if< long long >(lhs, rhs)) { if(long_longs.rhs()< 0 or long_longs.rhs() >(sizeof(long long) *CHAR_BIT - 1)) { throw std::domain_error(std::format("Invalid shift count {} '<<' {}", repr(lhs), repr(rhs)));} return datum{long_longs.lhs()<< long_longs.rhs()};} else { throw std::domain_error(std::format("Can not evaluate {} '<<' {}", repr(lhs), repr(rhs)));} } friend constexpr datum operator>>(datum const &lhs, datum const &rhs) { if(auto const long_longs=promote_if< long long >(lhs, rhs)) { if(long_longs.rhs()< 0 or long_longs.rhs() >(sizeof(long long) *CHAR_BIT - 1)) { throw std::domain_error(std::format("Invalid shift count {} '>>' {}", repr(lhs), repr(rhs)));} return datum{long_longs.lhs() > > long_longs.rhs()};} else { throw std::domain_error(std::format("Can not evaluate {} '>>' {}", repr(lhs), repr(rhs)));} } friend std::ostream &operator<<(std::ostream &lhs, datum const &rhs) { return lhs<< to_string(rhs);}#define X(op) \ \ \ \ \ \ \ \ \ \ \ \ X(==) X(<=>) X(+) X(-) X(*) X(/) X(%) X(&) X(|) X(^) X(<<) X(> >) friend std::string repr(datum const &rhs) noexcept { switch(rhs._tag) { case tag_type::monostate:return "undefined";case tag_type::floating_point:return std::format("{:.1f}", rhs._value._double);case tag_type::integral:return std::format("{}", rhs._value._long_long);case tag_type::boolean:return rhs._value._bool ? "true" :"false";case tag_type::year_month_day:return std::format("{:%Y-%m-%d}", rhs._value._year_month_day);case tag_type::null:return "null";case tag_type::flow_break:return "break";case tag_type::flow_continue:return "continue";case tag_type::string:return std::format("\"{}\"", *rhs._value._string);case tag_type::vector:{ auto r=std::string{"["};for(auto const &item :*rhs._value._vector) { r+=repr(item);r+=',';} r+='] |
|
| for (auto const &item :*rhs._value._map) |
|
A dynamic data type.
This class holds data of different types, useful as the data-type used for variables of scripting languages, or for serializing and deserializing JSON and other object storage formats.
Not only does this datum handle the storage of data, but can also different operations which are dynamically executed.