3#include "../core/array.hpp"
4#include "../core/string.hpp"
8#if __has_include(<cereal/cereal.hpp>)
9#include <cereal/types/complex.hpp>
15typedef std::complex<double> cplx;
31 std::variant<bool, long, double, std::complex<double>,
zstring,
list> value;
35 enum { VOID, INT, FLOAT, COMPLEX, STRING, ARRAY };
97 explicit inline operator INT()
const {
397#if __has_include(<cereal/cereal.hpp>)
402 template <
typename archive>
404 const short int type = this->value.index();
408 ar(cereal::make_nvp(
"value",
array()));
409 }
else if (
type == STRING) {
410 ar(cereal::make_nvp(
"value",
string()));
411 }
else if (
type == COMPLEX) {
413 ar(cereal::make_nvp(
"value",
val));
414 }
else if (
type == FLOAT) {
416 }
else if (
type == INT) {
417 ar(cereal::make_nvp(
"value",
integer()));
425 template <
class archive>
427 short int type = VOID;
432 ar(cereal::make_nvp(
"value",
val));
434 }
else if (
type == STRING) {
436 ar(cereal::make_nvp(
"value",
val));
438 }
else if (
type == COMPLEX) {
439 std::complex<double>
val;
440 ar(cereal::make_nvp(
"value",
val));
442 }
else if (
type == FLOAT) {
444 ar(cereal::make_nvp(
"value",
val));
446 }
else if (
type == INT) {
448 ar(cereal::make_nvp(
"value",
val));
A wrapper for std::vector.
Definition array.hpp:38
A template class for character strings.
Definition string.hpp:62
A class for simple storage and manipulation of data regardless of type.
Definition generic.hpp:25
bool operator==(const generic &other) const
Check strict equality.
z::core::array< generic > list
typedef for an array of generic objects
Definition generic.hpp:28
generic & operator*=(const generic &other)
Multiply a value with this numeric value.
bool equals(const generic &other) const
Check strict equality.
Definition generic.hpp:371
bool reduce(bool castStrings=false) noexcept
Downcast a value as low as possible without losing precision.
generic & operator-=(const generic &other)
Subtract a value from this numeric value.
generic operator-(const generic &other) const
Subtract a value from this numeric value.
Definition generic.hpp:282
generic & operator%=(const generic &other)
Get the remainder of division by another value.
zstring toString(bool printArrays=false) const noexcept
Safely convert to a string.
bool promote(generic *other) noexcept
Upcast two values as much as is needed for them to be the same type.
const list & arrayOr(const list &def) const noexcept
Get a reference to this array, or a default value if this is not an array.
generic & operator/=(const generic &other)
Divide this value by another numeric value.
bool is(std::size_t type) const noexcept
Check if this value is a specific type.
std::complex< double > complex() const noexcept
Conversion to a complex value.
double floating() const noexcept
Conversion to floating point.
bool equivalent(const generic &other) const
Check loose equality.
bool operator!=(const generic &other) const
Check strict inequality.
Definition generic.hpp:380
int type() const noexcept
Get the current type of this object.
int reducesTo(bool castStrings=false) const noexcept
Get the lowest type this value can be cast to without losing precision.
list & array()
Get a reference to this array.
generic operator/(const generic &other) const
Divide this value by another numeric value.
Definition generic.hpp:320
long integer() const noexcept
Conversion to integer.
generic operator*(const generic &other) const
Multiply a value with this numeric value.
Definition generic.hpp:301
generic operator-() const
Get the negation of this value.
generic operator%(const generic &other) const
Get the remainder of division by another value.
Definition generic.hpp:341
zstring typeString() const noexcept
Get a character string representing the current type.
bool numeric() const noexcept
Whether this value is a numeric type.