OMNeT++ Simulation Library  5.6.1
cClassDescriptor Class Referenceabstract

#include <cclassdescriptor.h>

Description

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.

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
}
 Field types. More...
 

Public Member Functions

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 (void *object, int field) const =0
 
virtual const char * getFieldDynamicTypeString (void *object, int field, int i) const
 
virtual std::string getFieldValueAsString (void *object, int field, int i) const =0
 
virtual bool setFieldValueAsString (void *object, int field, int i, const char *value) const =0
 
virtual const char * getFieldStructName (int field) const =0
 
virtual void * getFieldStructValuePointer (void *object, int field, int i) const =0
 
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
 
- Public Member Functions inherited from cNoncopyableOwnedObject
 cNoncopyableOwnedObject (const char *name=nullptr, bool namepooling=true)
 
virtual cNoncopyableOwnedObjectdup () const override
 
virtual void parsimPack (cCommBuffer *buffer) const override
 
virtual void parsimUnpack (cCommBuffer *buffer) 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
 
virtual bool isSoftOwner () const
 
- 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)
 
virtual ~cObject ()
 
virtual const char * getClassName () const
 
bool isName (const char *s) const
 
virtual const char * getFullName () const
 
virtual std::string getFullPath () const
 
const cObjectgetThisPtr () const
 
virtual std::string str () const
 
virtual _OPPDEPRECATED std::string info () const
 
virtual _OPPDEPRECATED std::string detailedInfo () const
 
virtual void forEachChild (cVisitor *v)
 
cObjectfindObject (const char *name, bool deep=true)
 
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 cDefaultListgetDefaultOwner ()
 

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

Constructor & Destructor Documentation

◆ cClassDescriptor()

cClassDescriptor ( const char *  className,
const char *  baseClassName = nullptr 
)

Constructor.

◆ ~cClassDescriptor()

virtual ~cClassDescriptor ( )
virtual

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 ( void *  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.

◆ getFieldDynamicTypeString()

virtual const char* getFieldDynamicTypeString ( void *  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 ( void *  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 bool setFieldValueAsString ( void *  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. Returns true if successful, and false if an error occurred or the field does not support setting.

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 void* getFieldStructValuePointer ( void *  object,
int  field,
int  i 
) const
pure virtual

Returns the pointer to the value of a compound field in the given object.


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