cClassDescriptor Class Reference¶
|
API
|
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 cClassDescriptor * | getBaseClassDescriptor () 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 cNoncopyableOwnedObject * | dup () const override |
| Public Member Functions inherited from cOwnedObject | |
| cOwnedObject () | |
| cOwnedObject (const char *name, bool namepooling=true) | |
| cOwnedObject (const cOwnedObject &obj) | |
| virtual | ~cOwnedObject () |
| cOwnedObject & | operator= (const cOwnedObject &o) |
| virtual cObject * | getOwner () 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 () |
| cNamedObject & | operator= (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 cObject * | getThisPtr () const |
| virtual std::string | str () const |
| virtual std::ostream & | printOn (std::ostream &os) const |
| virtual bool | isSoftOwner () const |
| virtual void | forEachChild (cVisitor *v) |
| cObject * | findObject (const char *name, bool deep=true) |
| virtual cClassDescriptor * | getDescriptor () const |
| void | copyNotSupported () const |
Static Public Member Functions | |
Getting descriptor for an object or a struct. | |
| static cClassDescriptor * | getDescriptorFor (const char *classname) |
| static cClassDescriptor * | getDescriptorFor (const cObject *object) |
| Static Public Member Functions inherited from cOwnedObject | |
| static long | getTotalObjectCount () |
| static long | getLiveObjectCount () |
| static void | resetObjectCounters () |
| static cSoftOwner * | getOwningContext () |
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 | ( | const char * | className, |
| const char * | baseClassName = nullptr ) |
Constructor.
Referenced by getBaseClassDescriptor(), getDescriptorFor(), getDescriptorFor(), cStdMapDescriptor< MapType >::getFieldArrayIndexString(), cStdListDescriptor< E >::getFieldTypeFlags(), cStdMapDescriptor< MapType >::getFieldTypeFlags(), cStdPairDescriptor< F, S >::getFieldTypeFlags(), cStdSetDescriptor< E >::getFieldTypeFlags(), cStdVectorDescriptor< E >::getFieldTypeFlags(), cStdListDescriptor< E >::getFieldValueAsString(), cStdMapDescriptor< MapType >::getFieldValueAsString(), cStdPairDescriptor< F, S >::getFieldValueAsString(), cStdSetDescriptor< E >::getFieldValueAsString(), cStdVectorDescriptor< E >::getFieldValueAsString(), cStdPairDescriptor< F, S >::getValueAsString(), cStdListDescriptor< E >::setFieldValueAsString(), cStdMapDescriptor< MapType >::setFieldValueAsString(), cStdPairDescriptor< F, S >::setFieldValueAsString(), and cStdVectorDescriptor< E >::setFieldValueAsString().
◆ ~cClassDescriptor()
|
inlinevirtual |
Destructor.
Member Function Documentation
◆ getDescriptorFor() [1/2]
|
static |
Returns the descriptor object for the given class. The returned descriptor object must not be deleted.
References cClassDescriptor().
Referenced by cStdMapDescriptor< MapType >::getFieldArrayIndexString(), cStdListDescriptor< E >::getFieldTypeFlags(), cStdMapDescriptor< MapType >::getFieldTypeFlags(), cStdPairDescriptor< F, S >::getFieldTypeFlags(), cStdSetDescriptor< E >::getFieldTypeFlags(), cStdVectorDescriptor< E >::getFieldTypeFlags(), cStdListDescriptor< E >::getFieldValueAsString(), cStdMapDescriptor< MapType >::getFieldValueAsString(), cStdPairDescriptor< F, S >::getFieldValueAsString(), cStdSetDescriptor< E >::getFieldValueAsString(), cStdVectorDescriptor< E >::getFieldValueAsString(), cStdPairDescriptor< F, S >::getValueAsString(), cStdListDescriptor< E >::setFieldValueAsString(), cStdMapDescriptor< MapType >::setFieldValueAsString(), cStdPairDescriptor< F, S >::setFieldValueAsString(), and cStdVectorDescriptor< E >::setFieldValueAsString().
◆ getDescriptorFor() [2/2]
|
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()
|
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 |
Returns the descriptor for the base class, if available.
References cClassDescriptor().
◆ extendsCObject()
| bool extendsCObject | ( | ) | const |
Returns true if cObject's class descriptor is present on the inheritance chain.
Referenced by cStdListDescriptor< E >::getFieldTypeFlags(), cStdMapDescriptor< MapType >::getFieldTypeFlags(), cStdPairDescriptor< F, S >::getFieldTypeFlags(), cStdSetDescriptor< E >::getFieldTypeFlags(), and cStdVectorDescriptor< E >::getFieldTypeFlags().
◆ 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()
|
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()
|
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()
|
inlinevirtual |
Returns the value of the given object as a string.
Reimplemented in cWatchProxyDescriptor, cPrimitiveTypeDescriptor< T >, cStdListDescriptor< E >, cStdMapDescriptor< MapType >, cStdPairDescriptor< F, S >, cStdSetDescriptor< E >, and cStdVectorDescriptor< E >.
Referenced by cStdMapDescriptor< MapType >::getFieldArrayIndexString(), cStdListDescriptor< E >::getFieldValueAsString(), cStdMapDescriptor< MapType >::getFieldValueAsString(), cStdPairDescriptor< F, S >::getFieldValueAsString(), cStdSetDescriptor< E >::getFieldValueAsString(), cStdVectorDescriptor< E >::getFieldValueAsString(), and cStdPairDescriptor< F, S >::getValueAsString().
◆ setValueAsString()
|
virtual |
Sets the value of the given object by parsing the given value string. If the operation is not successful, an exception is thrown.
Reimplemented in cWatchProxyDescriptor, and cPrimitiveTypeDescriptor< T >.
Referenced by cStdListDescriptor< E >::setFieldValueAsString(), cStdMapDescriptor< MapType >::setFieldValueAsString(), cStdPairDescriptor< F, S >::setFieldValueAsString(), cStdVectorDescriptor< E >::setFieldValueAsString(), and cPrimitiveTypeDescriptor< T >::setValueAsString().
◆ getFieldCount()
|
pure virtual |
Returns the number of fields in the described class.
Implemented in cWatchProxyDescriptor, cDynamicDescriptor, cStdListDescriptor< E >, cStdMapDescriptor< MapType >, cStdPairDescriptor< F, S >, cStdSetDescriptor< E >, and cStdVectorDescriptor< E >.
Referenced by cStdPairDescriptor< F, S >::getFieldTypeFlags().
◆ getFieldName()
|
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 |
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()
|
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 |
Returns the name of the class on which the given field was declared.
◆ getFieldTypeString()
|
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()
|
pure virtual |
Returns a nullptr-terminated string array with the names of the given field's properties.
Implemented in cWatchProxyDescriptor, and cDynamicDescriptor.
◆ getFieldProperty()
|
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()
|
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()
|
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()
|
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()
|
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()
|
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()
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()
|
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()
|
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()
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()
|
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 |
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
|
staticconstexpr |
Returned by getValueAsString() and getFieldValueAsString() for types that have no text representation.
Referenced by cStdMapDescriptor< MapType >::getFieldArrayIndexString(), cStdListDescriptor< E >::getFieldValueAsString(), cStdMapDescriptor< MapType >::getFieldValueAsString(), cStdPairDescriptor< F, S >::getFieldValueAsString(), cStdSetDescriptor< E >::getFieldValueAsString(), cStdVectorDescriptor< E >::getFieldValueAsString(), cPrimitiveTypeDescriptor< T >::getValueAsString(), and cStdPairDescriptor< F, S >::getValueAsString().
Generated on for API by