Data Class Reference

#include <datatypebase.h>

Detailed Description

General Data class. An object of this class can store every type of data as long as that type has been registered (see DataType).

See also
$ref datatype_data

Public Member Functions

 Data ()=default
 
Result< void > Init (const DataType &type)
 
 ~Data ()
 
Bool IsEmpty () const
 
Bool IsPopulated () const
 
const DataTypeGetType () const
 
void Reset ()
 
template<typename T >
 Data (T &&data, typename std::enable_if< !STD_IS_REPLACEMENT(same, typename std::decay< T >::type, Data), DummyParamType * >::type=(DummyParamType *) nullptr)
 
 Data (Data &&src)
 
Dataoperator= (Data &&src)
 
Result< DataGetCopy () const
 
Result< void > CopyFrom (const Data &src)
 
Result< void > CopyFrom (const ConstDataPtr &src)
 
Result< void > MoveFrom (MoveDataPtr &&src)
 
Result< void > CopyFrom (ForwardingDataPtr &&src)
 
template<typename T >
Result< void > Set (T &&data)
 
template<typename T >
Result< typename std::conditional< GetCollectionKind< T >::value==COLLECTION_KIND::ARRAY, T, typename ByValueParam< T >::type >::type > Get () const
 
template<typename T >
Result< typename std::conditional< STD_IS_REPLACEMENT(void, T)||(GetCollectionKind< T >::value==COLLECTION_KIND::ARRAY), T, T & >::type > Get ()
 
template<typename T >
ByValueParam< T >::type GetOrNull () const
 
template<typename T >
Get (const T &defaultValue) const
 
template<typename T >
Result< T > Convert () const
 
template<typename T >
ConvertOrNull () const
 
template<typename T >
Convert (const T &defaultValue) const
 
Result< DataConvertData (const DataType &destType) const
 
template<typename T >
T * GetPtr ()
 
template<typename T >
const T * GetPtr () const
 
Generic * GetPtr (const DataType &type)
 
const Generic * GetPtr (const DataType &type) const
 
const Generic * PrivateGetPtr () const
 
const Generic * PrivateGetPtr (const DataType &type) const
 
TupleValueGetTuple ()
 
const TupleValueGetTuple () const
 
String ToString (const FormatStatement *formatStatement) const
 
COMPARERESULT Compare (const Data &c) const
 
UInt GetHashCode () const
 
Bool IsEqual (const Data &other, EQUALITY equality=EQUALITY::DEEP) const
 
Bool operator== (const Data &other) const
 
Bool operator!= (const Data &other) const
 
Bool operator< (const Data &other) const
 
Bool operator<= (const Data &other) const
 
Bool operator> (const Data &other) const
 
Bool operator>= (const Data &other) const
 
ConstDataPtr ToConstDataPtr (const DataType &expectedType) const
 
template<>
void InitSet (Data &&data)
 
template<>
DataGetPtr ()
 
template<>
Result< void > Get () const
 
template<>
Result< void > Set (const Data &value)
 
template<>
Result< void > Set (Data &value)
 
template<>
Result< void > Set (Data &&value)
 
template<>
void InitSet (HTTPREQUESTTYPE &&d)
 

Static Public Member Functions

template<typename T >
static Result< DataCreate ()
 

Private Member Functions

 MAXON_DISALLOW_COPY_AND_ASSIGN (Data)
 
template<typename T >
Result< void > SetImpl (T &&data, OverloadRank0)
 
template<typename T >
std::enable_if< GetCollectionKind< T >::value==COLLECTION_KIND::ARRAY, Result< void > >::type SetImpl (T &&data, OverloadRank1)
 
template<typename T >
Result< typename ByValueParam< T >::type > GetImpl (OverloadRank0) const
 
template<typename T >
std::enable_if< GetCollectionKind< T >::value==COLLECTION_KIND::ARRAY, Result< T > >::type GetImpl (OverloadRank1) const
 
