INET Framework for OMNeT++/OMNEST
inet::MatchableField Class Reference

Wrapper around a cObject field to make it matchable with cMatchExpression. More...

#include <MatchableField.h>

Inheritance diagram for inet::MatchableField:

Public Member Functions

 MatchableField (cObject *object=nullptr, int fieldIndex=-1)
 
void setField (cObject *object, int fieldIndex)
 
void setField (cObject *object, const char *fieldName)
 
virtual const char * getAsString () const override
 
virtual const char * getAsString (const char *attribute) const override
 

Protected Attributes

cObject * object
 
cClassDescriptor * classDescriptor
 
int fieldIndex
 

Detailed Description

Wrapper around a cObject field to make it matchable with cMatchExpression.

The default attribute is the field name.

Constructor & Destructor Documentation

◆ MatchableField()

inet::MatchableField::MatchableField ( cObject *  object = nullptr,
int  fieldIndex = -1 
)
13 {
14  setField(object, fieldIndex);
15 }

Member Function Documentation

◆ getAsString() [1/2]

const char * inet::MatchableField::getAsString ( ) const
overridevirtual
36 {
37  ASSERT(object && classDescriptor);
38  return classDescriptor->getFieldName(fieldIndex);
39 }

◆ getAsString() [2/2]

const char * inet::MatchableField::getAsString ( const char *  attribute) const
overridevirtual
42 {
43  ASSERT(object && classDescriptor);
44 
45  if (!strcmp("name", attribute))
46  return classDescriptor->getFieldName(fieldIndex);
47  else if (!strcmp("type", attribute))
48  return classDescriptor->getFieldTypeString(fieldIndex);
49  else if (!strcmp("declaredOn", attribute))
50  return classDescriptor->getFieldDeclaredOn(fieldIndex);
51  else
52  return nullptr;
53 }

◆ setField() [1/2]

void inet::MatchableField::setField ( cObject *  object,
const char *  fieldName 
)
26 {
27  ASSERT(object);
28  this->object = object;
29  this->fieldIndex = -1;
30  this->classDescriptor = object->getDescriptor();
31  this->fieldIndex = classDescriptor->findField(fieldName);
32  ASSERT(fieldIndex != -1);
33 }

◆ setField() [2/2]

void inet::MatchableField::setField ( cObject *  object,
int  fieldIndex 
)
18 {
19  ASSERT(object);
20  this->object = object;
21  this->fieldIndex = fieldIndex;
22  this->classDescriptor = object->getDescriptor();
23 }

Referenced by MatchableField().

Member Data Documentation

◆ classDescriptor

cClassDescriptor* inet::MatchableField::classDescriptor
mutableprotected

Referenced by getAsString(), and setField().

◆ fieldIndex

int inet::MatchableField::fieldIndex
protected

◆ object

cObject* inet::MatchableField::object
protected

Referenced by setField().


The documentation for this class was generated from the following files:
inet::MatchableField::object
cObject * object
Definition: MatchableField.h:22
inet::MatchableField::classDescriptor
cClassDescriptor * classDescriptor
Definition: MatchableField.h:23
inet::MatchableField::setField
void setField(cObject *object, int fieldIndex)
Definition: MatchableField.cc:17
inet::MatchableField::fieldIndex
int fieldIndex
Definition: MatchableField.h:24