CppCrate 0.1
Public Types | Public Member Functions | List of all members
CppCrate::Value Class Reference

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
 

Detailed Description

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

Conversion

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.

Member Enumeration Documentation

◆ Type

Describes the Value's own data storage type.

Enumerator
InvalidType 

An invalid value.

NullType 

An empty value.

BoolType 

The value was constructed using a bool.

Int16Type 

The value was constructed using a int.

Int32Type 

The value was constructed using a long.

Int64Type 

The value was constructed using a long long.

FloatType 

The value was constructed using a float.

DoubleType 

The value was constructed using a double.

StringType 

The value was constructed using a std::string.

Constructor & Destructor Documentation

◆ Value() [1/10]

CppCrate::Value::Value ( )

Constructs an invalid value.

◆ Value() [2/10]

CppCrate::Value::Value ( const CrateDataType type)
explicit

Constructs an invalid value with Crate's original data type type.

◆ Value() [3/10]

CppCrate::Value::Value ( const CrateDataType type,
bool   
)

Constructs a null value with Crate's original data type type.

◆ Value() [4/10]

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.

◆ Value() [5/10]

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.

◆ Value() [6/10]

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.

◆ Value() [7/10]

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.

◆ Value() [8/10]

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.

◆ Value() [9/10]

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.

◆ Value() [10/10]

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.

Member Function Documentation

◆ asBool()

bool CppCrate::Value::asBool ( ) const

Returns the value as a bool or false if the value couldn't be converted.

◆ asDouble()

double CppCrate::Value::asDouble ( ) const

Returns the value as a double or 0 if the value couldn't be converted.

◆ asFloat()

float CppCrate::Value::asFloat ( ) const

Returns the value as a float or 0 if the value couldn't be converted.

◆ asInt16()

int16_t CppCrate::Value::asInt16 ( ) const

Returns the value as a signed 16 bit integer or 0 if the value couldn't be converted.

◆ asInt32()

int32_t CppCrate::Value::asInt32 ( ) const

Returns the value as a signed 32 bit integer or 0 if the value couldn't be converted.

◆ asInt64()

int64_t CppCrate::Value::asInt64 ( ) const

Returns the value as a signed 64 bit integer or 0 if the value couldn't be converted.

◆ asString()

std::string CppCrate::Value::asString ( ) const

Returns the value as a std::string or an empty string if the value couldn't be converted.

◆ crateType()

CrateDataType CppCrate::Value::crateType ( ) const

Returns the value's original Crate type.

◆ isInvalid()

bool CppCrate::Value::isInvalid ( ) const

Returns whether the value is invalid.

◆ isNull()

bool CppCrate::Value::isNull ( ) const

Returns whether the value is NULL.

◆ name()

const std::string & CppCrate::Value::name ( ) const

Returns the value's original column name.

◆ type()

Value::Type CppCrate::Value::type ( ) const

Returns the value's own storage type.