Public Types | |
enum | Type { InvalidType, NullType, BoolType, Int16Type, Int32Type, Int64Type, FloatType, DoubleType, StringType } |
Public Member Functions | |
Value () | |
Value (const CrateDataType &type) | |
Value (const CrateDataType &type, bool) | |
Value (const std::string &name, const CrateDataType &type, bool value) | |
Value (const std::string &name, const CrateDataType &type, int16_t value) | |
Value (const std::string &name, const CrateDataType &type, int32_t value) | |
Value (const std::string &name, const CrateDataType &type, int64_t value) | |
Value (const std::string &name, const CrateDataType &type, float value) | |
Value (const std::string &name, const CrateDataType &type, double value) | |
Value (const std::string &name, const CrateDataType &type, const std::string &value) | |
bool | asBool () const |
double | asDouble () const |
float | asFloat () const |
int16_t | asInt16 () const |
int32_t | asInt32 () const |
int64_t | asInt64 () const |
std::string | asString () const |
CrateDataType | crateType () const |
bool | isInvalid () const |
bool | isNull () const |
const std::string & | name () const |
Type | type () const |
The class Value holds the actual value inside a Record and provides convenience functions to get the value as different types.
The original column name can be accessed via name() and crateType() returns the value's data type inside Crate. In contrast type() returns the value's real data storage type inside Value.
The relation between Crate's data type and Values's own data storage type is as follows:
CrateDataType::Type | Value::Type | Description |
---|---|---|
Null | NullType | |
NotSupported | InvalidType | |
Byte | Int16Type | |
Boolean | BoolType | |
String | StringType | |
Ip | StringType | |
Double | DoubleType | |
Float | FloatType | |
Short | Int16Type | |
Integer | Int32Type | |
Long | Int64Type | |
Timestamp | Int64Type | |
Object | StringType | as received by Crate |
GeoPoint | StringType | as received by Crate |
GeoShape | StringType | as received by Crate |
Array | StringType | as received by Crate |
Set | StringType | as received by Crate |
Even if each value is bound to it's own type – type() – the value can be retrieved converted into different types using asBool(), asInt(), asLong(), asLongLong(), asFloat(), asDouble() and asString(). If a conversion is not possible a default value will be returned. Note, however, that it is advised to get the value according it's own data type.
Describes the Value's own data storage type.
CppCrate::Value::Value | ( | ) |
Constructs an invalid value.
|
explicit |
Constructs an invalid value with Crate's original data type type.
CppCrate::Value::Value | ( | const CrateDataType & | type, |
bool | |||
) |
Constructs a null value with Crate's original data type type.
CppCrate::Value::Value | ( | const std::string & | name, |
const CrateDataType & | type, | ||
bool | value | ||
) |
Constructs a value with the column name name and Crate's original data type type. The value is internally stored as a bool
with it's own type Value::BoolType.
CppCrate::Value::Value | ( | const std::string & | name, |
const CrateDataType & | type, | ||
int16_t | value | ||
) |
Constructs a value with the column name name and Crate's original data type type. The value is internally stored as a int
with it's own type Value::Int16Type.
CppCrate::Value::Value | ( | const std::string & | name, |
const CrateDataType & | type, | ||
int32_t | value | ||
) |
Constructs a value with the column name name and Crate's original data type type. The value is internally stored as a long
with it's own type Value::Int32Type.
CppCrate::Value::Value | ( | const std::string & | name, |
const CrateDataType & | type, | ||
int64_t | value | ||
) |
Constructs a value with the column name name and Crate's original data type type. The value is internally stored as a long
long
with it's own type Value::Int64Type.
CppCrate::Value::Value | ( | const std::string & | name, |
const CrateDataType & | type, | ||
float | value | ||
) |
Constructs a value with the column name name and Crate's original data type type. The value is internally stored as a float
with it's own type Value::FloatType.
CppCrate::Value::Value | ( | const std::string & | name, |
const CrateDataType & | type, | ||
double | value | ||
) |
Constructs a value with the column name name and Crate's original data type type. The value is internally stored as a double
with it's own type Value::DoubleType.
CppCrate::Value::Value | ( | const std::string & | name, |
const CrateDataType & | type, | ||
const std::string & | value | ||
) |
Constructs a value with the column name name and Crate's original data type type. The value is internally stored as a std::string
with it's own type Value::StringType.
bool CppCrate::Value::asBool | ( | ) | const |
Returns the value as a bool
or false
if the value couldn't be converted.
double CppCrate::Value::asDouble | ( | ) | const |
Returns the value as a double
or 0 if the value couldn't be converted.
float CppCrate::Value::asFloat | ( | ) | const |
Returns the value as a float
or 0 if the value couldn't be converted.
int16_t CppCrate::Value::asInt16 | ( | ) | const |
Returns the value as a signed 16 bit integer or 0 if the value couldn't be converted.
int32_t CppCrate::Value::asInt32 | ( | ) | const |
Returns the value as a signed 32 bit integer or 0 if the value couldn't be converted.
int64_t CppCrate::Value::asInt64 | ( | ) | const |
Returns the value as a signed 64 bit integer or 0 if the value couldn't be converted.
std::string CppCrate::Value::asString | ( | ) | const |
Returns the value as a std::string
or an empty string if the value couldn't be converted.
CrateDataType CppCrate::Value::crateType | ( | ) | const |
Returns the value's original Crate type.
bool CppCrate::Value::isInvalid | ( | ) | const |
Returns whether the value is invalid.
bool CppCrate::Value::isNull | ( | ) | const |
Returns whether the value is NULL.
const std::string & CppCrate::Value::name | ( | ) | const |
Returns the value's original column name.
Value::Type CppCrate::Value::type | ( | ) | const |
Returns the value's own storage type.