libgig  4.2.0
Serialization::DataType Class Reference

Abstract reflection of a native C++ data type. More...

#include <Serialization.h>

Public Member Functions

 DataType ()
 Default constructor. More...
 
bool isValid () const
 Check if this is a valid DataType object. More...
 
bool isPointer () const
 Whether this is reflecting a C/C++ pointer type. More...
 
bool isClass () const
 Whether this is reflecting a C/C++ struct or class type. More...
 
bool isPrimitive () const
 Whether this is reflecting a fundamental C/C++ data type. More...
 
bool isInteger () const
 Whether this is an integer C/C++ data type. More...
 
bool isReal () const
 Whether this is a floating point based C/C++ data type. More...
 
bool isBool () const
 Whether this is a boolean C/C++ data type. More...
 
bool isEnum () const
 Whether this is a C/C++ enum data type. More...
 
bool isSigned () const
 Whether this is a signed integer C/C++ data type. More...
 
bool operator== (const DataType &other) const
 Comparison for equalness. More...
 
bool operator!= (const DataType &other) const
 Comparison for inequalness. More...
 
bool operator< (const DataType &other) const
 Smaller than comparison. More...
 
bool operator> (const DataType &other) const
 Greater than comparison. More...
 
String asLongDescr () const
 Human readable long description for this data type. More...
 
String baseTypeName () const
 The base type name of this data type. More...
 
String customTypeName (bool demangle=false) const
 The user defined C/C++ data type name of this data type. More...
 

Static Public Member Functions

template<typename T >
static DataType dataTypeOf (const T &data)
 Construct a DataType object for the given native C++ data. More...
 

Protected Member Functions

 DataType (bool isPointer, int size, String baseType, String customType="")
 

Static Protected Member Functions

template<typename T >
static String rawCppTypeNameOf (const T &data)
 

Detailed Description

Abstract reflection of a native C++ data type.

Provides detailed information about a serialized C++ data type, whether it is a fundamental C/C++ data type (like int, float, char, etc.) or custom defined data types like a C++ class, C/C++ struct, enum, as well as other features of the respective data type like its native memory size and more.

All informations provided by this class are retrieved from the respective individual C++ objects, their members and other data when they are serialized, and all those information are stored with the serialized archive and its resulting data stream. Due to the availability of these extensive data type information within serialized archives, this framework is capable to use them in order to adapt its deserialization process upon subsequent changes to your individual C++ classes.

Definition at line 355 of file Serialization.h.

Constructor & Destructor Documentation

◆ DataType()

Serialization::DataType::DataType ( )

Default constructor.

Initializes a DataType object as being an "invalid" DataType object. Thus calling isValid(), after creating a DataType object with this constructor, would return false.

To create a valid and meaningful DataType object instead, call the static function DataType::dataTypeOf() instead.

Definition at line 83 of file Serialization.cpp.

Member Function Documentation

◆ asLongDescr()

String Serialization::DataType::asLongDescr ( ) const

Human readable long description for this data type.

Returns a human readable long description for this data type, designed for the purpose for being displayed to the user. Note that the implementation for this method and thus the precise textual strings returned by this method, may change at any time. So you should not rely on precise strings for certain data types, and you should not use the return values of this method for comparing data types with each other.

This class implements various comparison operators, so you should use them for comparing DataTypes objects instead.

See also
baseTypeName(), customTypeName()

Definition at line 333 of file Serialization.cpp.

References customTypeName(), and isPointer().

◆ baseTypeName()

String Serialization::DataType::baseTypeName ( ) const

The base type name of this data type.

Returns a textual short string identifying the basic type of name of this data type. For example for a 32 bit signed integer data type this method would return "int32". For all user defined C/C++ enum types this method would return "enum". For all user defined C/C++ struct and class types this method would return "class" for both. Note that the precise user defined type name (of i.e. enum, struct and class types) is not included in the string returned by this method, use customTypeName() to retrieve that information instead.

The precise textual strings returned by this method are guaranteed to retain equal with future versions of this framework. So you can rely on them for using the return values of this method for comparison tasks in your application. Note however that this class also implements various comparison operators.

Further it is important to know that this method returns the same string for pointers and non-pointers of the same underlying data type. So in the following example:

#include <stdint.h>
uint64_t i;
uint64_t* pi;

