cClassDescriptor Class Reference¶

API: cClassDescriptor Class Reference
API
cClassDescriptor Class Referenceabstract
Inheritance diagram for cClassDescriptor:
[legend]

Public Types

enum  {
  FD_ISARRAY = 0x01 , FD_ISCOMPOUND = 0x02 , FD_ISPOINTER = 0x04 , FD_ISCOBJECT = 0x08 ,
  FD_ISCOWNEDOBJECT = 0x10 , FD_ISEDITABLE = 0x20 , FD_ISREPLACEABLE = 0x40 , FD_ISRESIZABLE = 0x80 ,
  FD_NONE = 0x0
}
 Field types. More...

Public Member Functions

Constructors, destructor, assignment.
 cClassDescriptor (const char *className, const char *baseClassName=nullptr)
virtual ~cClassDescriptor ()
Querying and setting fields of the client object.
virtual bool doesSupport (cObject *obj) const
virtual cClassDescriptorgetBaseClassDescriptor () const
bool extendsCObject () const
std::string getNamespace () const
int getInheritanceChainLength () const
virtual const char ** getPropertyNames () const =0
virtual const char * getProperty (const char *propertyname) const =0
virtual std::string getValueAsString (any_ptr object) const
virtual void setValueAsString (any_ptr object, const char *value) const
virtual int getFieldCount () const =0
virtual const char * getFieldName (int field) const =0
virtual int findField (const char *fieldName) const
virtual unsigned int getFieldTypeFlags (int field) const =0
Utility functions based on getFieldTypeFlags()
virtual const char * getFieldDeclaredOn (int field) const
virtual const char * getFieldTypeString (int field) const =0
virtual const char ** getFieldPropertyNames (int field) const =0
virtual const char * getFieldProperty (int field, const char *propertyname) const =0
virtual int getFieldArraySize (any_ptr object, int field) const =0
virtual void setFieldArraySize (any_ptr object, int field, int size) const =0
virtual const char * getFieldDynamicTypeString (any_ptr object, int field, int i) const
virtual std::string getFieldValueAsString (any_ptr object, int field, int i) const =0
virtual void setFieldValueAsString (any_ptr object, int field, int i, const char *value) const =0
virtual cValue getFieldValue (any_ptr object, int field, int i) const =0
virtual void setFieldValue (any_ptr object, int field, int i, const cValue &value) const =0
virtual const char * getFieldStructName (int field) const =0
virtual any_ptr getFieldStructValuePointer (any_ptr object, int field, int i) const =0
virtual void setFieldStructValuePointer (any_ptr object, int field, int i, any_ptr ptr) const =0
virtual std::string getFieldArrayIndexString (any_ptr object, int field, int arrayIndex) const
Public Member Functions inherited from cNoncopyableOwnedObject
 cNoncopyableOwnedObject (const char *name=nullptr, bool namepooling=true)
virtual cNoncopyableOwnedObjectdup () const override
Public Member Functions inherited from cOwnedObject
 cOwnedObject ()
 cOwnedObject (const char *name, bool namepooling=true)
 cOwnedObject (const cOwnedObject &obj)
virtual ~cOwnedObject ()
cOwnedObjectoperator= (const cOwnedObject &o)
virtual cObjectgetOwner () const override
virtual bool isOwnedObject () const override
Public Member Functions inherited from cNamedObject
 cNamedObject ()
 cNamedObject (const char *name, bool namepooling=true)
 cNamedObject (const cNamedObject &obj)
virtual ~cNamedObject ()
cNamedObjectoperator= (const cNamedObject &o)
virtual void setName (const char *s)
virtual const char * getName () const override
virtual void setNamePooling (bool b)
virtual bool getNamePooling ()
Public Member Functions inherited from cObject
 cObject ()
 cObject (const cObject &other)=default
virtual ~cObject ()
virtual const char * getClassName () const
bool isName (const char *s) const
virtual const char * getFullName () const
virtual std::string getFullPath () const
virtual std::string getClassAndFullName () const
virtual std::string getClassAndFullPath () const
const cObjectgetThisPtr () const
virtual std::string str () const
virtual std::ostream & printOn (std::ostream &os) const
virtual bool isSoftOwner () const
virtual void forEachChild (cVisitor *v)
cObjectfindObject (const char *name, bool deep=true)
virtual cClassDescriptorgetDescriptor () const
void copyNotSupported () const