template<typename T >
Result< typename std::conditional< STD_IS_REPLACEMENT(void, T), void, T & >::type > GetImpl (OverloadRank0)
 
template<typename T >
std::enable_if< GetCollectionKind< T >::value==COLLECTION_KIND::ARRAY, Result< T > >::type GetImpl (OverloadRank1)
 
template<typename T >
SFINAEHelper< Result< T >, typename T::IsBlock >::type GetImpl (OverloadRank2)
 
template<typename T >
SFINAEHelper< Result< T >, typename T::IsBlock >::type GetImpl (OverloadRank2) const
 
template<typename T >
void InitSet (T &&data)
 

Static Private Member Functions

static const ObjectInterfaceCheckInstanceOf (const ObjectInterface *obj, const DataType &type)
 
static const ObjectRef * CheckInstanceOf (const ObjectRef *obj, const DataType &type)
 

Private Attributes

DataType _typeInfo
 
DataMemBlock _memBlock
 

Friends

class ConstDataPtr
 

Constructor & Destructor Documentation

◆ Data() [1/3]

Data ( )
default

constructor initializes the data with an nullptr type.

◆ ~Data()

~Data ( )

◆ Data() [2/3]

Data ( T &&  data,
typename std::enable_if< !STD_IS_REPLACEMENT(same, typename std::decay< T >::type, Data), DummyParamType * >::type  = (DummyParamType*)nullptr 
)
explicit

Template class to construct a Data object from a value. The value has to fit in DataMemBlock, i.e., this constructor can only be used when SIZEOF(T) <= SIZEOF(DataMemBlock). Otherwise, you have to use Set which might return an error.

Template Parameters
TType of data. This constructor only works if SIZEOF(T) <= SIZEOF(DataMemBlock).
Parameters
[in]dataData to copy into the Data.

◆ Data() [3/3]

Data ( Data &&  src)

Template class to move Data from every specialized data type. e.g. Int32, Url etc.

Parameters
[in,out]srcData to move to this.

Member Function Documentation

◆ MAXON_DISALLOW_COPY_AND_ASSIGN()

MAXON_DISALLOW_COPY_AND_ASSIGN ( Data  )
private

◆ Init()

Result<void> Init ( const DataType type)

Initializes this data to the given type. If this data already has the given type, nothing happens, i.e., the value is not reset. Otherwise, the current value is freed, and the data is initialized with a new default value of the given type.

Parameters
[in]typeType to which this data shall be set.
Returns
False if the initialization failed.

◆ IsEmpty()

Bool IsEmpty ( ) const

Checks if a Data is empty.

Returns
True if it doesn't contain any data.

◆ IsPopulated()

Bool IsPopulated ( ) const

Checks if a Data contains anything.

Returns
True if it contains data.

◆ GetType()

const DataType& GetType ( ) const

Returns the DataType of the Data. you can compare this value to GetDataType<Int32>() or GetDataType<String>().

Returns
DataType pointer of this.

◆ Reset()

void Reset ( )

Frees the wrapped data and resetd the Data object to its initial state.

◆ operator=()

Data& operator= ( Data &&  src)

Assignment move operator to move Data, (e.g. Swap uses this)

Parameters
[in]srcData to move to this.

◆ CopyFrom() [1/3]

Result<void> CopyFrom ( const Data src)

Makes this @CLASS a copy of src by copying the contents of src into this @CLASS.

Parameters
[in]srcAnother @CLASS to be used as source for the copy operation.
Returns
OK on success.

◆ CopyFrom() [2/3]

Result<void> CopyFrom ( const ConstDataPtr src)

Copies data described by a ConstDataPtr.

Parameters
[in]srcConstDataPtr to copy data from.
Returns
OK on success.

◆ MoveFrom()

Result<void> MoveFrom ( MoveDataPtr &&  src)

Moves data described by a MoveDataPtr.

Parameters
[in]srcMoveDataPtr to move data from.
Returns
OK on success.

◆ CopyFrom() [3/3]

Result<void> CopyFrom ( ForwardingDataPtr &&  src)

