Class CConstVariant#

Class Documentation#

class CConstVariant#

Variant class to store const values.

This class is used for the storage of all possible data types as well as solving the expressions in const assignments. Only 32-bit, 64-bit integers, largest floating point and several string data type variations are used. The conversion rules for data types follow the C++11 conversion rules:

  • Assignment of data type:

    • Signed integers are assigned to int32_t when smaller than 64-bit; otherwise are assigned to int64_t.

    • Unsigned integers are assigned to uint32_t when smaller than 64-bit; otherwise are assigned to uint64_t.

    • Integral signed data types are: char, short, long, long long, int8_t, int16_t, int32_t int64_t.

    • Integral unsigned data types are: bool, unsigned short, unsigned long, unsigned long long, uint8_t, uint16_t, uint32_t uint64_t, wchar_t, char16_t, char32_t.

    • String objects and string pointers are assigned to their corresponding counterparts.

  • Arithmic operations with two operands:

    • If either operand is long double, the other operand is converted to long double.

    • If both integral operands are signed or both are unsigned, the operand with lesser conversion rank is converted to the

    • operand with the greater conversion rank.

    • Otherwise, if the unsigned integral operand’s conversion rank is greater or equal to the conversion rank of the signed operand, the signed operand is converted to the unsigned operand’s type.

    • Otherwise, if the signed integral operand’s type can represent all values of the unsigned operand, the unsigned operand is converted to the signed operand’s type.

    • Otherwise, both integral operands are converted to the unsigned counterpart of the signed operand’s type.

    • Conversions with and between string based operands are not supported.

  • Cast to data type:

    • If the stored data type and target data type are both signed or both unsigned, the target data type boundaries are checked with the value before assignment takes place.

    • If the destination type is unsigned, the resulting value is the smallest unsigned value equal to the source value modulo 2^n where n is the number of bits used to represent the destination type.

    • If the destination type is signed, the value does not change if the source integer can be represented in the destination type.

Unnamed Group

bool IsArithmetic() const#

Meta information.

Remark

The ranking function provides a number indicating the ranking of the type.

Returns:

Returns ‘true’ when the type stored in the variant has the specific attribute; ‘false’ otherwise.

bool IsIntegral() const#

Meta information.

Remark

The ranking function provides a number indicating the ranking of the type.

Returns:

Returns ‘true’ when the type stored in the variant has the specific attribute; ‘false’ otherwise.

bool IsFloatingPoint() const#

Meta information.

Remark

The ranking function provides a number indicating the ranking of the type.

Returns:

Returns ‘true’ when the type stored in the variant has the specific attribute; ‘false’ otherwise.

bool IsBoolean() const#

Meta information.

Remark

The ranking function provides a number indicating the ranking of the type.

Returns:

Returns ‘true’ when the type stored in the variant has the specific attribute; ‘false’ otherwise.

bool IsSigned() const#

Meta information.

Remark

The ranking function provides a number indicating the ranking of the type.

Returns:

Returns ‘true’ when the type stored in the variant has the specific attribute; ‘false’ otherwise.

bool IsUnsigned() const#

Meta information.

Remark

The ranking function provides a number indicating the ranking of the type.

Returns:

Returns ‘true’ when the type stored in the variant has the specific attribute; ‘false’ otherwise.

size_t Ranking() const#

Meta information.

Remark

The ranking function provides a number indicating the ranking of the type.

Returns:

Returns ‘true’ when the type stored in the variant has the specific attribute; ‘false’ otherwise.

template<typename TType>
bool IsSame() const#

Meta information.

Remark

The ranking function provides a number indicating the ranking of the type.

Returns:

Returns ‘true’ when the type stored in the variant has the specific attribute; ‘false’ otherwise.

Unnamed Group

CConstVariant operator!() const#

Unary arithmetic operators.

Remark

The bit operator ‘~’ and the logical operator ‘!’ work with integral operands only.

Returns:

The result of the operation.

CConstVariant operator~() const#

Unary arithmetic operators.

Remark

The bit operator ‘~’ and the logical operator ‘!’ work with integral operands only.

Returns:

The result of the operation.

CConstVariant operator+() const#

Unary arithmetic operators.

Remark

The bit operator ‘~’ and the logical operator ‘!’ work with integral operands only.

Returns:

The result of the operation.

CConstVariant operator-() const#

Unary arithmetic operators.

Remark

The bit operator ‘~’ and the logical operator ‘!’ work with integral operands only.

Returns:

The result of the operation.

Unnamed Group

template<typename TFunction>
static CConstVariant UnaryOperation(const CConstVariant &rvarOperand, TFunction tOperation)#

Do unary operation. The first version allows the operation on any arithmetic type. The second version works for integral operation only.

Template Parameters:

TFunction – The function type that should do the operation. The function uses the prototype:

CConstVariant(auto tOperand); 

Parameters:
  • rvarOperand[in] The operand.

  • tOperation[in] The function that is used for the operation.

Returns:

The const variant with the result.

template<typename TFunction>
static CConstVariant UnaryOperationIntegral(const CConstVariant &rvarOperand, TFunction tOperation)#

Do unary operation. The first version allows the operation on any arithmetic type. The second version works for integral operation only.

Template Parameters:

TFunction – The function type that should do the operation. The function uses the prototype:

CConstVariant(auto tOperand); 

Parameters:
  • rvarOperand[in] The operand.

  • tOperation[in] The function that is used for the operation.

Returns:

The const variant with the result.

Unnamed Group

template<typename TFunction>
static CConstVariant BinaryOperation(const CConstVariant &rvarOperand1, const CConstVariant &rvarOperand2, TFunction tOperation)#