Static Public Member Functions

Getting descriptor for an object or a struct.
static cClassDescriptorgetDescriptorFor (const char *classname)
static cClassDescriptorgetDescriptorFor (const cObject *object)
Static Public Member Functions inherited from cOwnedObject
static long getTotalObjectCount ()
static long getLiveObjectCount ()
static void resetObjectCounters ()
static cSoftOwnergetOwningContext ()

Static Public Attributes

static constexpr const char * UNPRINTABLE = "(unprintable)"
 Returned by getValueAsString() and getFieldValueAsString() for types that have no text representation.

Additional Inherited Members

Protected Member Functions inherited from cObject
virtual void take (cOwnedObject *obj)
virtual void drop (cOwnedObject *obj)
void dropAndDelete (cOwnedObject *obj)

Description

Abstract base class for class descriptors.

Subclasses of cClassDescriptor encapsulate reflection information (in the Java sense) which is needed by e.g. Qtenv to display object contents. cClassDescriptor subclasses are normally generated by the message compiler from MSG files.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Field types.

Enumerator
FD_ISARRAY 

field is an array: int a[]; int a[10];

FD_ISCOMPOUND 

basic type (T) is struct or class: T a; T *a; T a[10]; T *a[]

FD_ISPOINTER 

field is pointer or pointer array: T *a; T *a[]; T *a[10];

FD_ISCOBJECT 

if ISCOMPOUND: basic type (T) subclasses from cObject

FD_ISCOWNEDOBJECT 

if ISCOMPOUND: basic type (T) subclasses from cOwnedObject

FD_ISEDITABLE 

whether field supports setFieldValueAsString()

FD_ISREPLACEABLE 

whether field supports setFieldStructValuePointer()

FD_ISRESIZABLE 

whether field supports setFieldArraySize()

Constructor & Destructor Documentation

◆ cClassDescriptor()

◆ ~cClassDescriptor()

virtual ~cClassDescriptor ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ getDescriptorFor() [1/2]

◆ getDescriptorFor() [2/2]

cClassDescriptor * getDescriptorFor ( const cObject * object)
static

Returns the descriptor object for the given object. This can return descriptor for a base class, if there is no exact match. The returned descriptor object must not be deleted.

References cClassDescriptor().

◆ doesSupport()

virtual bool doesSupport ( cObject * obj) const
inlinevirtual

Returns true if this descriptor supports the given object's class. If obj can be cast (dynamic_cast) to the class the descriptor supports, the method should return true.

◆ getBaseClassDescriptor()

virtual cClassDescriptor * getBaseClassDescriptor ( ) const
virtual

Returns the descriptor for the base class, if available.

References cClassDescriptor().

◆ extendsCObject()

◆ getNamespace()

std::string getNamespace ( ) const

Returns the namespace of this object (getFullName() minus trailing "::" + getName()).

◆ getInheritanceChainLength()

int getInheritanceChainLength ( ) const

Returns the number of base classes up to the root, as reflected in the descriptors (see getBaseClassDescriptor()).

◆ getPropertyNames()

virtual const char ** getPropertyNames ( ) const
pure virtual

Returns a NUL-terminated string array with the names of properties on this class. The list includes the properties of the ancestor classes as well.

Implemented in cWatchProxyDescriptor, and cDynamicDescriptor.

◆ getProperty()

virtual const char * getProperty ( const char * propertyname) const
pure virtual

Returns the value of the given property of the descriptor as a single string. Returns nullptr if there is no such property. For structured property values (with multiple keys and/or list(s) inside), the value is returned as a single unparsed string. If a property appears in a base class and its subclass too, the subclass's property will be returned.

Implemented in cWatchProxyDescriptor, and cDynamicDescriptor.

◆ getValueAsString()

◆ setValueAsString()

virtual void setValueAsString ( any_ptr object,
const char * value ) const
virtual

◆ getFieldCount()

virtual int getFieldCount ( ) const
pure virtual

◆ getFieldName()

virtual const char * getFieldName ( int field) const
pure virtual

Returns the name of a field in the described class. The argument must be in the 0..getFieldCount()-1 range, inclusive.

