libgig
4.4.1
|
Abstract reflection of a native C++ data type. More...
#include <Serialization.h>
Public Member Functions | |
DataType () | |
Default constructor (as "invalid" DataType). More... | |
size_t | size () const |
Returns native memory size of the respective C++ object or variable. | |
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 | isString () const |
Whether this is a C++ String 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 | isArray () const |
Whether this is a C++ Array<> object type. More... | |
bool | isSet () const |
Whether this is a C++ Set<> object type. More... | |
bool | isMap () const |
Whether this is a C++ Map<> object type. More... | |
bool | isSigned () const |
Whether this is a signed integer C/C++ data type. More... | |
operator bool () const | |
Same as calling isValid(). | |
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 1st user defined C/C++ data type name of this data type. More... | |
String | customTypeName2 (bool demangle=false) const |
The 2nd 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 customType1="", String customType2="") | |
Constructs a valid DataType object. More... | |
Static Protected Member Functions | |
template<typename T > | |
static String | rawCppTypeNameOf (const T &data) |
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 435 of file Serialization.h.
Serialization::DataType::DataType | ( | ) |
Default constructor (as "invalid" DataType).
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 82 of file Serialization.cpp.
|
protected |
Constructs a valid DataType object.
Initializes this object as "valid" DataType object, with specific and useful data type information.
This is a protected constructor which should not be called directly by applications, as its argument list is somewhat implementation specific and might change at any time. Applications should call the static function DataType::dataTypeOf() instead.
isPointer | - whether pointer type (i.e. a simple memory address) |
size | - native size of data type in bytes (i.e. according to sizeof() C/C++ keyword) |
baseType | - this framework's internal name for specifying the base type in a coarse way, which must be either one of: "int8", "uint8", "int16", "uint16", "int32", "uint32", "int64", "uint64", "bool", "real32", "real64", "String", "Array", "Set", "enum", "union" or "class" |
customType1 | - this is only used for base types "enum", "union", "class", "Array", "Set" or "Map", in which case this identifies the user defined type name (e.g. "Foo" for class Foo or e.g. "Bar" for Array<Bar> respectively), for all other types this is empty |
customType2 | - this is only used for Map<> objects in which case it identifies the map's value type (i.e. 2nd template parameter of map) |
Definition at line 114 of file Serialization.cpp.
References Serialization::UID::size.
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.
Definition at line 432 of file Serialization.cpp.
Referenced by Serialization::Archive::valueAsBool().
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:
this method would return for both i
and pi
the string "uint64"
!
Definition at line 472 of file Serialization.cpp.
References Serialization::UID::size.
Referenced by Serialization::Archive::rootObject().
String Serialization::DataType::customTypeName | ( | bool | demangle = false | ) | const |
The 1st user defined C/C++ data type name of this data type.
Call this method on user defined C/C++ data types like enum
, struct
, class
or Array<>
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:
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!
Definition at line 535 of file Serialization.cpp.
Referenced by Serialization::Archive::rootObject().
String Serialization::DataType::customTypeName2 | ( | bool | demangle = false | ) | const |
The 2nd user defined C/C++ data type name of this data type.
This is currently only used for Map<>
data types in which case this method returns the map's value type (i.e. map's 2nd template parameter).
Definition at line 547 of file Serialization.cpp.
Referenced by Serialization::Archive::rootObject().
|
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.
data | - native C/C++ object/member/variable a DataType object shall be created for |
Definition at line 474 of file Serialization.h.
References Serialization::IsClass(), Serialization::IsEnum(), Serialization::IsUnion(), and Serialization::UID::size.
Referenced by Serialization::Archive::serializeHeapMember(), Serialization::Archive::serializeMember(), Serialization::Archive::setMinVersion(), and Serialization::Archive::setVersion().
bool Serialization::DataType::isArray | ( | ) | const |
Whether this is a C++ Array<>
object type.
Returns true
if the respective native C/C++ object, member or variable (this DataType instance is reflecting) is a C++ Array<>
container object type.
Array<>
types neither as primitive types, nor as class types. So isPrimitive()
and isClass()
both return false
for arrays.Definition at line 291 of file Serialization.cpp.
Referenced by Serialization::Archive::valueAsBool().
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!
Definition at line 260 of file Serialization.cpp.
Referenced by Serialization::Archive::rootObject(), Serialization::Archive::setAutoValue(), and Serialization::Object::uid().
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.
String
and Array<>
are NOT handled as class data types by this framwork. So isClass()
returns false
for e.g. String
and any Array<>
based data type.Note that in the following example:
the DataType objects of both foo
, as well as of the C/C++ pointer pFoo
would both return true
for isClass() here!
Definition at line 172 of file Serialization.cpp.
Referenced by operator==(), and Serialization::Archive::valueAsBool().
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!
Definition at line 275 of file Serialization.cpp.
Referenced by Serialization::Archive::rootObject(), Serialization::Archive::setAutoValue(), and Serialization::Object::uid().
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!
Definition at line 228 of file Serialization.cpp.
Referenced by Serialization::Archive::rootObject(), Serialization::Archive::setAutoValue(), and Serialization::Object::uid().
bool Serialization::DataType::isMap | ( | ) | const |
Whether this is a C++ Map<>
object type.
Returns true
if the respective native C/C++ object, member or variable (this DataType instance is reflecting) is an associative sorted C++ Map<>
container object type.
Map<>
types neither as primitive types, nor as class types. So isPrimitive()
and isClass()
both return false
for maps.Definition at line 323 of file Serialization.cpp.
Referenced by Serialization::Archive::valueAsBool().
bool Serialization::DataType::isPointer | ( | ) | const |
Whether this is reflecting a C/C++ pointer type.
Returns if the respective native C/C++ object, member or variable (this DataType instance is reflecting) is a C/C++ pointer type.
Definition at line 143 of file Serialization.cpp.
Referenced by Serialization::Archive::rootObject(), Serialization::Object::uid(), and Serialization::Archive::valueAsBool().
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 String
objects and any pointer types like int*
, double**
, but including pointers to user defined types like:
So the DataType object of pFoo
in the latter example would also return true
for isPrimitive() here!
Definition at line 196 of file Serialization.cpp.
Referenced by Serialization::Archive::rootObject(), Serialization::Object::uid(), and Serialization::Archive::valueAsBool().
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!
Definition at line 245 of file Serialization.cpp.
Referenced by Serialization::Archive::rootObject(), Serialization::Archive::setAutoValue(), and Serialization::Object::uid().
bool Serialization::DataType::isSet | ( | ) | const |
Whether this is a C++ Set<>
object type.
Returns true
if the respective native C/C++ object, member or variable (this DataType instance is reflecting) is a C++ Set<>
unique container object type.
Set<>
types neither as primitive types, nor as class types. So isPrimitive()
and isClass()
both return false
for sets.Definition at line 307 of file Serialization.cpp.
Referenced by Serialization::Archive::valueAsBool().
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!
Definition at line 340 of file Serialization.cpp.
Referenced by Serialization::Archive::rootObject(), Serialization::Archive::setIntValue(), and Serialization::Object::uid().
bool Serialization::DataType::isString | ( | ) | const |
Whether this is a C++ String
data type.
Returns true
if the respective native C/C++ object, member or variable (this DataType instance is reflecting) is a C++ String
object (a.k.a. std::string
from the C++ STL).
Note that this framework handles String
objects as if they were a fundamental, primitive C/C++ data type, so isPrimitive()
returns true
for strings.
Definition at line 210 of file Serialization.cpp.
Referenced by Serialization::Archive::rootObject(), Serialization::Archive::setAutoValue(), Serialization::Object::uid(), and Serialization::Archive::valueAsBool().
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 134 of file Serialization.cpp.
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 376 of file Serialization.cpp.
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 391 of file Serialization.cpp.
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 363 of file Serialization.cpp.
References isClass().
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 414 of file Serialization.cpp.