OMNeT++ Simulation Library  6.0.3
cclassdescriptor.h
1 //==========================================================================
2 // CCLASSDESCRIPTOR.H - part of
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 1992-2017 Andras Varga
10  Copyright (C) 2006-2017 OpenSim Ltd.
11 
12  This file is distributed WITHOUT ANY WARRANTY. See the file
13  `license' for details on this and other legal matters.
14 *--------------------------------------------------------------*/
15 
16 #ifndef __OMNETPP_CCLASSDESCRIPTOR_H
17 #define __OMNETPP_CCLASSDESCRIPTOR_H
18 
19 #include <string>
20 #include "cownedobject.h"
21 #include "simtime.h"
22 #include "opp_string.h"
23 #include "any_ptr.h"
24 
25 namespace omnetpp {
26 
27 class cValue;
28 
40 {
41  public:
43  enum {
44  FD_ISARRAY = 0x01,
45  FD_ISCOMPOUND = 0x02,
46  FD_ISPOINTER = 0x04,
47  FD_ISCOBJECT = 0x08,
48  FD_ISCOWNEDOBJECT = 0x10,
49  FD_ISEDITABLE = 0x20,
50  FD_ISREPLACEABLE = 0x40,
51  FD_ISRESIZABLE = 0x80,
52  FD_NONE = 0x0
53  };
54 
55  private:
56  std::string baseClassName;
57  cClassDescriptor *baseClassDesc = nullptr;
58  int inheritanceChainLength = 1;
59  int extendscObject = -1; // 0:false, 1:true, -1:unset
60 
61  protected:
62  // utility functions for converting from/to strings
63  static std::string long2string(long l);
64  static long string2long(const char *s);
65  static std::string ulong2string(unsigned long l);
66  static unsigned long string2ulong(const char *s);
67  static std::string int642string(int64_t l);
68  static int64_t string2int64(const char *s);
69  static std::string uint642string(uint64_t l);
70  static uint64_t string2uint64(const char *s);
71  static std::string bool2string(bool b);
72  static bool string2bool(const char *s);
73  static std::string double2string(double d);
74  static double string2double(const char *s);
75  static std::string simtime2string(SimTime t) {return t.ustr();}
76  static simtime_t string2simtime(const char *s) {return SimTime::parse(s);}
77  std::string enum2string(int e, const char *enumName) const;
78  int string2enum(const char *s, const char *enumName) const;
79  static std::string oppstring2string(const char *s) {return s?s:"";}
80  static std::string oppstring2string(const opp_string& s) {return s.c_str();}
81  static std::string oppstring2string(const std::string& s) {return s;}
82  static void string2oppstring(const char *s, opp_string& str) {str = s?s:"";}
83  static void string2oppstring(const char *s, std::string& str) {str = s?s:"";}
84  static const char **mergeLists(const char **list1, const char **list2);
85 
86  public:
89 
93  cClassDescriptor(const char *className, const char *baseClassName=nullptr);
94 
98  virtual ~cClassDescriptor() {}
100 
103 
108  static cClassDescriptor *getDescriptorFor(const char *classname);
109 
115  static cClassDescriptor *getDescriptorFor(const cObject *object);
117 
120 
126  virtual bool doesSupport(cObject *obj) const {return false;}
127 
131  virtual cClassDescriptor *getBaseClassDescriptor() const;
132 
136  bool extendsCObject() const;
137 
141  std::string getNamespace() const;
142 
147  int getInheritanceChainLength() const;
148 
153  virtual const char **getPropertyNames() const = 0;
154 
162  virtual const char *getProperty(const char *propertyname) const = 0;
163 
167  virtual int getFieldCount() const = 0;
168 
173  virtual const char *getFieldName(int field) const = 0;
174 
180  virtual int findField(const char *fieldName) const;
181 
188  virtual unsigned int getFieldTypeFlags(int field) const = 0;
189 
192  bool getFieldIsArray(int field) const {return getFieldTypeFlags(field) & FD_ISARRAY;}
193  bool getFieldIsCompound(int field) const {return getFieldTypeFlags(field) & FD_ISCOMPOUND;}
194  bool getFieldIsPointer(int field) const {return getFieldTypeFlags(field) & FD_ISPOINTER;}
195  bool getFieldIsCObject(int field) const {return getFieldTypeFlags(field) & (FD_ISCOBJECT|FD_ISCOWNEDOBJECT);}
196  bool getFieldIsCOwnedObject(int field) const {return getFieldTypeFlags(field) & FD_ISCOWNEDOBJECT;}
197  bool getFieldIsEditable(int field) const {return getFieldTypeFlags(field) & FD_ISEDITABLE;}
198  bool getFieldIsReplaceable(int field) const {return getFieldTypeFlags(field) & FD_ISREPLACEABLE;}
199  bool getFieldIsResizable(int field) const {return getFieldTypeFlags(field) & FD_ISRESIZABLE;}
201 
205  virtual const char *getFieldDeclaredOn(int field) const;
206 
213  virtual const char *getFieldTypeString(int field) const = 0;
214 
219  virtual const char **getFieldPropertyNames(int field) const = 0;
220 
227  virtual const char *getFieldProperty(int field, const char *propertyname) const = 0;
228 
233  virtual int getFieldArraySize(any_ptr object, int field) const = 0;
234 
243  virtual void setFieldArraySize(any_ptr object, int field, int size) const = 0;
244 
256  virtual const char *getFieldDynamicTypeString(any_ptr object, int field, int i) const {return nullptr;}
257 
266  virtual std::string getFieldValueAsString(any_ptr object, int field, int i) const = 0;
267 
276  virtual void setFieldValueAsString(any_ptr object, int field, int i, const char *value) const = 0;
277 
285  virtual cValue getFieldValue(any_ptr object, int field, int i) const = 0;
286 
295  virtual void setFieldValue(any_ptr object, int field, int i, const cValue& value) const = 0;
296 
302  virtual const char *getFieldStructName(int field) const = 0;
303 
310  virtual any_ptr getFieldStructValuePointer(any_ptr object, int field, int i) const = 0;
311 
320  virtual void setFieldStructValuePointer(any_ptr object, int field, int i, any_ptr ptr) const = 0;
322 };
323 
324 } // namespace omnetpp
325 
326 
327 #endif
328 
329 
omnetpp::cClassDescriptor
Abstract base class for class descriptors.
Definition: cclassdescriptor.h:39
omnetpp::SimTime::ustr
std::string ustr() const
omnetpp::cObject
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition: cobject.h:92
omnetpp::cValue
A variant-like value class used during evaluating NED expressions.
Definition: cvalue.h:47
omnetpp::any_ptr
A type-safe equivalent of the void* pointer.
Definition: any_ptr.h:61
omnetpp::SimTime
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
omnetpp::cClassDescriptor::getFieldDynamicTypeString
virtual const char * getFieldDynamicTypeString(any_ptr object, int field, int i) const
Definition: cclassdescriptor.h:256
omnetpp::cClassDescriptor::~cClassDescriptor
virtual ~cClassDescriptor()
Definition: cclassdescriptor.h:98
omnetpp::simtime_t
SimTime simtime_t
Represents simulation time.
Definition: simtime_t.h:40
omnetpp::cNoncopyableOwnedObject
Base class for cOwnedObject-based classes that do not wish to support assignment and duplication.
Definition: cownedobject.h:242
omnetpp::cClassDescriptor::doesSupport
virtual bool doesSupport(cObject *obj) const
Definition: cclassdescriptor.h:126
omnetpp::SimTime::parse
static const SimTime parse(const char *s)