Implemented in cWatchProxyDescriptor, cDynamicDescriptor, cStdListDescriptor< E >, cStdMapDescriptor< MapType >, cStdPairDescriptor< F, S >, cStdSetDescriptor< E >, and cStdVectorDescriptor< E >.

◆ findField()

virtual int findField ( const char * fieldName) const
virtual

Returns the index of the field with the given name, or -1 if not found. cClassDescriptor provides an default implementation, but it is recommended to replace it in subclasses with a more efficient version.

◆ getFieldTypeFlags()

virtual unsigned int getFieldTypeFlags ( int field) const
pure virtual

Returns the type flags of a field in the described class. Flags is a binary OR of the following: FD_ISARRAY, FD_ISCOMPOUND, FD_ISPOINTER, FD_ISCOWNEDOBJECT, FD_ISCOBJECT. The argument must be in the 0..getFieldCount()-1 range, inclusive.

Implemented in cWatchProxyDescriptor, cDynamicDescriptor, cStdListDescriptor< E >, cStdMapDescriptor< MapType >, cStdPairDescriptor< F, S >, cStdSetDescriptor< E >, and cStdVectorDescriptor< E >.

References FD_ISARRAY, and getFieldTypeFlags().

Referenced by getFieldTypeFlags().

◆ getFieldDeclaredOn()

virtual const char * getFieldDeclaredOn ( int field) const
virtual

Returns the name of the class on which the given field was declared.

◆ getFieldTypeString()

virtual const char * getFieldTypeString ( int field) const
pure virtual

Returns the declared type of a field in the described class as a string. The argument must be in the 0..getFieldCount()-1 range, inclusive.

See also
getFieldDynamicTypeString()

Implemented in cWatchProxyDescriptor, cDynamicDescriptor, cStdListDescriptor< E >, cStdMapDescriptor< MapType >, cStdPairDescriptor< F, S >, cStdSetDescriptor< E >, and cStdVectorDescriptor< E >.

◆ getFieldPropertyNames()

virtual const char ** getFieldPropertyNames ( int field) const
pure virtual

Returns a nullptr-terminated string array with the names of the given field's properties.

Implemented in cWatchProxyDescriptor, and cDynamicDescriptor.

◆ getFieldProperty()

virtual const char * getFieldProperty ( int field,
const char * propertyname ) const
pure virtual

Returns the value of the given property of the given field in the described class as a single string. Returns nullptr if there is no such property. For structured property values (with multiple keys and/or list(s) inside), the value is returned as a single unparsed string.

Implemented in cWatchProxyDescriptor, and cDynamicDescriptor.

◆ getFieldArraySize()

virtual int getFieldArraySize ( any_ptr object,
int field ) const
pure virtual

Returns the array size of a field in the given object. If the field is not an array, it returns 0.

Implemented in cWatchProxyDescriptor, cDynamicDescriptor, cStdListDescriptor< E >, cStdMapDescriptor< MapType >, cStdSetDescriptor< E >, and cStdVectorDescriptor< E >.

◆ setFieldArraySize()

virtual void setFieldArraySize ( any_ptr object,
int field,
int size ) const
pure virtual

Sets the array size of a field in the given object. If the operation is not successful, an exception is thrown.

The field argument must be in the 0..getFieldCount()-1 range. The i argument must be in the 0..getFieldArraySize()-1 range, or 0 if the field is not an array.

Implemented in cWatchProxyDescriptor, cDynamicDescriptor, and cStdVectorDescriptor< E >.

◆ getFieldDynamicTypeString()

virtual const char * getFieldDynamicTypeString ( any_ptr object,
int field,
int i ) const
inlinevirtual

Returns the runtime type of the given field as a string if it can be determined. (This method is relevant if the field contains a pointer or or an array of pointers to objects with RTTI.) If a runtime type is not available, nullptr is returned, and the caller should use the declared type instead (getFieldTypeString()).

The field argument must be in the 0..getFieldCount()-1 range. The i argument must be in the 0..getFieldArraySize()-1 range, or 0 if the field is not an array.

◆ getFieldValueAsString()

virtual std::string getFieldValueAsString ( any_ptr object,
int field,
int i ) const
pure virtual