Do binary operation. The first version allows the operation on any arithmetic type. The second version works for integral operation only.

Template Parameters:

TFunction – The function type that should do the operation. The function uses the prototype:

CConstVariant(auto tOperand1, auto tOperand2); 

Parameters:
  • rvarOperand1[in] The first operand.

  • rvarOperand2[in] The second operand.

  • tOperation[in] The function that is used for the operation.

Returns:

The const variant with the result.

template<typename TFunction>
static CConstVariant BinaryOperationIntegral(const CConstVariant &rvarOperand1, const CConstVariant &rvarOperand2, TFunction tOperation)#

Do binary operation. The first version allows the operation on any arithmetic type. The second version works for integral operation only.

Template Parameters:

TFunction – The function type that should do the operation. The function uses the prototype:

CConstVariant(auto tOperand1, auto tOperand2); 

Parameters:
  • rvarOperand1[in] The first operand.

  • rvarOperand2[in] The second operand.

  • tOperation[in] The function that is used for the operation.

Returns:

The const variant with the result.

Public Types

enum ETypeMapping#

Type to index mapping.

Remark

’char’ is represented by ‘int8_t’. ‘char16_t’ is represented by ‘uint16_t’. ‘char32_t’ is represented by ‘int32_t’. ‘wchar_t’ is either represented by ‘uint16_t’ or by ‘uint32_t’. ASCII and UTF-8 strings are represented by ‘std::string’.

Values:

enumerator type_bool#
enumerator type_int8_t#
enumerator type_uint8_t#
enumerator type_int16_t#
enumerator type_uint16_t#
enumerator type_int32_t#
enumerator type_uint32_t#
enumerator type_int64_t#
enumerator type_uint64_t#
enumerator type_fixed#
enumerator type_float#
enumerator type_double#
enumerator type_long_double#
enumerator type_string#
enumerator type_u16string#
enumerator type_u32string#
enumerator type_wstring#

Public Functions

CConstVariant() = default#

Default constructor.

CConstVariant(const CConstVariant &rvar)#

Copy constructor.

Parameters:

rvar[in] Reference to the const variant to copy from.

CConstVariant(CConstVariant &&rvar) noexcept#

Move constructor is not available.

Parameters:

rvar[in] Reference to the const variant to move from.

CConstVariant(bool bValue)#

Assignment constructor.

Parameters:

bValue[in] Value to assign.

CConstVariant(int8_t iValue)#

Assignment constructor.

Parameters:

iValue[in] Value to assign.

CConstVariant(uint8_t uiValue)#

Assignment constructor.

Parameters:

uiValue[in] Value to assign.

CConstVariant(int16_t iValue)#

Assignment constructor.

Parameters:

iValue[in] Value to assign.

CConstVariant(uint16_t uiValue)#

Assignment constructor.

Parameters:

uiValue[in] Value to assign.

CConstVariant(int32_t iValue)#

Assignment constructor.

Parameters:

iValue[in] Value to assign.

CConstVariant(uint32_t uiValue)#

Assignment constructor.

Parameters:

uiValue[in] Value to assign.

CConstVariant(int64_t iValue)#

Assignment constructor.

Parameters:

iValue[in] Value to assign.

CConstVariant(uint64_t uiValue)#

Assignment constructor.

Parameters:

uiValue[in] Value to assign.

CConstVariant(fixed fixValue)#

Assignment constructor.

Parameters:

fixValue[in] Value to assign.

CConstVariant(float fValue)#

Assignment constructor.

Parameters:

fValue[in] Value to assign.

CConstVariant(double dValue)#

Assignment constructor.

Parameters:

dValue[in] Value to assign.

CConstVariant(long double ldValue)#

Assignment constructor.

Parameters:

ldValue[in] Value to assign.

CConstVariant(const std::string &rssValue)#

Assignment constructor.

Parameters:

rssValue[in] Reference to the string value to assign.

CConstVariant(const std::u16string &rssValue)#

Assignment constructor.

Parameters:

rssValue[in] Reference to the string value to assign.

CConstVariant(const std::u32string &rssValue)#

Assignment constructor.

Parameters:

rssValue[in] Reference to the string value to assign.

CConstVariant(const std::wstring &rssValue)#

Assignment constructor.

Parameters:

rssValue[in] Reference to the string value to assign.

CConstVariant &operator=(const CConstVariant &rvar)#

Copy assignment operator.

Parameters:

rvar[in] Reference to the const variant to copy from.

Returns:

Reference to the const variant instance.

CConstVariant &operator=(CConstVariant &&rvar) noexcept#

Move operator is not available.

Parameters:

rvar[in] Reference to the const variant to move from.

Returns:

Reference to the const variant instance.

template<typename TType>
CConstVariant &operator=(const TType &rtValue)#

Assignment operator.

Template Parameters:

TType – Type of the value to assign.

Parameters:

rtValue[in] Reference to the value to assign.

Returns:

Reference to the const variant instance.

template<typename TTargetType>
TTargetType Get() const#

Get the value of the variant casted to the provided target type.

Throws:

Throws – exception when the value exceeds the boundaries of the target value or the types are incompatible.

Template Parameters:

TTargetType – The target type.

Returns:

The value casted to the target type.

std::string GetAsString() const#

Get the value as string.

Returns:

Get the value as a string.

void Convert(size_t nRank)#

Convert the variant to the type supplied.

Throws:

Throws – exception when the value exceeds the boundaries of the target value or the types are incompatible.

Parameters:

nRank[in] The rank of the type to convert to.

template<typename TType>
void Convert()#

Convert the variant to the type supplied.

Throws:

Throws – exception when the value exceeds the boundaries of the target value or the types are incompatible.

Template Parameters:

TType – The type to convert to.