cpgf library documentation

Using GMetaType

GMetaType is one of the core data type in cpgf reflection system. GMetaType provides basic type information such as the base class name (if any), pointer and reference information, etc. The informatio provided by GMetaType is only guaranteed enough for reflection and script binding usage. It's not guaranteed to cover all C++ type information. We can't expect accurate information from GMetaType for “char *(*(* *foo [][8])())[]”.

Member functions

bool isEmpty() const; 

Return true if the GMetaType is not initialized with any type. GMetaType constructed by the default constructor is empty.

const GTypeInfo & getBaseType() const; 

Get the type information of underlying base type. Base type is the type removed all const-volatile qualifiers and pointers and reference. However, currently an array type is considered of a base type, which is not quite accurate. GTypeInfo is a simple wrapper of std::type_info. Note: for interface based API such as IMetaClass, getBaseType always returns an empty GTypeInfo since GTypeInfo is not ABI portable which interface based API requires ABI portability.

const char * getBaseName() const; 

Get the meta name of underlying base type. Currently the fundamental types (int, double, etc) name can't be got through this function. If you are using the interface based API, such as IMetaClass, the base name is already there. If you are using class based API, such as GMetaClass, you must call global function fixupMetaType to fetch the base name. void fixupMetaType(GMetaType * type); Give a type of Foo, or Foo *, or const Foo &, or const Foo * const * &, getBaseName returns “Foo”.

bool baseIsClass() const; 

Return true if the base type is a class.

bool baseIsArray() const; 

Return true if the base type is an array.

bool isFundamental() const; 

Return true if the type is fundamental. Note: here it's not base type but type.

bool isFunction() const; 

Return true if the type is a function. Such as “void f()”.

bool isConstFunction() const; 

Return true if the type is a const function. Such as “void f() const”.

bool isVolatileFunction() const; 

Return true if the type is a volatile function. Such as “void f() volatile”.

bool isConstVolatileFunction() const; 

Return true if the type is a const volatile function. Such as “void f() const volatile”.

bool isConst() const; 

Return true if the type is const. Such as “const Foo”.

bool isVolatile() const; 

Return true if the type is volatile. Such as “volatile Foo”.

bool isConstVolatile() const; 

Return true if the type is const volatile. Such as “const volatile Foo”.

bool isPointerToConst() const; 

Return true if type is a pointer which points to a const. Such as “const Foo *”.

bool isPointerToVolatile() const; 

Return true if type is a pointer which points to a volatile. Such as “volatile Foo *”.

bool isPointerToConstVolatile() const; 

Return true if type is a pointer which points to a const volatile. Such as “const volatile Foo *”.

bool isReferenceToConst() const; 

Return true if type is a reference which references to a const. Such as “const Foo &”.

bool isReferenceToVolatile() const; 

Return true if type is a reference which references to a volatile. Such as “volatile Foo &”.

bool isReferenceToConstVolatile() const; 

Return true if type is a reference which references to a const volatile. Such as “const volatile Foo &”.

bool isPointer() const; 

Return true if type is a pointer. Such as “Foo *”, “const Foo *”, “const Foo * volatile * *”.

bool isReference() const; 

Return true if type is a reference. Such as “Foo &”, “const Foo &”, “const Foo * volatile * &”. isReference can overlap with isPointer. For example, “Foo * &” is a reference and is a pointer. If both isPointer and isReference return true, the type is a reference to pointer.

bool isString() const; 

Return true if type is a “char *” or “const char *”. Note: GMetaType doesn't know std::string.

bool isWideString() const; 

Return true if type is a “wchar_t *” or “const wchar_t *”. Note: GMetaType doesn't know std::wstring.

unsigned int getPointerDimension() const; 

Get the count of pointers there. For example, “Foo” returns 0, “Foo *” return 1, “const Foo * const volatile **” return 3. Usually only 1 dimension makes sense.

GVariantType getVariantType() const; 

Get type's variant type. This is useful if the type is a fundamental.