Ocean
Ocean::Value Class Reference

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...
 
Valueoperator= (Value &&value)
 Move operator. More...
 
Valueoperator= (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_
 

Detailed Description

This class implements a type independent value.

Member Enumeration Documentation

◆ ValueType

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.

Constructor & Destructor Documentation

◆ Value() [1/11]

Ocean::Value::Value ( )
inlinenoexcept

Creates an empty value.

◆ Value() [2/11]

Ocean::Value::Value ( Value &&  value)

Move constructor.

Parameters
valuethe value object to move

◆ Value() [3/11]

Ocean::Value::Value ( const Value value)

Copies a value object.

Parameters
valueThe value object to copy

◆ Value() [4/11]

Ocean::Value::Value ( const bool  value)
explicit

Creates a new value object with an boolean value as internal data type.

Parameters
valueInternal value

◆ Value() [5/11]

Ocean::Value::Value ( const int32_t  value)
explicit

Creates a new value object with an integer value as internal data type.

Parameters
valueInternal value

◆ Value() [6/11]

Ocean::Value::Value ( const int64_t  value)
explicit

Creates a new value object with an 64 bit integer value as internal data type.

Parameters
valueInternal value

◆ Value() [7/11]

Ocean::Value::Value ( const float  value)
explicit

Creates a new value object with a floating point value as internal data type.

Parameters
valueInternal value

◆ Value() [8/11]

Ocean::Value::Value ( const double  value)
explicit

Creates a new value object with a double precision floating point value as internal data type.

Parameters
valueInternal value

◆ Value() [9/11]

Ocean::Value::Value ( const char *  value)
explicit

Creates a new value object with a string value as internal data type.

Parameters
valueInternal value

◆ Value() [10/11]

Ocean::Value::Value ( const std::string &  value)
explicit

Creates a new value object with a string value as internal data type.

Parameters
valueInternal value

◆ Value() [11/11]

Ocean::Value::Value ( const void *  value,
const size_t  size 
)
explicit

Creates a new value object with an arbitrary buffer as internal data type.

Parameters
valueInternal value, can be nullptr if size == 0
sizeThe size of the buffer in bytes, with range [0, infinity)

◆ ~Value()

Ocean::Value::~Value ( )

Destructs a value object.

Member Function Documentation

◆ boolValue()

bool Ocean::Value::boolValue ( ) const

Returns the internal value as a boolean.

Beware: Check the internal type of this value object before!

Returns
Internal data as boolean

◆ bufferValue()

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!

Parameters
sizeThe size of the buffer in bytes, with range [0, infinity)
Returns
The pointer to the buffer value

◆ float64Value()

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!

Parameters
allowIntAndFloatTrue, to allow int, int64, float and float64 values; False, to force float64 value only
Returns
Internal data as 64 bit float

◆ floatValue()

float Ocean::Value::floatValue ( ) const

Returns the internal value as float.

Beware: Check the internal type of this value object before!

Returns
Internal data as float

◆ int64Value()

int64_t Ocean::Value::int64Value ( ) const

Returns the internal value as 64 bit integer.

Beware: Check the internal type of this value object before!

Returns
Internal data as 64 bit integer

◆ intValue()

int32_t Ocean::Value::intValue ( ) const

Returns the internal value as integer.

Beware: Check the internal type of this value object before!

Returns
Internal data as integer

◆ isBool()

bool Ocean::Value::isBool ( ) const
inline

Returns whether this object holds an boolean value as internal data.

Returns
True, if so

◆ isBuffer()

bool Ocean::Value::isBuffer ( ) const
inline

Returns whether this object holds a buffer value as internal data.

Returns
True, if so

◆ isFloat()

bool Ocean::Value::isFloat ( ) const
inline

Returns whether this object holds a float value as internal data.

Returns
True, if so

◆ isFloat64()

bool Ocean::Value::isFloat64 ( const bool  allowIntAndFloat = false) const
inline

Returns whether this object holds a 64 bit float value as internal data.

Parameters
allowIntAndFloatTrue, to allow int, int64, float and float64 values; False, to force float64 value only
Returns
True, if so

◆ isInt()

bool Ocean::Value::isInt ( ) const
inline

Returns whether this object holds an integer value as internal data.

Returns
True, if so

◆ isInt64()

bool Ocean::Value::isInt64 ( ) const
inline

Returns whether this object holds a 64 bit integer value as internal data.

Returns
True, if so

◆ isNull()

bool Ocean::Value::isNull ( ) const
inline

Returns whether this object does not holds any internal data.

Returns
True, if so

◆ isString()

bool Ocean::Value::isString ( ) const
inline

Returns whether this object holds a string value as internal data.

Returns
True, if so

◆ isType()

bool Ocean::Value::isType ( const ValueType  valueType) const
inline

Returns whether the internal data type is equivalent to a given one.

Parameters
valueTypeInternal data type to check
Returns
True, if so

◆ operator bool()

Ocean::Value::operator bool ( ) const
inlineexplicit

Returns whether this object holds any internal data.

Returns
True, if so

◆ operator!=()

bool Ocean::Value::operator!= ( const Value value) const
inline

Returns whether two value objects are not identical (not having same type or not holding the same value).

Parameters
valueThe second value to compare
Returns
True, if so

◆ operator=() [1/2]

Value& Ocean::Value::operator= ( const Value value)

Assigns a value object to this one.

Parameters
valueThe value object to assign
Returns
Reference to this object

◆ operator=() [2/2]

Value& Ocean::Value::operator= ( Value &&  value)

Move operator.

Parameters
valueThe value object to be moved
Returns
Reference to this object

◆ operator==()

bool Ocean::Value::operator== ( const Value value) const

Returns whether two value objects are identical (having same type and holding the same value).

Parameters
valueThe second value to compare
Returns
True, if so

◆ readableString()

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.

Parameters
floatingPointPrecisionThe number of decimal places for floating point numbers, with range [1, infinity)
Returns
The readable string of this value

◆ readFromBuffer()

static Value Ocean::Value::readFromBuffer ( const void *  buffer,
const size_t  size 
)
static

Reads a Value object from a buffer.

Parameters
bufferThe pointer to the input buffer, must be valid
sizeThe size of the input buffer in bytes, with range [1, infinity)
Returns
The resulting Value object, invalid if the input was invalid
See also
writeToBuffer().

◆ release()

void Ocean::Value::release ( )
protected

Releases the value data.

◆ stringValue()

std::string Ocean::Value::stringValue ( ) const

Returns the internal value as string.

Beware: Check the internal type of this value object before!

Returns
Internal data as string

◆ type()

Value::ValueType Ocean::Value::type ( ) const
inline

Returns the internal data type of this value object.

Returns
Internal data type.

◆ writeToBuffer()

static bool Ocean::Value::writeToBuffer ( const Value value,
std::vector< uint8_t > &  buffer,
const size_t  offsetInBuffer = 0 
)
static

Writes a Value object to a buffer.

Parameters
valueThe value to write to the buffer, must be valid
bufferThe buffer to which the value will be written, will be resized as needed
offsetInBufferThe offset within the buffer at which position the value information will be written, with range [0, infinity)
Returns
True, if succeeded
See also
readFromBuffer().

Field Documentation

◆ valueType_

ValueType Ocean::Value::valueType_ = VT_INVALID
protected

Internal value type.

◆ valueUnion_

union Ocean::Value::ValueUnion Ocean::Value::valueUnion_
protected

The documentation for this class was generated from the following file: