libgig  4.3.0
Serialization::Member Class Reference

Abstract reflection of a native C++ class/struct's member variable. More...

#include <Serialization.h>

Public Member Functions

 Member ()
 Default constructor. More...
 
UID uid () const
 Unique identifier of this member instance. More...
 
String name () const
 Name of the member. More...
 
ssize_t offset () const
 Offset of member in its containing parent data structure. More...
 
const DataTypetype () const
 C/C++ Data type of this member. More...
 
bool isValid () const
 Check if this is a valid Member object. More...
 
 operator bool () const
 Same as calling isValid().
 
bool operator== (const Member &other) const
 Comparison for equalness. More...
 
bool operator!= (const Member &other) const
 Comparison for inequalness. More...
 
bool operator< (const Member &other) const
 Smaller than comparison. More...
 
bool operator> (const Member &other) const
 Greater than comparison. More...
 

Protected Member Functions

 Member (String name, UID uid, ssize_t offset, DataType type)
 

Detailed Description

Abstract reflection of a native C++ class/struct's member variable.

Provides detailed information about a specific C++ member variable of serialized C++ object, like its C++ data type, offset of this member within its containing data structure/class, its C++ member variable name and more.

Consider you defined the following user defined C/C++ struct type in your application:

struct Foo {
int a;
bool b;
double someValue;
};

Then a, b and someValue are "members" of struct Foo for instance. So that struct would have 3 members in the latter example.

See also
Object::members()

Definition at line 650 of file Serialization.h.

Constructor & Destructor Documentation

◆ Member()

Serialization::Member::Member ( )

Default constructor.

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

You are currently not supposed to create (meaningful) Member objects on your own. This framework automatically create such Member objects for you instead.

See also
Object::members()

Definition at line 567 of file Serialization.cpp.

References Serialization::NO_UID.

Member Function Documentation

◆ isValid()

bool Serialization::Member::isValid ( ) const

Check if this is a valid Member object.

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

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

Definition at line 684 of file Serialization.cpp.

Referenced by operator bool().

◆ name()

String Serialization::Member::name ( ) const

Name of the member.

Returns the name of the native C/C++ member variable as originally typed in its C++ source code. So in the following example:

struct Foo {
int a;
bool b;
double someValue;
};

this method would usually return "a" for the first member of object instances of your native C/C++ struct Foo, and this method would usually return "someValue" for its third member.

Note that when you implement the serialize() method of your own C/C++ clases or strucs, you are able to override defining the precise name of your members. In that case this method would of course return the member names as explicitly forced by you instead.

Definition at line 617 of file Serialization.cpp.

◆ offset()

ssize_t Serialization::Member::offset ( ) const

Offset of member in its containing parent data structure.

Returns the offset of this member (in bytes) within its containing parent user defined data structure or class. So in the following example:

#include <stdint.h>
struct Foo __attribute__ ((__packed__)) {
int32_t a;
bool b;
double c;
};

this method would typically return 0 for member a, 4 for member b and 5 for member c. As you have noted in the latter example, the structure Foo was declared to have "packed" data members. That means the compiler is instructed to add no memory spaces between the individual members. Because by default the compiler might add memory spaces between individual members to align them on certain memory address boundaries for increasing runtime performance while accessing the members. So if you declared the previous example without the "packed" attribute like:

#include <stdint.h>
struct Foo {
int32_t a;
bool b;
double c;
};

then this method would usually return a different offset for members b and c instead. For most 64 bit architectures this example would now still return 0 for member a, but 8 for member b and 16 for member c.

Note
Offset is intended for native members only, that is member variables which are memory located directly within the associated parent data structure. For members allocated on the heap offset() always returns -1 instead since there is no constant, static offset relationship between data on the heap and the parent structure owning their life-time control.

Definition at line 662 of file Serialization.cpp.

◆ operator!=()

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

Comparison for inequalness.

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

Definition at line 708 of file Serialization.cpp.

References operator==().

◆ operator<()

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

Smaller than comparison.

Returns true if this Member object can be consider to be "smaller" than the other Member object being compared with. This operator is actually quite arbitrarily implemented and may change at any time, and thus result for the same member representations 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 724 of file Serialization.cpp.

Referenced by operator>().

◆ operator==()

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

Comparison for equalness.

Returns true if the two Member objects being compared can be considered to be "equal" C/C++ members. They are considered to be equal if their data type, member name, their offset within their parent containing C/C++ data structure, as well as their original native C/C++ instance were exactly identical.

Definition at line 696 of file Serialization.cpp.

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

◆ operator>()

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

Greater than comparison.

Returns true if this Member object can be consider to be "greater" than the other Member object being compared with. This operator is actually quite arbitrarily implemented and may change at any time, and thus result for the same member representations 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 746 of file Serialization.cpp.

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

◆ type()

const DataType & Serialization::Member::type ( ) const

C/C++ Data type of this member.

Returns the precise data type of the original native C/C++ member.

Definition at line 670 of file Serialization.cpp.

Referenced by Serialization::Object::membersOfType().

◆ uid()

UID Serialization::Member::uid ( ) const

Unique identifier of this member instance.

Returns the unique identifier of the original C/C++ member instance of your C++ class. It is important to know that this unique identifier is not meant to be unique for Member instances themselves, but it is rather meant to be unique for the original native C/C++ data these Member instances are representing. So that means no matter how many individual Member objects are created, as long as they are representing the same original native member variable of the same original native instance of your C++ class, then all those separately created Member objects return the same unique identifier here.

See also
UID for more details

Definition at line 593 of file Serialization.cpp.


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