Skip to content

Value

class Value

Class representing a value of any type.

constructor Value()

Create void value.

constructor Value(bool value)

Create a boolean value.

ParameterDescription
value

The boolean value.

TYPE: bool

constructor Value(double value)

Create a floating point value.

ParameterDescription
value

The floating point value.

TYPE: double

constructor Value(const std::string &value)

Create a binary value.

ParameterDescription
value

The binary data.

TYPE: const std::string &

constructor Value(Symbol value)

Create a string value.

ParameterDescription
value

The string value.

TYPE: Symbol

constructor Value(uint64_t value, uint64_t default_size = 0)

Create a unsigned value.

ParameterDescription
value

The unsigned integer value.

TYPE: uint64_t

default_size

Explicitly set the default size of the value. Otherwise the smallest size that can hold the value is used.

TYPE: uint64_tDEFAULT: 0

constructor Value(int64_t value, uint64_t default_size = 0)

Create a signed value.

ParameterDescription
value

The signed integer value.

TYPE: int64_t

default_size

Explicitly set the default size of the value. Otherwise the smallest size that can hold the value is used.

TYPE: uint64_tDEFAULT: 0

method std::string binary_value()

Get the binary data of the value.

ReturnsDescription
std::string

The value as binary data.

ThrowsDescription
Exception

if the value is not binary data.

method bool boolean_value()

Interpret value as a boolean.

Numbers are true if they are nonzero, strings are true if they are nonempty. Binary data and void values can't be interpreted as booleans.

ReturnsDescription
bool

The value as a boolean.

ThrowsDescription
Exception

Value can't be interpreted as a boolean.

method std::optional< uint64_t > default_size()

Get the default size of the value.

For integer values, this is the smallest size that can hold the value, or the explicitly set default size if it is larger. For binary data, this is its size in bytes.

ReturnsDescription
std::optional< uint64_t >

The default size of the value, if it has a default size.

method double float_value()

Get the floating point value.

ReturnsDescription
double

The value as a floating point number.

ThrowsDescription
Exception

if the value is not a number.

method bool is_binary()

Check if value is binary data.

ReturnsDescription
bool

true if it is binary data, false otherwise.

method bool is_boolean()

Check if it is a boolean value.

ReturnsDescription
bool

true if it is a boolean value, false otherwise.

method bool is_float()

Check if it is a floating point number.

ReturnsDescription
bool

true if it is a floating point number, false otherwise.

method bool is_integer()

Check if it is an integer.

ReturnsDescription
bool

true if it is an integer, false otherwise.

method bool is_number()

Check if it is a number (integer or floating point).

ReturnsDescription
bool

true if it is a number, false otherwise.

method bool is_signed()

Check if it is a signed integer.

ReturnsDescription
bool

true if it is a signed integer, false otherwise.

method bool is_string()

Check if it is a string.

ReturnsDescription
bool

true if it is a string, false otherwise.

method bool is_unsigned()

Check if it is an unsigned integer.

ReturnsDescription
bool

true if it is an unsigned integer, false otherwise.

method bool is_void()

Check if it is void (has no value).

ReturnsDescription
bool

true if it is void, false otherwise.

method operator bool()

Interpret the value as a boolean.

Numbers are true if they are nonzero, strings are true if they are nonempty. Binary data and void values can't be interpreted as booleans.

ThrowsDescription
Exception

Value can't be interpreted as a boolean.

method bool operator!=(const Value &other)

Check if two values are different.

ParameterDescription
other

The value to compare with.

TYPE: const Value &

ReturnsDescription
bool

true if the values are different, false otherwise.

method Value operator%(const Value &other)

The remainder of this value divided by another value.

ParameterDescription
other

The value to divide by.

TYPE: const Value &

ReturnsDescription
Value

The remainder of the division.

ThrowsDescription
Exception

if either value is not an unsigned integer or if dividing by zero.

method Value operator&(const Value &other)

Bitwise AND of this value and another value.

ParameterDescription
other

The value to AND with.

TYPE: const Value &

ReturnsDescription
Value

The result of the bitwise AND operation.

ThrowsDescription
Exception

if either value is not an unsigned integer.

method Value operator&(uint64_t other)

Bitwise AND of this value and an unsigned integer.

ParameterDescription
other

The unsigned integer to AND with.

TYPE: uint64_t

ReturnsDescription
Value

The result of the bitwise AND operation.

ThrowsDescription
Exception

if this value is not an unsigned integer.

method Value operator&&(const Value &other)

Logical AND of this value and another value.

ParameterDescription
other

The value to AND with.

TYPE: const Value &

ReturnsDescription
Value

True if both values are true.

ThrowsDescription
Exception

if either value can't be interpreted as a boolean.

method Value operator*(const Value &other)

Multiply this value by another value.

ParameterDescription
other

The value to multiply by.

TYPE: const Value &

ReturnsDescription
Value

The product of the two values.

ThrowsDescription
Exception

if either value is not a number or if the multiplication would overflow.

method Value &operator*=(const Value &other)

Multiply this value by another value, modifying this value.

ParameterDescription
other

The value to multiply by.

TYPE: const Value &

ReturnsDescription
Value &

This value after multiplication.

ThrowsDescription
Exception

if either value is not a number or if the multiplication would overflow.

method Value operator+(const Value &other)

Add another value to this value.

ParameterDescription
other

The value to add.

TYPE: const Value &

ReturnsDescription
Value

The sum of the two values.

ThrowsDescription
Exception

if either value is not a number or if the addition would overflow.

method Value &operator+=(const Value &other)

Add another value to this value, modifying this value.

ParameterDescription
other

The value to add.

TYPE: const Value &

ReturnsDescription
Value &

This value after addition.

ThrowsDescription
Exception

if either value is not a number or if the addition would overflow.

