Value
class Value
Class representing a value of any type.
constructor Value()
Create void value.
constructor Value(bool value)
Create a boolean value.
| Parameter | Description |
|---|---|
value |
The boolean value. TYPE: |
constructor Value(double value)
Create a floating point value.
| Parameter | Description |
|---|---|
value |
The floating point value. TYPE: |
constructor Value(const std::string &value)
Create a binary value.
| Parameter | Description |
|---|---|
value |
The binary data. TYPE: |
constructor Value(Symbol value)
Create a string value.
| Parameter | Description |
|---|---|
value |
The string value. TYPE: |
constructor Value(uint64_t value, uint64_t default_size = 0)
Create a unsigned value.
| Parameter | Description |
|---|---|
value |
The unsigned integer value. TYPE: |
default_size |
Explicitly set the default size of the value. Otherwise the smallest size that can hold the value is used. TYPE: |
constructor Value(int64_t value, uint64_t default_size = 0)
Create a signed value.
| Parameter | Description |
|---|---|
value |
The signed integer value. TYPE: |
default_size |
Explicitly set the default size of the value. Otherwise the smallest size that can hold the value is used. TYPE: |
method std::string binary_value()
Get the binary data of the value.
| Returns | Description |
|---|---|
std::string |
The value as binary data. |
| Throws | Description |
|---|---|
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.
| Returns | Description |
|---|---|
bool |
The value as a boolean. |
| Throws | Description |
|---|---|
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.
| Returns | Description |
|---|---|
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.
| Returns | Description |
|---|---|
double |
The value as a floating point number. |
| Throws | Description |
|---|---|
Exception |
if the value is not a number. |
method bool is_binary()
Check if value is binary data.
| Returns | Description |
|---|---|
bool |
|
method bool is_boolean()
Check if it is a boolean value.
| Returns | Description |
|---|---|
bool |
|
method bool is_float()
Check if it is a floating point number.
| Returns | Description |
|---|---|
bool |
|
method bool is_integer()
Check if it is an integer.
| Returns | Description |
|---|---|
bool |
|
method bool is_number()
Check if it is a number (integer or floating point).
| Returns | Description |
|---|---|
bool |
|
method bool is_signed()
Check if it is a signed integer.
| Returns | Description |
|---|---|
bool |
|
method bool is_string()
Check if it is a string.
| Returns | Description |
|---|---|
bool |
|
method bool is_unsigned()
Check if it is an unsigned integer.
| Returns | Description |
|---|---|
bool |
|
method bool is_void()
Check if it is void (has no value).
| Returns | Description |
|---|---|
bool |
|
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.
| Throws | Description |
|---|---|
Exception |
Value can't be interpreted as a boolean. |
method bool operator!=(const Value &other)
Check if two values are different.
| Parameter | Description |
|---|---|
other |
The value to compare with. TYPE: |
| Returns | Description |
|---|---|
bool |
|
method Value operator%(const Value &other)
The remainder of this value divided by another value.
| Parameter | Description |
|---|---|
other |
The value to divide by. TYPE: |
| Returns | Description |
|---|---|
Value |
The remainder of the division. |
| Throws | Description |
|---|---|
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.
| Parameter | Description |
|---|---|
other |
The value to AND with. TYPE: |
| Returns | Description |
|---|---|
Value |
The result of the bitwise AND operation. |
| Throws | Description |
|---|---|
Exception |
if either value is not an unsigned integer. |
method Value operator&(uint64_t other)
Bitwise AND of this value and an unsigned integer.
| Parameter | Description |
|---|---|
other |
The unsigned integer to AND with. TYPE: |
| Returns | Description |
|---|---|
Value |
The result of the bitwise AND operation. |
| Throws | Description |
|---|---|
Exception |
if this value is not an unsigned integer. |
method Value operator&&(const Value &other)
Logical AND of this value and another value.
| Parameter | Description |
|---|---|
other |
The value to AND with. TYPE: |
| Returns | Description |
|---|---|
Value |
True if both values are true. |
| Throws | Description |
|---|---|
Exception |
if either value can't be interpreted as a boolean. |
method Value operator*(const Value &other)
Multiply this value by another value.
| Parameter | Description |
|---|---|
other |
The value to multiply by. TYPE: |
| Returns | Description |
|---|---|
Value |
The product of the two values. |
| Throws | Description |
|---|---|
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.
| Parameter | Description |
|---|---|
other |
The value to multiply by. TYPE: |
| Returns | Description |
|---|---|
Value & |
This value after multiplication. |
| Throws | Description |
|---|---|
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.
| Parameter | Description |
|---|---|
other |
The value to add. TYPE: |
| Returns | Description |
|---|---|
Value |
The sum of the two values. |
| Throws | Description |
|---|---|
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.
| Parameter | Description |
|---|---|
other |
The value to add. TYPE: |
| Returns | Description |
|---|---|
Value & |
This value after addition. |
| Throws | Description |
|---|---|
Exception |
if either value is not a number or if the addition would overflow. |
method Value operator-()
Negate value.
| Returns | Description |
|---|---|
Value |
The negated value. |
| Throws | Description |
|---|---|
Exception |
if the value is not a number. |
method Value operator-(const Value &other)
Subtract another value from this value.
| Parameter | Description |
|---|---|
other |
The value to subtract. TYPE: |
| Returns | Description |
|---|---|
Value |
The difference of the two values. |
| Throws | Description |
|---|---|
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.
| Parameter | Description |
|---|---|
other |
The value to subtract. TYPE: |
| Returns | Description |
|---|---|
Value & |
This value after subtraction. |
| Throws | Description |
|---|---|
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.
| Parameter | Description |
|---|---|
other |
The value to divide by. TYPE: |
| Returns | Description |
|---|---|
Value |
The quotient of the two values. |
| Throws | Description |
|---|---|
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.
| Parameter | Description |
|---|---|
other |
The value to divide by. TYPE: |
| Returns | Description |
|---|---|
Value & |
This value after division. |
| Throws | Description |
|---|---|
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.
| Parameter | Description |
|---|---|
other |
The value to compare with. TYPE: |
| Returns | Description |
|---|---|
bool |
|
method Value operator<<(const Value &other)
Left shift this value by another value.
| Parameter | Description |
|---|---|
other |
The value to shift by. TYPE: |
| Returns | Description |
|---|---|
Value |
The result of the left shift operation. |
| Throws | Description |
|---|---|
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.
| Parameter | Description |
|---|---|
other |
The value to compare with. TYPE: |
| Returns | Description |
|---|---|
bool |
|
method bool operator==(const Value &other)
Check if two values are equal.
| Parameter | Description |
|---|---|
other |
The value to compare with. TYPE: |
| Returns | Description |
|---|---|
bool |
|
method bool operator>(const Value &other)
Check if this value is greater than another value. Only numbers are comparable.
| Parameter | Description |
|---|---|
other |
The value to compare with. TYPE: |
| Returns | Description |
|---|---|
bool |
|
method bool operator>=(const Value &other)
Check if this value is greater than or equal to another value. Only numbers are comparable.
| Parameter | Description |
|---|---|
other |
The value to compare with. TYPE: |
| Returns | Description |
|---|---|
bool |
|
method Value operator>>(const Value &other)
Right shift this value by another value.
| Parameter | Description |
|---|---|
other |
The value to shift by. TYPE: |
| Returns | Description |
|---|---|
Value |
The result of the right shift operation. |
| Throws | Description |
|---|---|
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.
| Parameter | Description |
|---|---|
other |
The unsigned integer to shift by. TYPE: |
| Returns | Description |
|---|---|
Value |
The result of the left shift operation. |
| Throws | Description |
|---|---|
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.
| Parameter | Description |
|---|---|
other |
The value to exclusive OR with. TYPE: |
| Returns | Description |
|---|---|
Value |
The result of the bitwise exclusive OR operation. |
| Throws | Description |
|---|---|
Exception |
if either value is not an unsigned integer. |
method Value operator|(const Value &other)
Bitwise OR of this value and another value.
| Parameter | Description |
|---|---|
other |
The value to OR with. TYPE: |
| Returns | Description |
|---|---|
Value |
The result of the bitwise OR operation. |
| Throws | Description |
|---|---|
Exception |
if either value is not an unsigned integer. |
method Value operator||(const Value &other)
Logical OR of this value and another value.
| Parameter | Description |
|---|---|
other |
The value to OR with. TYPE: |
| Returns | Description |
|---|---|
Value |
True if either value is true. |
| Throws | Description |
|---|---|
Exception |
if either value can't be interpreted as a boolean. |
method Value operator~()
Bitwise NOT of the value.
| Returns | Description |
|---|---|
Value |
The bitwise NOT of the value. |
| Throws | Description |
|---|---|
Exception |
if the value is not an integer. |
method void serialize(std::ostream &stream)
Serialize the value to a stream.
| Parameter | Description |
|---|---|
stream |
The stream to serialize to. TYPE: |
method int64_t signed_value()
Get the signed integer value.
| Returns | Description |
|---|---|
int64_t |
The value as a signed integer. |
| Throws | Description |
|---|---|
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.
| Returns | Description |
|---|---|
std::string |
The value as a string. |
| Throws | Description |
|---|---|
Exception |
if the value can't be interpreted as a string. |
method Symbol symbol_value()
Get the symbol for string value.
| Returns | Description |
|---|---|
Symbol |
The value as a symbol. |
| Throws | Description |
|---|---|
Exception |
if the value is not a string. |
method Type type()
Get the type of the value.
| Returns | Description |
|---|---|
Type |
The type of the value. |
method std::string type_name()
Get the name of the value's type.
| Returns | Description |
|---|---|
std::string |
The name of the value's type. |
method std::string type_name(Type type)
Get the name of a value type.
| Parameter | Description |
|---|---|
type |
The type to get the name of. TYPE: |
| Returns | Description |
|---|---|
std::string |
The name of the type. |
method uint64_t unsigned_value()
Get the unsigned integer value.
| Returns | Description |
|---|---|
uint64_t |
The value as an unsigned integer. |
| Throws | Description |
|---|---|
Exception |
if the value is not an integer or doesn't fit in an unsigned integer. |