this method would return for both i and pi the string "uint64" !

See also
isPointer(), customTypeName()

Definition at line 371 of file Serialization.cpp.

◆ customTypeName()

String Serialization::DataType::customTypeName ( bool  demangle = false) const

The user defined C/C++ data type name of this data type.

Call this method on user defined C/C++ data types like enum, struct and class types to retrieve the user defined type name portion of those data types. Note that this method is only intended for such user defined data types. For all fundamental, primitive data types (like i.e. int) this method returns an empty string instead.

This method takes an optional boolean argument demangle, which allows you define whether you are interested in the raw C++ type name or rather the demangled custom type name. By default this method returns the raw C++ type name. The raw C++ type name is the one that is actually used in the compiled binaries and should be preferred for comparions tasks. The demangled C++ type name is a human readable representation of the type name instead, which you may use for displaying the user defined type name portion to the user, however you should not use the demangled representation for comparison tasks.

Note that in the following example:

struct Foo {
int a;
bool b;
};
Foo foo;
Foo* pFoo;

this method would return the same string for both foo and pFoo ! In the latter example customTypeName(true) would return for both foo and pFoo the string "Foo" as return value of this method.

Windows: please note that the current implementation of this method on Windows is not thread safe!

See also
isPointer(), baseTypeName()

Definition at line 411 of file Serialization.cpp.

Referenced by asLongDescr().

◆ dataTypeOf()

template<typename T >
static DataType Serialization::DataType::dataTypeOf ( const T &  data)
inlinestatic

Construct a DataType object for the given native C++ data.

Use this function to create corresponding DataType objects for native C/C++ objects, members and variables.

Parameters
data- native C/C++ object/member/variable a DataType object shall be created for
Returns
corresponding DataType object for the supplied native C/C++ object/member/variable

Definition at line 389 of file Serialization.h.

Referenced by Serialization::Archive::serializeMember(), Serialization::Archive::setMinVersion(), and Serialization::Archive::setVersion().

◆ isBool()

bool Serialization::DataType::isBool ( ) const

Whether this is a boolean C/C++ data type.

Returns true if the respective native C/C++ object, member or variable (this DataType instance is reflecting) is a (fundamental, primitive) boolean data type. So this is the case for the C++ bool data type. It does not include integer or floating point types though.

Note that this method also returns true on bool pointer types!

See also
isPointer()

Definition at line 212 of file Serialization.cpp.

Referenced by Serialization::Archive::setAutoValue().

◆ isClass()

bool Serialization::DataType::isClass ( ) const

Whether this is reflecting a C/C++ struct or class type.

Returns true if the respective native C/C++ object, member or variable (this DataType instance is reflecting) is a C/C++ struct or class type.

Note that in the following example:

struct Foo {
int a;
bool b;
};
Foo foo;
Foo* pFoo;

the DataType objects of both foo, as well as of the C/C++ pointer pFoo would both return true for isClass() here!

See also
isPointer()

Definition at line 138 of file Serialization.cpp.

Referenced by isPrimitive(), and operator==().

◆ isEnum()

bool Serialization::DataType::isEnum ( ) const

Whether this is a C/C++ enum data type.

Returns true if the respective native C/C++ object, member or variable (this DataType instance is reflecting) is a user defined enumeration data type. So this is the case for all C/C++ enum data types. It does not include integer (or even floating point) types though.

Note that this method also returns true on enum pointer types!

See also
isPointer()

Definition at line 227 of file Serialization.cpp.

Referenced by Serialization::Archive::setAutoValue().

◆ isInteger()

bool Serialization::DataType::isInteger ( ) const

Whether this is an integer C/C++ data type.

Returns true if the respective native C/C++ object, member or variable (this DataType instance is reflecting) is a (fundamental, primitive) integer data type. So these are all int and unsigned int types of any size. It does not include floating point ("real") types though.

You may use isSigned() to further check whether this data type allows negative numbers.

Note that this method also returns true on integer pointer types!

See also
isPointer()

Definition at line 180 of file Serialization.cpp.

Referenced by Serialization::Archive::setAutoValue().

◆ isPointer()

bool Serialization::DataType::isPointer ( ) const

Whether this is reflecting a C/C++ pointer type.

Returns @true if the respective native C/C++ object, member or variable (this DataType instance is reflecting) is a C/C++ pointer type.

