CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::CBOR::Value Class Reference

The Value class represents a data holder in the CBOR encoder or decoder. More...

#include <CeresEngine/Foundation/CBOR.hpp>

Inheritance diagram for CeresEngine::CBOR::Value:
CeresEngine::Variant< UInt64, Int64, float, double, bool, String, Binary, std::nullptr_t, Undefined, Array, Map, Tag, Break, Unknown >

Public Member Functions

 Value ()
 
ValueType getType () const noexcept
 Gets the type of the stored value.
 
String toString () const
 Converts the type into a string format.
 
bool isUInt64 () const noexcept
 Checks if the type is UInt64.
 
bool isInt64 () const noexcept
 Checks if the type is Int64.
 
bool isFloat () const noexcept
 Checks if the type is float.
 
bool isDouble () const noexcept
 Checks if the type is double.
 
bool isBoolean () const noexcept
 Checks if the type is bool.
 
bool isString () const noexcept
 Checks if the type is String.
 
bool isBinary () const noexcept
 Checks if the type is Binary.
 
bool isNull () const noexcept
 Checks if the type is nullptr.
 
bool isUndefined () const noexcept
 Checks if the type is undefined.
 
bool isArray () const noexcept
 Checks if the type is Array.
 
bool isMap () const noexcept
 Checks if the type is Map.
 
bool isTag () const noexcept
 Checks if the type is Tag.
 
bool isBreak () const noexcept
 Checks if the type is Break.
 
bool isUnknown () const noexcept
 Checks if the type is Unknown.
 
UInt64 asUInt64 () const noexcept
 Gets the value as type UInt64.
 
Int64 asInt64 () const noexcept
 Gets the value as type Int64.
 
float asFloat () const noexcept
 Gets the value as type float.
 
double asDouble () const noexcept
 Gets the value as type double.
 
bool asBoolean () const noexcept
 Gets the value as type bool.
 
const StringasString () const noexcept
 Gets the value as type String.
 
const BinaryasBinary () const &noexcept
 Gets the value as type Binary.
 
Binary && asBinary () &&noexcept
 Gets the value as type Binary.
 
StringView asStringView () const noexcept
 Gets the value as type asStringView.
 
const ArrayasArray () const noexcept
 Gets the value as type Array.
 
const MapasMap () const noexcept
 Gets the value as type Map.
 
const TagasTag () const noexcept
 Gets the value as type Tag.
 
const UnknownasUnknown () const noexcept
 Gets the value as type Unknown.
 
template<typename T >
requires std::is_enum_v<T>
T asEnum () const
 Gets the value as an enum type.
 

Private Types

using super = Variant< UInt64, Int64, float, double, bool, String, Binary, std::nullptr_t, Undefined, Array, Map, Tag, Break, Unknown >
 

Detailed Description

The Value class represents a data holder in the CBOR encoder or decoder.

It can encapsulate data of various types and provides a convenient way to represent values parsed from, or to be encoded into, CBOR data.

  • Multi-Type Support: The Value class can hold data of various types including integers (UInt64 and Int64), floating point values (float and double), boolean, String, Binary, nullptr_t, Undefined, Array, Map, Tag, Break and Unknown.
  • Type-Safe Access: The class provides type checking and type-safe data retrieval methods for each supported type. It also asserts the condition if an attempt is made to retrieve the value of a different type than the one currently stored.
  • Enum Type Support: For enumeration data, the asEnum() template function is provided.

A Value instance can be created with a value of any supported type from it's constructor.

A value can be retrieved using the type-specific as<T>() function calls. These functions will retrieve the value only if it is of a corresponding type.

The type of a value currently held by an instance can be checked using the type-specific is<T>() function calls.

The getType() function provides the specific ValueType enumeration representative of the type of value currently held by the Value instance. This is useful to use in a switch context.

The toString() function converts the value to a string representation, regardless of its actual type.

Overall, the Value class acts as a user-friendly interface for handling diverse data types in the CBOR handling process. It provides convenient type checking and safe type-specific access to values, ensuring the robustness of the CBOR encoding and decoding operations.

Member Typedef Documentation

◆ super

Constructor & Destructor Documentation

◆ Value()

CeresEngine::CBOR::Value::Value ( )
inline

Member Function Documentation

◆ asArray()