Copies or moves data described by a ForwardingDataPtr.

Parameters
[in]srcForwardingDataPtr to copy or move data from.
Returns
OK on success.

◆ Set()

Result<void> Set ( T &&  data)

Set or move a value into a Data.

Parameters
[in]dataNew value for this Data object.

◆ Get() [1/3]

Result<typename std::conditional<GetCollectionKind<T>::value == COLLECTION_KIND::ARRAY, T, typename ByValueParam<T>::type>::type> Get ( ) const

Returns the value of type T of this Data.

Template Parameters
TThe expected type of the value.
Returns
The value stored in this Data, or an error if this Data doesn't store a value of type T.

◆ Get() [2/3]

Result<typename std::conditional<STD_IS_REPLACEMENT(void, T) || (GetCollectionKind<T>::value == COLLECTION_KIND::ARRAY), T, T&>::type> Get ( )

◆ GetOrNull()

ByValueParam<T>::type GetOrNull ( ) const

Returns the value of type T of this Data.

Template Parameters
TThe expected type of the value.
Returns
The value stored in this Data, or a null value if this Data doesn't store a value of type T.

◆ Get() [3/3]

T Get ( const T &  defaultValue) const

Returns the value of type T of this Data.

Parameters
[in]defaultValueIf this Data doesn't store a value of type T, the default value will be returned.
Template Parameters
TThe expected type of the value.
Returns
The value stored in this Data, or defaultValue if this Data doesn't store a value of type T.

◆ Convert() [1/2]

Result<T> Convert ( ) const

Returns the value of this Data, converted to T.

Template Parameters
TThe type to convert to.
Returns
The value stored in this Data, converted to T, or an error if this Data doesn't store a value or the value cannot be converted to T.
See also
DataType::Convert

◆ ConvertOrNull()

T ConvertOrNull ( ) const

Returns the value of this Data, converted to T.

Template Parameters
TThe type to convert to.
Returns
The value stored in this Data, converted to T, or T() if this Data doesn't store a value or the value cannot be converted to T.
See also
DataType::Convert

◆ Convert() [2/2]

T Convert ( const T &  defaultValue) const

Returns the value of this Data, converted to T.

Parameters
[in]defaultValueIf this Data doesn't store a value or the value cannot converted to T, the default value will be returned.
Template Parameters
TThe type to convert to.
Returns
The value stored in this Data, converted to T, or defaultValue if this Data doesn't store a value or the value cannot be converted to T.
See also
DataType::Convert

◆ ConvertData()

Result<Data> ConvertData ( const DataType destType) const

Returns the value of this Data, converted to destType.

Parameters
[in]destTypeThe type to convert to.
Returns
The value stored in this Data, converted to destType, or an error if this Data doesn't store a value or the value cannot be converted to dataType.
See also
DataType::Convert

◆ GetPtr() [1/3]

const T* GetPtr ( ) const

Returns the pointer of the native data if its type matches the given type T, otherwise nullptr.

Template Parameters
TThe desired type.
Returns
Pointer to the data in native format.

◆ GetPtr() [2/3]

Generic* GetPtr ( const DataType type)

Returns the pointer of the native data if its type matches the given #type, otherwise nullptr.

Parameters
[in]typeThe desired type.
Returns
Pointer to the data in native format.

◆ GetPtr() [3/3]

const Generic* GetPtr ( const DataType type) const

◆ PrivateGetPtr() [1/2]

const Generic* PrivateGetPtr ( ) const

Returns the pointer to the native data.

Returns
Pointer to the data in native format.

◆ PrivateGetPtr() [2/2]

const Generic* PrivateGetPtr ( const DataType type) const

Returns the pointer to the native data. It is not checked if its type matches the given #type, the only purpose of the parameter is to enable a special behavior when #type is the type Data: Then a pointer to this Data object itself is returned.

Parameters
[in]typeThe desired type.
Returns
Pointer to the data in native format.

◆ GetTuple() [1/2]

TupleValue* GetTuple ( )

