This class contains a value to be stored in the object dictionary. The value can have one of the types which are supported by the KaCanOpen library (see enum Type). It's very similar to Boost's variant type, but a bit simpler. More...
#include <value.h>
Public Member Functions | |
Value () | |
Constructs an invalid value. | |
Value (uint8_t value) | |
Constructs a uint8 value. | |
Value (uint16_t value) | |
Constructs a uint16 value. | |
Value (uint32_t value) | |
Constructs a uint32 value. | |
Value (uint64_t value) | |
Constructs a uint64 value. | |
Value (int8_t value) | |
Constructs an int8 value. | |
Value (int16_t value) | |
Constructs an int16 value. | |
Value (int32_t value) | |
Constructs an int32 value. | |
Value (int64_t value) | |
Constructs an int64 value. | |
Value (float value) | |
Constructs a real32 value. | |
Value (double value) | |
Constructs a real64 value. | |
Value (bool value) | |
Constructs a boolean value. | |
Value (const std::string &value) | |
Constructs a string value. | |
Value (const char *value) | |
Constructs a string value from a string literal. | |
Value (const std::vector< uint8_t > &value) | |
Constructs a octet string value. | |
Value (Type type_, const std::vector< uint8_t > &data) | |
Creates a value given a type and the byte representation (little-endian) in a vector. More... | |
std::vector< uint8_t > | get_bytes () const |
Returns the byte representation (little-endian) as a vector. More... | |
operator uint8_t () const | |
Casts uint8 to C++ type. More... | |
operator uint16_t () const | |
Casts uint16 to C++ type. More... | |
operator uint32_t () const | |
Casts uint32 to C++ type. More... | |
operator uint64_t () const | |
Casts uint64 to C++ type. More... | |
operator int8_t () const | |
Casts int8 to C++ type. More... | |
operator int16_t () const | |
Casts int16 to C++ type. More... | |
operator int32_t () const | |
Casts int32 to C++ type. More... | |
operator int64_t () const | |
Casts int64 to C++ type. More... | |
operator float () const | |
Casts real32 to C++ type. More... | |
operator double () const | |
Casts real64 to C++ type. More... | |
operator bool () const | |
Casts boolean to C++ type. More... | |
operator std::string () const | |
Casts string to C++ type. More... | |
operator std::vector< uint8_t > () const | |
Casts octet_string to C++ type. More... | |
bool | operator== (const Value &other) const |
Compares equal. More... | |
bool | operator!= (const Value &other) const |
Compares not equal. More... | |
std::string | to_string () const |
Returns the value as a printable string. | |
Public Attributes | |
Type | type |
Tyoe of the value. | |
std::string | string |
The value if type==Type::string It's seperate because std::string is non-trivial and should not be part of a union. | |
std::vector< uint8_t > | octet_string |
The value if type==Type::octet_string It's seperate because std::vector is non-trivial and should not be part of a union. | |
union { | |
uint8_t uint8 | |
uint16_t uint16 | |
uint32_t uint32 | |
uint64_t uint64 | |
int8_t int8 | |
int16_t int16 | |
int32_t int32 | |
int64_t int64 | |
float real32 | |
double real64 | |
bool boolean | |
}; | |
Anonymous union containing the value if type!=Tyoe::string. | |
This class contains a value to be stored in the object dictionary. The value can have one of the types which are supported by the KaCanOpen library (see enum Type). It's very similar to Boost's variant type, but a bit simpler.
There are implicit cast constructors and implicit cast operators. All conversions are checked at runtime (at least in debug mode).
Maybe we should introduce a specific exception if types don't match.
Maybe we could be less restrictive for integer types of different size (e.g casting uint16_t to uint32_t should be safe).
kaco::Value::Value | ( | Type | type_, |
const std::vector< uint8_t > & | data | ||
) |
Creates a value given a type and the byte representation (little-endian) in a vector.
canopen_error | if type is invalid or data vector has wrong size. |
std::vector< uint8_t > kaco::Value::get_bytes | ( | ) | const |
Returns the byte representation (little-endian) as a vector.
canopen_error | if value is invalid. |
kaco::Value::operator bool | ( | ) | const |
Casts boolean to C++ type.
canopen_error | if types don't match. |
kaco::Value::operator double | ( | ) | const |
Casts real64 to C++ type.
canopen_error | if types don't match. |
kaco::Value::operator float | ( | ) | const |
Casts real32 to C++ type.
canopen_error | if types don't match. |
kaco::Value::operator int16_t | ( | ) | const |
Casts int16 to C++ type.
canopen_error | if types don't match. |
kaco::Value::operator int32_t | ( | ) | const |
Casts int32 to C++ type.
canopen_error | if types don't match. |
kaco::Value::operator int64_t | ( | ) | const |
Casts int64 to C++ type.
canopen_error | if types don't match. |
kaco::Value::operator int8_t | ( | ) | const |
Casts int8 to C++ type.
canopen_error | if types don't match. |
kaco::Value::operator std::string | ( | ) | const |
Casts string to C++ type.
canopen_error | if types don't match. |
kaco::Value::operator std::vector< uint8_t > | ( | ) | const |
Casts octet_string to C++ type.
canopen_error | if types don't match. |
kaco::Value::operator uint16_t | ( | ) | const |
Casts uint16 to C++ type.
canopen_error | if types don't match. |
kaco::Value::operator uint32_t | ( | ) | const |
Casts uint32 to C++ type.
canopen_error | if types don't match. |
kaco::Value::operator uint64_t | ( | ) | const |
Casts uint64 to C++ type.
canopen_error | if types don't match. |
kaco::Value::operator uint8_t | ( | ) | const |
Casts uint8 to C++ type.
canopen_error | if types don't match. |
bool kaco::Value::operator!= | ( | const Value & | other | ) | const |
Compares not equal.
canopen_error | if types don't match. |
bool kaco::Value::operator== | ( | const Value & | other | ) | const |
Compares equal.
canopen_error | if types don't match. |