cStructDescriptor Class Reference
[Internal classes]

#include <cstruct.h>

Inheritance diagram for cStructDescriptor:

cObject cPolymorphic List of all members.

Detailed Description

Abstract base class for structure description classes, used mainly with message subclassing.

Subclasses of cStructDescriptor 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 cStructDescriptor subclass is generated along with the message class, (struct, object, etc.).

When Tkenv encounters a message object, it creates an appropriate cStructDescriptor 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 cStructDescriptor object.

In this class, the copy constructor, dup() and the assignment operator are redefined to raise an error (throw cRuntimeError), since they would be of no use in subclasses.

See also:
sFieldWrapper


Public Types

enum  {
  FT_BASIC, FT_SPECIAL, FT_STRUCT, FT_BASIC_ARRAY,
  FT_SPECIAL_ARRAY, FT_STRUCT_ARRAY, FT_INVALID
}

Public Member Functions

Constructors, destructor, assignment.
 cStructDescriptor (const char *_baseclassname=NULL)
 cStructDescriptor (const cStructDescriptor &cs)
virtual ~cStructDescriptor ()
cStructDescriptoroperator= (const cStructDescriptor &)
Getting and setting client object.
void setStruct (void *_p)
void * getStruct () const
Querying and setting fields of the client object.
virtual int getFieldCount ()=0
virtual const char * getFieldName (int field)=0
virtual int getFieldType (int field)=0
virtual const char * getFieldTypeString (int field)=0
virtual const char * getFieldEnumName (int field)=0
virtual int getArraySize (int field)=0
virtual bool getFieldAsString (int field, int i, char *buf, int bufsize)=0
virtual bool setFieldAsString (int field, int i, const char *value)=0
virtual sFieldWrappergetFieldWrapper (int field, int i)=0
virtual const char * getFieldStructName (int field)=0
virtual void * getFieldStructPointer (int field, int i)=0

Static Public Member Functions

Getting descriptor for an object or a struct.
static cStructDescriptorcreateDescriptorFor (const char *classname, void *p)


Member Enumeration Documentation

anonymous enum
 

Field types.

Enumerator:
FT_BASIC  int, long, double, bool, char*, char[]
FT_SPECIAL  another data type that requires special presentation (e.g IP address)
FT_STRUCT  embedded structure, for which there's another cStructDescriptor
FT_BASIC_ARRAY  array of FT_BASIC
FT_SPECIAL_ARRAY  array of FT_SPECIAL
FT_STRUCT_ARRAY  array of FT_STRUCT
FT_INVALID  invalid type (signals error condition)


Constructor & Destructor Documentation

cStructDescriptor::cStructDescriptor const char *  _baseclassname = NULL  ) 
 

Constructor.

The argument is the client object.

cStructDescriptor::cStructDescriptor const cStructDescriptor cs  )  [inline]
 

Copy constructor.

virtual cStructDescriptor::~cStructDescriptor  )  [virtual]
 

Destructor.


Member Function Documentation

static cStructDescriptor* cStructDescriptor::createDescriptorFor const char *  classname,
void *  p
[static]
 

Creates and returns a descriptor object for the struct passed as argument.

The class of the descriptor object will be determined from the 1st argument: an instance of the class classname+"Descriptor" will be created. The passed struct will be the client object for the descriptor object.

virtual int cStructDescriptor::getArraySize int  field  )  [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.

virtual bool cStructDescriptor::getFieldAsString int  field,
int  i,
char *  buf,
int  bufsize
[pure virtual]
 

Must be redefined in subclasses to return the value of a basic field (of type FT_BASIC(_ARRAY)) in the client object as a string.

It is an error if this method is invoked for non-basic fields. Returns true if no error occurred, false otherwise.

virtual int cStructDescriptor::getFieldCount  )  [pure virtual]
 

Must be redefined in subclasses to return the number of fields in the client object.

virtual const char* cStructDescriptor::getFieldEnumName int  field  )  [pure virtual]
 

Returns the enum name associated with the field.

This makes only sense with integer-type fields (short, int, long, etc.). Returns NULL if there's no associated enum.

See also:
cEnum

virtual const char* cStructDescriptor::getFieldName int  field  )  [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* cStructDescriptor::getFieldStructName int  field  )  [pure virtual]
 

Must be redefined in subclasses to return the type name of an FT_STRUCT(_ARRAY) field in the client object.

The return value may be used then as classname to create a descriptor object for this structure field.

virtual void* cStructDescriptor::getFieldStructPointer int  field,
int  i
[pure virtual]
 

Must be redefined in subclasses to return the pointer of an FT_STRUCT(_ARRAY) field in the client object.

The return value may be used then as client object pointer to create a descriptor object for this structure field.

virtual int cStructDescriptor::getFieldType int  field  )  [pure virtual]
 

Must be redefined in subclasses to return the type of a field in the client object.

The argument must be in the 0..getFieldCount()-1 range, inclusive. The returned field type is one of the FT_BASIC, FT_SPECIAL, FT_STRUCT, FT_BASIC_ARRAY, FT_SPECIAL_ARRAY, FT_STRUCT_ARRAY constants, or FT_INVALID if there's no such field.

virtual const char* cStructDescriptor::getFieldTypeString int  field  )  [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 sFieldWrapper* cStructDescriptor::getFieldWrapper int  field,
int  i
[pure virtual]
 

Must be redefined in subclasses to return a wrapper for an FT_SPECIAL(_ARRAY) field in the client object.

There's no corresponding setFieldWrapper() method -- setting the field value should can take place via the wrapper object returned here. Returns NULL if no associated wrapper is defined for this field.

void* cStructDescriptor::getStruct  )  const [inline]
 

Returns client object.

cStructDescriptor& cStructDescriptor::operator= const cStructDescriptor  )  [inline]
 

Assignment is not supported by this class: this method throws a cRuntimeError when called.

virtual bool cStructDescriptor::setFieldAsString int  field,
int  i,
const char *  value
[pure virtual]
 

Must be redefined in subclasses to set the value of a basic field (of type FT_BASIC(_ARRAY)) in the client object as a string.

It is an error if this method is invoked for non-basic fields. Returns true if no error occurred, false otherwise.

void cStructDescriptor::setStruct void *  _p  ) 
 

Sets client object.


The documentation for this class was generated from the following file:
Generated on Sat Oct 21 17:47:57 2006 for OMNeT++/OMNEST Simulation Library by  doxygen 1.4.6