OMNeT++ Simulation Library  6.0.3
cClassDescriptor Class Referenceabstract

#include <cclassdescriptor.h>

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.

Inheritance diagram for cClassDescriptor:
cNoncopyableOwnedObject cOwnedObject noncopyable cNamedObject cObject

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
}
 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 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()
bool getFieldIsArray (int field) const
 
bool getFieldIsCompound (int field) const
 
bool getFieldIsPointer (int field) const
 
bool getFieldIsCObject (int field) const
 
bool getFieldIsCOwnedObject (int field) const
 
bool getFieldIsEditable (int field) const
 
bool getFieldIsReplaceable (int field) const
 
bool getFieldIsResizable (int field) const
 
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
 
- 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 ()
 

Additional Inherited Members

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

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.

◆ ~cClassDescriptor()

virtual ~cClassDescriptor ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ getDescriptorFor() [1/2]

static cClassDescriptor* getDescriptorFor ( const char *  classname)
static

Returns the descriptor object for the given class. The returned descriptor object must not be deleted.

◆ getDescriptorFor() [2/2]

static 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.

◆ 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.

◆ extendsCObject()

bool extendsCObject ( ) const

Returns true if cObject's class descriptor is present on the inheritance chain.

◆ 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.

◆ 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.

◆ getFieldCount()

virtual int getFieldCount ( ) const
pure virtual

Returns the number of fields in the described class.

◆ 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.

◆ 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.

◆ 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()

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.


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