Returns the value of this Data object as a TupleValue. If this object doesn't hold a tuple value, nullptr is returned.

Returns
Pointer to the TupleValue stored in this object, or nullptr if no tuple value is stored.

◆ GetTuple() [2/2]

const TupleValue* GetTuple ( ) const

Returns the value of this Data object as a TupleValue. If this object doesn't hold a tuple value, nullptr is returned.

Returns
Pointer to the TupleValue stored in this object, or nullptr if no tuple value is stored.

◆ ToString()

String ToString ( const FormatStatement formatStatement) const

Returns a readable string of the content.

Parameters
[in]formatStatementNullptr or additional formatting instruction. See also format_mixed.
Returns
The converted result.

◆ Compare()

COMPARERESULT Compare ( const Data c) const

Returns a readable string of the content.

Returns
String that represents the content of Data.

◆ GetHashCode()

UInt GetHashCode ( ) const

Returns the hash code of the wrapped object. If the object's type doesn't provide a hash code function, this function returns 0.

Returns
Hash code of this Data.

◆ IsEqual()

Bool IsEqual ( const Data other,
EQUALITY  equality = EQUALITY::DEEP 
) const

Returns true if the wrapped object of this Data equals that of the #other Data.

Parameters
[in]otherAnother Data object to compare.
[in]equalityThe equality mode, by default EQUALITY::DEEP.
Returns
True if both Data objects are equal, false otherwise.

◆ operator==()

Bool operator== ( const Data other) const

==

==

◆ operator!=()

Bool operator!= ( const Data other) const

!=

!=

◆ operator<()

Bool operator< ( const Data other) const

<

<

◆ operator<=()

Bool operator<= ( const Data other) const

<=

<=

◆ operator>()

Bool operator> ( const Data other) const

>

>

◆ operator>=()

Bool operator>= ( const Data other) const

>=

>=

◆ ToConstDataPtr()

ConstDataPtr ToConstDataPtr ( const DataType expectedType) const

◆ CheckInstanceOf() [1/2]

static const ObjectInterface* CheckInstanceOf ( const ObjectInterface obj,
const DataType type 
)
staticprivate

◆ CheckInstanceOf() [2/2]

static const ObjectRef* CheckInstanceOf ( const ObjectRef *  obj,
const DataType type 
)
staticprivate

◆ SetImpl()

std::enable_if< GetCollectionKind< T >::value==COLLECTION_KIND::ARRAY, Result< void > >::type SetImpl ( T &&  data,
OverloadRank1   
)
private

◆ GetImpl() [1/6]

Result<typename ByValueParam<T>::type> GetImpl ( OverloadRank0  ) const
private

◆ GetImpl() [2/6]

std::enable_if< GetCollectionKind< T >::value==COLLECTION_KIND::ARRAY, Result< T > >::type GetImpl ( OverloadRank1  ) const
private

◆ GetImpl() [3/6]

Result<typename std::conditional<STD_IS_REPLACEMENT(void, T), void, T&>::type> GetImpl ( OverloadRank0  )
private

◆ GetImpl() [4/6]

std::enable_if< GetCollectionKind< T >::value==COLLECTION_KIND::ARRAY, Result< T > >::type GetImpl ( OverloadRank1  )
private

◆ GetImpl() [5/6]

SFINAEHelper<Result<T>, typename T::IsBlock>::type GetImpl ( OverloadRank2  )
private

◆ GetImpl() [6/6]

SFINAEHelper<Result<T>, typename T::IsBlock>::type GetImpl ( OverloadRank2  ) const
private

◆ InitSet()

void InitSet ( HTTPREQUESTTYPE &&  d)

Friends And Related Function Documentation

◆ ConstDataPtr

friend class ConstDataPtr
friend

Member Data Documentation

◆ _typeInfo

DataType _typeInfo
private

pointer to the DataType structure

◆ _memBlock

DataMemBlock _memBlock
private

placeholder for embedded data. this size must stay for compatibility reasons.