method Value operator-()

Negate value.

ReturnsDescription
Value

The negated value.

ThrowsDescription
Exception

if the value is not a number.

method Value operator-(const Value &other)

Subtract another value from this value.

ParameterDescription
other

The value to subtract.

TYPE: const Value &

ReturnsDescription
Value

The difference of the two values.

ThrowsDescription
Exception

if either value is not a number or if the subtraction would overflow.

method Value &operator-=(const Value &other)

Subtract another value from this value, modifying this value.

ParameterDescription
other

The value to subtract.

TYPE: const Value &

ReturnsDescription
Value &

This value after subtraction.

ThrowsDescription
Exception

if either value is not a number or if the subtraction would overflow.

method Value operator/(const Value &other)

Divide this value by another value.

ParameterDescription
other

The value to divide by.

TYPE: const Value &

ReturnsDescription
Value

The quotient of the two values.

ThrowsDescription
Exception

if either value is not a number or if dividing by zero.

method Value &operator/=(const Value &other)

Divide this value by another value, modifying this value.

ParameterDescription
other

The value to divide by.

TYPE: const Value &

ReturnsDescription
Value &

This value after division.

ThrowsDescription
Exception

if either value is not a number or if dividing by zero.

method bool operator<(const Value &other)

Check if this value is less than another value. Only numbers are comparable.

ParameterDescription
other

The value to compare with.

TYPE: const Value &

ReturnsDescription
bool

true if both values are numbers and this value is less than the other value, false otherwise.

method Value operator<<(const Value &other)

Left shift this value by another value.

ParameterDescription
other

The value to shift by.

TYPE: const Value &

ReturnsDescription
Value

The result of the left shift operation.

ThrowsDescription
Exception

if either value is not an integer or an overflow occurs.

method bool operator<=(const Value &other)

Check if this value is less than or equal to another value. Only numbers are comparable.

ParameterDescription
other

The value to compare with.

TYPE: const Value &

ReturnsDescription
bool

true if both values are numbers and this value is less than or equal to the other value, false otherwise.

method bool operator==(const Value &other)

Check if two values are equal.

ParameterDescription
other

The value to compare with.

TYPE: const Value &

ReturnsDescription
bool

true if the values are equal, false otherwise.

method bool operator>(const Value &other)

Check if this value is greater than another value. Only numbers are comparable.

ParameterDescription
other

The value to compare with.

TYPE: const Value &

ReturnsDescription
bool

true if both values are numbers and this value is greater than the other value, false otherwise.

method bool operator>=(const Value &other)

Check if this value is greater than or equal to another value. Only numbers are comparable.

ParameterDescription
other

The value to compare with.

TYPE: const Value &

ReturnsDescription
bool

true if both values are numbers and this value is greater than or equal to the other value, false otherwise.

method Value operator>>(const Value &other)

Right shift this value by another value.

ParameterDescription
other

The value to shift by.

TYPE: const Value &

ReturnsDescription
Value

The result of the right shift operation.

ThrowsDescription
Exception

if either value is not an integer or an overflow occurs.

method Value operator>>(uint64_t other)

Left shift this value by an unsigned integer.

ParameterDescription
other

The unsigned integer to shift by.

TYPE: uint64_t

ReturnsDescription
Value

The result of the left shift operation.

ThrowsDescription
Exception

if this value is not an integer or an overflow occurs.

method Value operator^(const Value &other)

Bitwise exclusive OR of this value and another value.

ParameterDescription
other

The value to exclusive OR with.

TYPE: const Value &

ReturnsDescription
Value

The result of the bitwise exclusive OR operation.

ThrowsDescription
Exception

if either value is not an unsigned integer.

method Value operator|(const Value &other)

Bitwise OR of this value and another value.

ParameterDescription
other

The value to OR with.

TYPE: const Value &

ReturnsDescription
Value

The result of the bitwise OR operation.

ThrowsDescription
Exception

if either value is not an unsigned integer.

method Value operator||(const Value &other)

Logical OR of this value and another value.

ParameterDescription
other

The value to OR with.

TYPE: const Value &

ReturnsDescription
Value

True if either value is true.

ThrowsDescription
Exception

if either value can't be interpreted as a boolean.

method Value operator~()

Bitwise NOT of the value.

ReturnsDescription
Value

The bitwise NOT of the value.

ThrowsDescription
Exception

if the value is not an integer.

method void serialize(std::ostream &stream)

Serialize the value to a stream.

ParameterDescription
stream

The stream to serialize to.

TYPE: std::ostream &

method int64_t signed_value()

Get the signed integer value.

ReturnsDescription
int64_t

The value as a signed integer.

ThrowsDescription
Exception

if the value is not an integer or doesn't fit in a signed integer.

method std::string string_value()

Get string representation of the value.

Numbers are converted to their string representation, strings are returned as they are. Boolean, binary data and void values can't be interpreted as strings.

ReturnsDescription
std::string

The value as a string.

ThrowsDescription
Exception

if the value can't be interpreted as a string.

method Symbol symbol_value()

Get the symbol for string value.

ReturnsDescription
Symbol

The value as a symbol.

ThrowsDescription
Exception

if the value is not a string.

method Type type()

Get the type of the value.

ReturnsDescription
Type

The type of the value.

method std::string type_name()

Get the name of the value's type.

ReturnsDescription
std::string

The name of the value's type.

method std::string type_name(Type type)

Get the name of a value type.

ParameterDescription
type

The type to get the name of.

TYPE: Type

ReturnsDescription
std::string

The name of the type.

method uint64_t unsigned_value()

Get the unsigned integer value.

ReturnsDescription
uint64_t

The value as an unsigned integer.

ThrowsDescription
Exception

if the value is not an integer or doesn't fit in an unsigned integer.