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

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

#include <MatchableObject.h>

Inheritance diagram for inet::MatchableObject:

Public Types

enum  Attribute { ATTRIBUTE_FULLNAME, ATTRIBUTE_FULLPATH, ATTRIBUTE_CLASSNAME }
 

Public Member Functions

 MatchableObject (Attribute defaultAttribute=ATTRIBUTE_FULLPATH, const cObject *object=nullptr)
 
void setObject (const cObject *object)
 
void setDefaultAttribute (Attribute defaultAttribute)
 
virtual const char * getAsString () const override
 
virtual const char * getAsString (const char *attribute) const override
 

Static Protected Member Functions

static void splitIndex (char *indexedName, int &index)
 
static bool findDescriptorField (cClassDescriptor *classDescriptor, const char *attribute, int &fieldId, int &index)
 

Protected Attributes

Attribute defaultAttribute
 
const cObject * object
 
cClassDescriptor * classDescriptor
 
std::string attributeValue
 

Detailed Description

Wrapper around a cObject to make it matchable with cMatchExpression.

Member Enumeration Documentation

Enumerator
ATTRIBUTE_FULLNAME 
ATTRIBUTE_FULLPATH 
ATTRIBUTE_CLASSNAME 
31  {
35  };
Definition: MatchableObject.h:33
Definition: MatchableObject.h:34
Definition: MatchableObject.h:32

Constructor & Destructor Documentation

inet::MatchableObject::MatchableObject ( Attribute  defaultAttribute = ATTRIBUTE_FULLPATH,
const cObject *  object = nullptr 
)
23 {
25  this->object = object;
26  classDescriptor = nullptr;
27 }
cClassDescriptor * classDescriptor
Definition: MatchableObject.h:40
Attribute defaultAttribute
Definition: MatchableObject.h:38
const cObject * object
Definition: MatchableObject.h:39

Member Function Documentation

bool inet::MatchableObject::findDescriptorField ( cClassDescriptor *  classDescriptor,
const char *  attribute,
int &  fieldId,
int &  index 
)
staticprotected

Referenced by getAsString().

62 {
63  // attribute may be in the form "fieldName[index]"; split the two
64  char *fieldNameBuf = new char[strlen(attribute)+1];
65  strcpy(fieldNameBuf, attribute);
66  splitIndex(fieldNameBuf, index);
67 
68  // find field by name
69  fieldId = classDescriptor->findField(fieldNameBuf);
70  delete[] fieldNameBuf;
71  return fieldId != -1;
72 }
cClassDescriptor * classDescriptor
Definition: MatchableObject.h:40
static void splitIndex(char *indexedName, int &index)
Definition: MatchableObject.cc:45
const char * inet::MatchableObject::getAsString ( ) const
overridevirtual
36 {
37  switch (defaultAttribute) {
38  case ATTRIBUTE_FULLPATH: attributeValue = object->getFullPath(); return attributeValue.c_str();
39  case ATTRIBUTE_FULLNAME: return object->getFullName();
40  case ATTRIBUTE_CLASSNAME: return object->getClassName();
41  default: throw cRuntimeError("Unknown setting for default attribute");
42  }
43 }
Definition: MatchableObject.h:33
Definition: MatchableObject.h:34
std::string attributeValue
Definition: MatchableObject.h:41
Attribute defaultAttribute
Definition: MatchableObject.h:38
Definition: MatchableObject.h:32
const char * inet::MatchableObject::getAsString ( const char *  attribute) const
overridevirtual
75 {
76  if (!classDescriptor) {
77  classDescriptor = object->getDescriptor();
78  if (!classDescriptor)
79  return nullptr;
80  }
81 
82 /*FIXME TBD
83  // start tokenizing the path
84  cStringTokenizer tokenizer(attribute, ".");
85  const char *token;
86  void *currentObj = obj;
87  cClassDescriptor *currentDesc = desc;
88  int currentFieldId = id
89  while ((token = tokenizer.nextToken())!=nullptr)
90  {
91  bool found = findDescriptorField(d, token, fid, index);
92  if (!found) return nullptr;
93  }
94 */
95 
96  int fieldId;
97  int index;
98  bool found = findDescriptorField(classDescriptor, attribute, fieldId, index);
99  if (!found)
100  return nullptr;
101 
102  attributeValue = classDescriptor->getFieldValueAsString((void *)object, fieldId, index);
103  return attributeValue.c_str();
104 }
cClassDescriptor * classDescriptor
Definition: MatchableObject.h:40
static bool findDescriptorField(cClassDescriptor *classDescriptor, const char *attribute, int &fieldId, int &index)
Definition: MatchableObject.cc:61
std::string attributeValue
Definition: MatchableObject.h:41
void inet::MatchableObject::setDefaultAttribute ( Attribute  defaultAttribute)
inline
Attribute defaultAttribute
Definition: MatchableObject.h:38
void inet::MatchableObject::setObject ( const cObject *  object)
30 {
31  this->object = object;
32  classDescriptor = nullptr;
33 }
cClassDescriptor * classDescriptor
Definition: MatchableObject.h:40
const cObject * object
Definition: MatchableObject.h:39
void inet::MatchableObject::splitIndex ( char *  indexedName,
int &  index 
)
staticprotected

Referenced by findDescriptorField().

46 {
47  index = 0;
48  char *startbracket = strchr(indexedName, '[');
49  if (startbracket) {
50  char *lastcharp = indexedName + strlen(indexedName) - 1;
51  if (*lastcharp != ']')
52  throw cRuntimeError("Unmatched '['");
53  *startbracket = '\0';
54  char *end;
55  index = strtol(startbracket+1, &end, 10);
56  if (end != lastcharp)
57  throw cRuntimeError("Brackets [] must contain numeric index");
58  }
59 }

Member Data Documentation

std::string inet::MatchableObject::attributeValue
mutableprotected

Referenced by getAsString().

cClassDescriptor* inet::MatchableObject::classDescriptor
mutableprotected
Attribute inet::MatchableObject::defaultAttribute
protected

Referenced by getAsString(), and MatchableObject().

const cObject* inet::MatchableObject::object
protected

Referenced by MatchableObject(), and setObject().


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