OMNeT++ Simulation Library  5.6.1
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 
24 namespace omnetpp {
25 
26 
45 {
46  public:
48  enum {
49  FD_ISARRAY = 0x01,
50  FD_ISCOMPOUND = 0x02,
51  FD_ISPOINTER = 0x04,
52  FD_ISCOBJECT = 0x08,
53  FD_ISCOWNEDOBJECT = 0x10,
54  FD_ISEDITABLE = 0x20,
55  FD_NONE = 0x0
56  };
57 
58  private:
59  std::string baseClassName;
60  cClassDescriptor *baseClassDesc;
61  int inheritanceChainLength;
62  int extendscObject; // 0:false, 1:true, -1:unset
63 
64  protected:
65  // utility functions for converting from/to strings
66  static std::string long2string(long l);
67  static long string2long(const char *s);
68  static std::string ulong2string(unsigned long l);
69  static unsigned long string2ulong(const char *s);
70  static std::string int642string(int64_t l);
71  static int64_t string2int64(const char *s);
72  static std::string uint642string(uint64_t l);
73  static uint64_t string2uint64(const char *s);
74  static std::string bool2string(bool b);
75  static bool string2bool(const char *s);
76  static std::string double2string(double d);
77  static double string2double(const char *s);
78  static std::string simtime2string(SimTime t) {return t.ustr();}
79  static simtime_t string2simtime(const char *s) {return SimTime::parse(s);}
80  std::string enum2string(int e, const char *enumName) const;
81  int string2enum(const char *s, const char *enumName) const;
82  static std::string oppstring2string(const char *s) {return s?s:"";}
83  static std::string oppstring2string(const opp_string& s) {return s.c_str();}
84  static std::string oppstring2string(const std::string& s) {return s;}
85  static void string2oppstring(const char *s, opp_string& str) {str = s?s:"";}
86  static void string2oppstring(const char *s, std::string& str) {str = s?s:"";}
87  static const char **mergeLists(const char **list1, const char **list2);
88 
89  public:
92 
96  cClassDescriptor(const char *className, const char *baseClassName=nullptr);
97 
101  virtual ~cClassDescriptor();
103 
106 
111  static cClassDescriptor *getDescriptorFor(const char *classname);
112 
118  static cClassDescriptor *getDescriptorFor(const cObject *object);
120 
123 
129  virtual bool doesSupport(cObject *obj) const {return false;}
130 
134  virtual cClassDescriptor *getBaseClassDescriptor() const;
135 
139  bool extendsCObject() const;
140 
144  std::string getNamespace() const;
145 
150  int getInheritanceChainLength() const;
151 
156  virtual const char **getPropertyNames() const = 0;
157 
165  virtual const char *getProperty(const char *propertyname) const = 0;
166 
170  virtual int getFieldCount() const = 0;
171 
176  virtual const char *getFieldName(int field) const = 0;
177 
183  virtual int findField(const char *fieldName) const;
184 
191  virtual unsigned int getFieldTypeFlags(int field) const = 0;
192 
195  bool getFieldIsArray(int field) const {return getFieldTypeFlags(field) & FD_ISARRAY;}
196  bool getFieldIsCompound(int field) const {return getFieldTypeFlags(field) & FD_ISCOMPOUND;}
197  bool getFieldIsPointer(int field) const {return getFieldTypeFlags(field) & FD_ISPOINTER;}
198  bool getFieldIsCObject(int field) const {return getFieldTypeFlags(field) & (FD_ISCOBJECT|FD_ISCOWNEDOBJECT);}
199  bool getFieldIsCOwnedObject(int field) const {return getFieldTypeFlags(field) & FD_ISCOWNEDOBJECT;}
200  bool getFieldIsEditable(int field) const {return getFieldTypeFlags(field) & FD_ISEDITABLE;}
202 
206  virtual const char *getFieldDeclaredOn(int field) const;
207 
214  virtual const char *getFieldTypeString(int field) const = 0;
215 
220  virtual const char **getFieldPropertyNames(int field) const = 0;
221 
228  virtual const char *getFieldProperty(int field, const char *propertyname) const = 0;
229 
234  virtual int getFieldArraySize(void *object, int field) const = 0;
235 
247  virtual const char *getFieldDynamicTypeString(void *object, int field, int i) const {return nullptr;}
248 
257  virtual std::string getFieldValueAsString(void *object, int field, int i) const = 0;
258 
268  virtual bool setFieldValueAsString(void *object, int field, int i, const char *value) const = 0;
269 
275  virtual const char *getFieldStructName(int field) const = 0;
276 
280  virtual void *getFieldStructValuePointer(void *object, int field, int i) const = 0;
282 };
283 
284 } // namespace omnetpp
285 
286 
287 #endif
288 
289 
Lightweight string class, used internally in some parts of OMNeT++.
Definition: opp_string.h:39
Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members...
Definition: cobject.h:58
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
static const SimTime parse(const char *s)
virtual const char * getFieldDynamicTypeString(void *object, int field, int i) const
Definition: cclassdescriptor.h:247
virtual bool doesSupport(cObject *obj) const
Definition: cclassdescriptor.h:129
std::string ustr() const
const char * c_str() const
Definition: opp_string.h:78
Definition: cabstracthistogram.h:21
Abstract base class for structure description classes, used mainly with message subclassing.
Definition: cclassdescriptor.h:44
Base class for cOwnedObject-based classes that do not wish to support assignment and duplication...
Definition: cownedobject.h:248