Abstract base class for structure description classes, used mainly with message subclassing. More...
#include <cclassdescriptor.h>
Public Types | |
enum | { FD_ISARRAY = 0x01, FD_ISCOMPOUND = 0x02, FD_ISPOINTER = 0x04, FD_ISCOBJECT = 0x08, FD_ISCOWNEDOBJECT = 0x10, FD_ISEDITABLE = 0x20 } |
Public Member Functions | |
virtual const char * | getFieldDeclaredOn (void *object, int field) const |
virtual const char * | getFieldTypeString (void *object, int field) const =0 |
virtual const char * | getFieldProperty (void *object, int field, const char *propertyname) const =0 |
virtual int | getArraySize (void *object, int field) const =0 |
virtual std::string | getFieldAsString (void *object, int field, int i) const =0 |
virtual _OPPDEPRECATED bool | getFieldAsString (void *object, int field, int i, char *buf, int bufsize) const |
virtual bool | setFieldAsString (void *object, int field, int i, const char *value) const =0 |
virtual const char * | getFieldStructName (void *object, int field) const =0 |
virtual void * | getFieldStructPointer (void *object, int field, int i) const =0 |
Constructors, destructor, assignment. | |
cClassDescriptor (const char *classname, const char *_baseclassname=NULL) | |
virtual | ~cClassDescriptor () |
Querying and setting fields of the client object. | |
virtual bool | doesSupport (cObject *obj) const |
virtual cClassDescriptor * | getBaseClassDescriptor () const |
bool | extendsCObject () const |
int | getInheritanceChainLength () const |
virtual const char * | getProperty (const char *propertyname) const =0 |
virtual int | getFieldCount (void *object) const =0 |
virtual const char * | getFieldName (void *object, int field) const =0 |
virtual int | findField (void *object, const char *fieldName) const |
virtual unsigned int | getFieldTypeFlags (void *object, int field) const =0 |
Utility functions based on getFieldTypeFlags() | |
bool | getFieldIsArray (void *object, int field) const |
bool | getFieldIsCompound (void *object, int field) const |
bool | getFieldIsPointer (void *object, int field) const |
bool | getFieldIsCObject (void *object, int field) const |
bool | getFieldIsCOwnedObject (void *object, int field) const |
bool | getFieldIsEditable (void *object, int field) const |
Static Public Member Functions | |
Getting descriptor for an object or a struct. | |
static cClassDescriptor * | getDescriptorFor (const char *classname) |
static cClassDescriptor * | getDescriptorFor (cObject *object) |
Abstract base class for structure description classes, used mainly with message subclassing.
Subclasses of cClassDescriptor encapsulate the kind of reflection information (in the Java sense) which is needed by Tkenv to display fields in a message, struct or object created with the .msg syntax. The cClassDescriptor subclass is generated along with the message class, (struct, object, etc.).
When Tkenv encounters a message object, it creates an appropriate cClassDescriptor object and uses that to find out what fields the message object has, what are their values etc. The message object is said to be the `client object' of the cClassDescriptor object.
anonymous enum |
Field types.
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 setFieldAsString() |
virtual bool cClassDescriptor::doesSupport | ( | cObject * | obj | ) | const [inline, virtual] |
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.
virtual int cClassDescriptor::findField | ( | void * | object, | |
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.
virtual int cClassDescriptor::getArraySize | ( | void * | object, | |
int | field | |||
) | const [pure virtual] |
Must be redefined in subclasses to return the array size of a field in the client object.
If the field is not an array, it should return 0.
static cClassDescriptor* cClassDescriptor::getDescriptorFor | ( | 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 is a singleton, and must not be deleted.
static cClassDescriptor* cClassDescriptor::getDescriptorFor | ( | const char * | classname | ) | [static] |
Returns the descriptor object for the given class.
The returned descriptor object is a singleton, and must not be deleted.
virtual std::string cClassDescriptor::getFieldAsString | ( | void * | object, | |
int | field, | |||
int | i | |||
) | const [pure virtual] |
Must be redefined in subclasses to return the value of the given field in the client object as a string.
For compound fields, the message compiler generates code which calls operator<<.
virtual const char* cClassDescriptor::getFieldName | ( | void * | object, | |
int | field | |||
) | const [pure virtual] |
Must be redefined in subclasses to return the name of a field in the client object.
The argument must be in the 0..getFieldCount()-1 range, inclusive.
virtual const char* cClassDescriptor::getFieldProperty | ( | void * | object, | |
int | field, | |||
const char * | propertyname | |||
) | const [pure virtual] |
Returns the value of the given property of the field as a single string.
Returns NULL 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.
virtual const char* cClassDescriptor::getFieldStructName | ( | void * | object, | |
int | field | |||
) | const [pure virtual] |
Must be redefined in subclasses to return the type name of a compound field in the client object.
If it is a pointer, the "*" is removed. The return value may be used then as classname to create a descriptor object for this compound field.
virtual unsigned int cClassDescriptor::getFieldTypeFlags | ( | void * | object, | |
int | field | |||
) | const [pure virtual] |
Must be redefined in subclasses to return the type flags of a field in the client object.
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.
virtual const char* cClassDescriptor::getFieldTypeString | ( | void * | object, | |
int | field | |||
) | const [pure virtual] |
Must be redefined in subclasses to return the type of a field in the client object as a string.
The argument must be in the 0..getFieldCount()-1 range, inclusive.
virtual const char* cClassDescriptor::getProperty | ( | const char * | propertyname | ) | const [pure virtual] |
Returns the value of the given property of the descriptor as a single string.
Returns NULL 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.
virtual bool cClassDescriptor::setFieldAsString | ( | void * | object, | |
int | field, | |||
int | i, | |||
const char * | value | |||
) | const [pure virtual] |
Must be redefined in subclasses to set the value of a field in the client object from the given value string.
Returns true if successful, and false if an error occurred or the field does not support setting.