Returns the value of the given field in the given object as a string. For compound fields, the message compiler generates code which calls operator<<.

The field argument must be in the 0..getFieldCount()-1 range. The i argument must be in the 0..getFieldArraySize()-1 range, or 0 if the field is not an array.

Implemented in cWatchProxyDescriptor, cDynamicDescriptor, cStdListDescriptor< E >, cStdMapDescriptor< MapType >, cStdPairDescriptor< F, S >, cStdSetDescriptor< E >, and cStdVectorDescriptor< E >.

◆ setFieldValueAsString()

virtual void setFieldValueAsString ( any_ptr object,
int field,
int i,
const char * value ) const
pure virtual

Sets the value of a field in the given object by parsing the given value string. If the operation is not successful, an exception is thrown.

The field argument must be in the 0..getFieldCount()-1 range. The i argument must be in the 0..getFieldArraySize()-1 range, or 0 if the field is not an array.

Implemented in cWatchProxyDescriptor, cDynamicDescriptor, cStdListDescriptor< E >, cStdMapDescriptor< MapType >, cStdPairDescriptor< F, S >, and cStdVectorDescriptor< E >.

◆ getFieldValue()

virtual cValue getFieldValue ( any_ptr object,
int field,
int i ) const
pure virtual

Returns the value of the given field in the given object.

The field argument must be in the 0..getFieldCount()-1 range. The i argument must be in the 0..getFieldArraySize()-1 range, or 0 if the field is not an array.

Implemented in cWatchProxyDescriptor, and cDynamicDescriptor.

◆ setFieldValue()

virtual void setFieldValue ( any_ptr object,
int field,
int i,
const cValue & value ) const
pure virtual

Sets the value of a field in the given object. If the operation is not successful, an exception is thrown.

The field argument must be in the 0..getFieldCount()-1 range. The i argument must be in the 0..getFieldArraySize()-1 range, or 0 if the field is not an array.

Implemented in cWatchProxyDescriptor, and cDynamicDescriptor.

◆ getFieldStructName()

virtual const char * getFieldStructName ( int field) const
pure virtual

Returns the declared type name of a compound field in the described class. The field is a pointer, the "*" is removed. The return value may be used as class name to obtain a class descriptor for this compound field.

Implemented in cWatchProxyDescriptor, cDynamicDescriptor, cStdListDescriptor< E >, cStdMapDescriptor< MapType >, cStdPairDescriptor< F, S >, cStdSetDescriptor< E >, and cStdVectorDescriptor< E >.

◆ getFieldStructValuePointer()

virtual any_ptr getFieldStructValuePointer ( any_ptr object,
int field,
int i ) const
pure virtual

Returns the pointer to the value of a compound field in the given object. The field argument must be in the 0..getFieldCount()-1 range. The i argument must be in the 0..getFieldArraySize()-1 range, or 0 if the field is not an array.

Implemented in cWatchProxyDescriptor, cDynamicDescriptor, cStdListDescriptor< E >, cStdMapDescriptor< MapType >, cStdPairDescriptor< F, S >, cStdSetDescriptor< E >, and cStdVectorDescriptor< E >.

◆ setFieldStructValuePointer()

virtual void setFieldStructValuePointer ( any_ptr object,
int field,
int i,
any_ptr ptr ) const
pure virtual

Sets a pointer field in the given object. If the operation is not successful, an exception is thrown.

The field argument must be in the 0..getFieldCount()-1 range. The i argument must be in the 0..getFieldArraySize()-1 range, or 0 if the field is not an array.

Implemented in cWatchProxyDescriptor, and cDynamicDescriptor.

◆ getFieldArrayIndexString()

virtual std::string getFieldArrayIndexString ( any_ptr object,
int field,
int arrayIndex ) const
virtual

Returns a string to be used as the array index in the UI when displaying an array element. The default implementation returns "[arrayIndex] ". This method can be overridden to provide custom index formatting, for example to show map keys instead of numeric indices.

The field argument must be in the 0..getFieldCount()-1 range. The arrayIndex argument must be in the 0..getFieldArraySize()-1 range.

Reimplemented in cWatchProxyDescriptor, cStdMapDescriptor< MapType >, and cStdSetDescriptor< E >.

Member Data Documentation

◆ UNPRINTABLE