Definition at line 114 of file Serialization.cpp.

Referenced by asLongDescr().

◆ isPrimitive()

bool Serialization::DataType::isPrimitive ( ) const

Whether this is reflecting a fundamental C/C++ data type.

Returns true if the respective native C/C++ object, member or variable (this DataType instance is reflecting) is a primitive, fundamental C/C++ data type. Those are fundamental data types which are already predefined by the C/C++ language, for example: char, int, float, double, bool, but also any pointer types like int*, double**, but including pointers to user defined types like:

struct Foo {
int a;
bool b;
};
Foo* pFoo;

So the DataType object of pFoo in the latter example would also return true for isPrimitive() here!

See also
isPointer()

Definition at line 162 of file Serialization.cpp.

References isClass().

◆ isReal()

bool Serialization::DataType::isReal ( ) const

Whether this is a floating point based C/C++ data type.

Returns true if the respective native C/C++ object, member or variable (this DataType instance is reflecting) is a (fundamental, primitive) floating point based data type. So these are currently the C/C++ float and double types. It does not include integer types though.

Note that this method also returns true on float pointer and double pointer types!

See also
isPointer()

Definition at line 197 of file Serialization.cpp.

Referenced by isSigned(), and Serialization::Archive::setAutoValue().

◆ isSigned()

bool Serialization::DataType::isSigned ( ) const

Whether this is a signed integer C/C++ data type.

Returns true if the respective native C/C++ object, member or variable (this DataType instance is reflecting) is a (fundamental, primitive) signed integer data type. This is the case for are all unsigned int C/C++ types of any size. For all floating point ("real") based types this method returns false though!

Note that this method also returns true on signed integer pointer types!

See also
isInteger();

Definition at line 244 of file Serialization.cpp.

References isReal().

Referenced by Serialization::Archive::setIntValue().

◆ isValid()

bool Serialization::DataType::isValid ( ) const

Check if this is a valid DataType object.

Returns true if this DataType object is reflecting a valid data type. The default constructor creates DataType objects initialized to be "invalid" DataType objects by default. That way one can detect whether a DataType object was ever assigned to something meaningful.

Note that this class also implements the bool operator, both return the same boolean result.

Definition at line 105 of file Serialization.cpp.

◆ operator!=()

bool Serialization::DataType::operator!= ( const DataType other) const

Comparison for inequalness.

Returns the inverse result of what DataType::operator==() would return. So refer to the latter for more details.

Definition at line 279 of file Serialization.cpp.

References operator==().

◆ operator<()

bool Serialization::DataType::operator< ( const DataType other) const

Smaller than comparison.

Returns true if this DataType object can be consider to be "smaller" than the other DataType object being compared with. This operator is actually quite arbitrarily implemented and may change at any time, and thus result for the same data types may change in future at any time.

This operator is basically implemented for allowing this DataType class to be used with various standard template library (STL) classes, which require sorting operators to be implemented.

Definition at line 294 of file Serialization.cpp.

Referenced by operator>().

◆ operator==()

bool Serialization::DataType::operator== ( const DataType other) const

Comparison for equalness.

Returns true if the two DataType objects being compared can be considered to be "equal" C/C++ data types. They are considered to be equal if their underlying C/C++ data types are exactly identical. For example comparing int and unsigned int data types are considere to be not equal, since they are differently signed. Furthermore short int and long int would also not be considered to be equal, since they do have a different memory size. Additionally pointer type characteristic is compared as well. So a double type and double* type are also considered to be not equal data types and hence this method would return false.

As an exception here, classes and structs with the same class/struct name but different sizes are also considered to be "equal". This relaxed requirement is necessary to retain backward compatiblity to older versions of the same native C++ classes/structs.

Definition at line 267 of file Serialization.cpp.

References isClass().

Referenced by operator!=(), and operator>().

◆ operator>()

bool Serialization::DataType::operator> ( const DataType other) const

Greater than comparison.

Returns true if this DataType object can be consider to be "greater" than the other DataType object being compared with. This operator is actually quite arbitrarily implemented and may change at any time, and thus result for the same data types may change in future at any time.

This operator is basically implemented for allowing this DataType class to be used with various standard template library (STL) classes, which require sorting operators to be implemented.

Definition at line 315 of file Serialization.cpp.

References operator<(), and operator==().


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