Ocean
|
This class implements a type independent value. More...
Data Structures | |
struct | BufferStruct |
Definition of a struct combining memory pointer and size. More... | |
union | ValueUnion |
Definition of a union holding all possible values. More... | |
Public Types | |
enum | ValueType { VT_INVALID , VT_BOOL , VT_INT_32 , VT_INT_64 , VT_FLOAT_32 , VT_FLOAT_64 , VT_STRING , VT_BUFFER } |
Definition of different internal value type. More... | |
Public Member Functions | |
Value () noexcept | |
Creates an empty value. More... | |
Value (Value &&value) | |
Move constructor. More... | |
Value (const Value &value) | |
Copies a value object. More... | |
Value (const bool value) | |
Creates a new value object with an boolean value as internal data type. More... | |
Value (const int32_t value) | |
Creates a new value object with an integer value as internal data type. More... | |
Value (const int64_t value) | |
Creates a new value object with an 64 bit integer value as internal data type. More... | |
Value (const float value) | |
Creates a new value object with a floating point value as internal data type. More... | |
Value (const double value) | |
Creates a new value object with a double precision floating point value as internal data type. More... | |
Value (const char *value) | |
Creates a new value object with a string value as internal data type. More... | |
Value (const std::string &value) | |
Creates a new value object with a string value as internal data type. More... | |
Value (const void *value, const size_t size) | |
Creates a new value object with an arbitrary buffer as internal data type. More... | |
~Value () | |
Destructs a value object. More... | |
ValueType | type () const |
Returns the internal data type of this value object. More... | |
bool | isType (const ValueType valueType) const |
Returns whether the internal data type is equivalent to a given one. More... | |
bool | isBool () const |
Returns whether this object holds an boolean value as internal data. More... | |
bool | isInt () const |
Returns whether this object holds an integer value as internal data. More... | |
bool | isInt64 () const |
Returns whether this object holds a 64 bit integer value as internal data. More... | |
bool | isFloat () const |
Returns whether this object holds a float value as internal data. More... | |
bool | isFloat64 (const bool allowIntAndFloat=false) const |
Returns whether this object holds a 64 bit float value as internal data. More... | |
bool | isString () const |
Returns whether this object holds a string value as internal data. More... | |
bool | isBuffer () const |
Returns whether this object holds a buffer value as internal data. More... | |
bool | isNull () const |
Returns whether this object does not holds any internal data. More... | |
bool | boolValue () const |
Returns the internal value as a boolean. More... | |
int32_t | intValue () const |
Returns the internal value as integer. More... | |
int64_t | int64Value () const |
Returns the internal value as 64 bit integer. More... | |
float | floatValue () const |
Returns the internal value as float. More... | |
double | float64Value (const bool allowIntAndFloat=false) const |
Returns the internal value as 64 bit float. More... | |
std::string | stringValue () const |
Returns the internal value as string. More... | |
const void * | bufferValue (size_t &size) const |
Returns the internal value as buffer. More... | |
std::string | readableString (const unsigned int floatingPointPrecision=2u) const |
Returns the internal value as a readable string not considering the type of the value. More... | |
Value & | operator= (Value &&value) |
Move operator. More... | |
Value & | operator= (const Value &value) |
Assigns a value object to this one. More... | |
bool | operator== (const Value &value) const |
Returns whether two value objects are identical (having same type and holding the same value). More... | |
bool | operator!= (const Value &value) const |
Returns whether two value objects are not identical (not having same type or not holding the same value). More... | |
operator bool () const | |
Returns whether this object holds any internal data. More... | |
Static Public Member Functions | |
static bool | writeToBuffer (const Value &value, std::vector< uint8_t > &buffer, const size_t offsetInBuffer=0) |
Writes a Value object to a buffer. More... | |
static Value | readFromBuffer (const void *buffer, const size_t size) |
Reads a Value object from a buffer. More... | |
Protected Member Functions | |
void | release () |
Releases the value data. More... | |
Protected Attributes | |
ValueType | valueType_ = VT_INVALID |
Internal value type. More... | |
union Ocean::Value::ValueUnion | valueUnion_ |
This class implements a type independent value.
Definition of different internal value type.
Enumerator | |
---|---|
VT_INVALID | Invalid value type. |
VT_BOOL | Boolean value type. |
VT_INT_32 | 32 bit integer value. |
VT_INT_64 | 64 bit integer value. |
VT_FLOAT_32 | Single precision floating point value. |
VT_FLOAT_64 | Double precision floating point value. |
VT_STRING | String value. |
VT_BUFFER | Buffer value. |
|
inlinenoexcept |
Creates an empty value.
Ocean::Value::Value | ( | Value && | value | ) |
Move constructor.
value | the value object to move |
Ocean::Value::Value | ( | const Value & | value | ) |
Copies a value object.
value | The value object to copy |
|
explicit |
Creates a new value object with an boolean value as internal data type.
value | Internal value |
|
explicit |
Creates a new value object with an integer value as internal data type.
value | Internal value |
|
explicit |
Creates a new value object with an 64 bit integer value as internal data type.
value | Internal value |
|
explicit |
Creates a new value object with a floating point value as internal data type.
value | Internal value |
|
explicit |
Creates a new value object with a double precision floating point value as internal data type.
value | Internal value |
|
explicit |
Creates a new value object with a string value as internal data type.
value | Internal value |
|
explicit |
Creates a new value object with a string value as internal data type.
value | Internal value |
|
explicit |
Creates a new value object with an arbitrary buffer as internal data type.
value | Internal value, can be nullptr if size == 0 |
size | The size of the buffer in bytes, with range [0, infinity) |
Ocean::Value::~Value | ( | ) |
Destructs a value object.
bool Ocean::Value::boolValue | ( | ) | const |
Returns the internal value as a boolean.
Beware: Check the internal type of this value object before!
const void* Ocean::Value::bufferValue | ( | size_t & | size | ) | const |
Returns the internal value as buffer.
Beware: Check the internal type of this value object before!
size | The size of the buffer in bytes, with range [0, infinity) |
double Ocean::Value::float64Value | ( | const bool | allowIntAndFloat = false | ) | const |
Returns the internal value as 64 bit float.
Beware: Check the internal type of this value object before!
allowIntAndFloat | True, to allow int, int64, float and float64 values; False, to force float64 value only |
float Ocean::Value::floatValue | ( | ) | const |
Returns the internal value as float.
Beware: Check the internal type of this value object before!
int64_t Ocean::Value::int64Value | ( | ) | const |
Returns the internal value as 64 bit integer.
Beware: Check the internal type of this value object before!
int32_t Ocean::Value::intValue | ( | ) | const |
Returns the internal value as integer.
Beware: Check the internal type of this value object before!
|
inline |
Returns whether this object holds an boolean value as internal data.
|
inline |
Returns whether this object holds a buffer value as internal data.
|
inline |
Returns whether this object holds a float value as internal data.
|
inline |
Returns whether this object holds a 64 bit float value as internal data.
allowIntAndFloat | True, to allow int, int64, float and float64 values; False, to force float64 value only |
|
inline |
Returns whether this object holds an integer value as internal data.
|
inline |
Returns whether this object holds a 64 bit integer value as internal data.
|
inline |
Returns whether this object does not holds any internal data.
|
inline |
Returns whether this object holds a string value as internal data.
|
inline |
Returns whether the internal data type is equivalent to a given one.
valueType | Internal data type to check |
|
inlineexplicit |
Returns whether this object holds any internal data.
|
inline |
Returns whether two value objects are not identical (not having same type or not holding the same value).
value | The second value to compare |
Assigns a value object to this one.
value | The value object to assign |
Move operator.
value | The value object to be moved |
bool Ocean::Value::operator== | ( | const Value & | value | ) | const |
Returns whether two value objects are identical (having same type and holding the same value).
value | The second value to compare |
std::string Ocean::Value::readableString | ( | const unsigned int | floatingPointPrecision = 2u | ) | const |
Returns the internal value as a readable string not considering the type of the value.
Thus, this function can be called for any value type.
floatingPointPrecision | The number of decimal places for floating point numbers, with range [1, infinity) |
|
static |
Reads a Value object from a buffer.
buffer | The pointer to the input buffer, must be valid |
size | The size of the input buffer in bytes, with range [1, infinity) |
|
protected |
Releases the value data.
std::string Ocean::Value::stringValue | ( | ) | const |
Returns the internal value as string.
Beware: Check the internal type of this value object before!
|
inline |
Returns the internal data type of this value object.
|
static |
Writes a Value object to a buffer.
value | The value to write to the buffer, must be valid |
buffer | The buffer to which the value will be written, will be resized as needed |
offsetInBuffer | The offset within the buffer at which position the value information will be written, with range [0, infinity) |
|
protected |
Internal value type.
|
protected |