const Array & CeresEngine::CBOR::Value::asArray ( ) const
inlinenoexcept

Gets the value as type Array.

◆ asBinary() [1/2]

Binary && CeresEngine::CBOR::Value::asBinary ( ) &&
inlinenoexcept

Gets the value as type Binary.

◆ asBinary() [2/2]

const Binary & CeresEngine::CBOR::Value::asBinary ( ) const &
inlinenoexcept

Gets the value as type Binary.

◆ asBoolean()

bool CeresEngine::CBOR::Value::asBoolean ( ) const
inlinenoexcept

Gets the value as type bool.

◆ asDouble()

double CeresEngine::CBOR::Value::asDouble ( ) const
inlinenoexcept

Gets the value as type double.

◆ asEnum()

template<typename T >
requires std::is_enum_v<T>
T CeresEngine::CBOR::Value::asEnum ( ) const
inline

Gets the value as an enum type.

◆ asFloat()

float CeresEngine::CBOR::Value::asFloat ( ) const
inlinenoexcept

Gets the value as type float.

◆ asInt64()

Int64 CeresEngine::CBOR::Value::asInt64 ( ) const
inlinenoexcept

Gets the value as type Int64.

◆ asMap()

const Map & CeresEngine::CBOR::Value::asMap ( ) const
inlinenoexcept

Gets the value as type Map.

◆ asString()

const String & CeresEngine::CBOR::Value::asString ( ) const
inlinenoexcept

Gets the value as type String.

◆ asStringView()

StringView CeresEngine::CBOR::Value::asStringView ( ) const
inlinenoexcept

Gets the value as type asStringView.

◆ asTag()

const Tag & CeresEngine::CBOR::Value::asTag ( ) const
inlinenoexcept

Gets the value as type Tag.

◆ asUInt64()

UInt64 CeresEngine::CBOR::Value::asUInt64 ( ) const
inlinenoexcept

Gets the value as type UInt64.

◆ asUnknown()

const Unknown & CeresEngine::CBOR::Value::asUnknown ( ) const
inlinenoexcept

Gets the value as type Unknown.

◆ getType()

ValueType CeresEngine::CBOR::Value::getType ( ) const
noexcept

Gets the type of the stored value.

◆ isArray()

bool CeresEngine::CBOR::Value::isArray ( ) const
inlinenoexcept

Checks if the type is Array.

◆ isBinary()

bool CeresEngine::CBOR::Value::isBinary ( ) const
inlinenoexcept

Checks if the type is Binary.

◆ isBoolean()

bool CeresEngine::CBOR::Value::isBoolean ( ) const
inlinenoexcept

Checks if the type is bool.

◆ isBreak()

bool CeresEngine::CBOR::Value::isBreak ( ) const
inlinenoexcept

Checks if the type is Break.

◆ isDouble()

bool CeresEngine::CBOR::Value::isDouble ( ) const
inlinenoexcept

Checks if the type is double.

◆ isFloat()

bool CeresEngine::CBOR::Value::isFloat ( ) const
inlinenoexcept

Checks if the type is float.

◆ isInt64()

bool CeresEngine::CBOR::Value::isInt64 ( ) const
inlinenoexcept

Checks if the type is Int64.

◆ isMap()

bool CeresEngine::CBOR::Value::isMap ( ) const
inlinenoexcept

Checks if the type is Map.

◆ isNull()

bool CeresEngine::CBOR::Value::isNull ( ) const
inlinenoexcept

Checks if the type is nullptr.

◆ isString()

bool CeresEngine::CBOR::Value::isString ( ) const
inlinenoexcept

Checks if the type is String.

◆ isTag()

bool CeresEngine::CBOR::Value::isTag ( ) const
inlinenoexcept

Checks if the type is Tag.

◆ isUInt64()

bool CeresEngine::CBOR::Value::isUInt64 ( ) const
inlinenoexcept

Checks if the type is UInt64.

◆ isUndefined()

bool CeresEngine::CBOR::Value::isUndefined ( ) const
inlinenoexcept

Checks if the type is undefined.

◆ isUnknown()

bool CeresEngine::CBOR::Value::isUnknown ( ) const
inlinenoexcept

Checks if the type is Unknown.

◆ toString()

String CeresEngine::CBOR::Value::toString ( ) const

Converts the type into a string format.


The documentation for this class was generated from the following file: