cclassdescriptor.h Source File¶

API: cclassdescriptor.h Source File
API
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
25namespace omnetpp {
26
27class cValue;
28
39class SIM_API cClassDescriptor : public cNoncopyableOwnedObject
40{
41 public:
43 enum {
44 FD_ISARRAY = 0x01,
46 FD_ISPOINTER = 0x04,
47 FD_ISCOBJECT = 0x08,
52 FD_NONE = 0x0
53 };
54
56 static constexpr const char *UNPRINTABLE = "(unprintable)";
57
58 private:
59 std::string baseClassName;
60 cClassDescriptor *baseClassDesc = nullptr;
61 int inheritanceChainLength = 1;
62 int extendscObject = -1; // 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 intval_t 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
120
123
129 virtual bool doesSupport(cObject *obj) const {return false;}
130
135
139 bool extendsCObject() const;
140
144 std::string getNamespace() const;
145
151
156 virtual const char **getPropertyNames() const = 0;
157
165 virtual const char *getProperty(const char *propertyname) const = 0;
166
170 virtual std::string getValueAsString(any_ptr object) const {return "";}
171
176 virtual void setValueAsString(any_ptr object, const char *value) const;
177
181 virtual int getFieldCount() const = 0;
182
187 virtual const char *getFieldName(int field) const = 0;
188
194 virtual int findField(const char *fieldName) const;
195
202 virtual unsigned int getFieldTypeFlags(int field) const = 0;
203
206 bool getFieldIsArray(int field) const {return getFieldTypeFlags(field) & FD_ISARRAY;}
207 bool getFieldIsCompound(int field) const {return getFieldTypeFlags(field) & FD_ISCOMPOUND;}
208 bool getFieldIsPointer(int field) const {return getFieldTypeFlags(field) & FD_ISPOINTER;}
209 bool getFieldIsCObject(int field) const {return getFieldTypeFlags(field) & (FD_ISCOBJECT|FD_ISCOWNEDOBJECT);}
210 bool getFieldIsCOwnedObject(int field) const {return getFieldTypeFlags(field) & FD_ISCOWNEDOBJECT;}
211 bool getFieldIsEditable(int field) const {return getFieldTypeFlags(field) & FD_ISEDITABLE;}
212 bool getFieldIsReplaceable(int field) const {return getFieldTypeFlags(field) & FD_ISREPLACEABLE;}
213 bool getFieldIsResizable(int field) const {return getFieldTypeFlags(field) & FD_ISRESIZABLE;}
215
219 virtual const char *getFieldDeclaredOn(int field) const;
220
227 virtual const char *getFieldTypeString(int field) const = 0;
228
233 virtual const char **getFieldPropertyNames(int field) const = 0;
234
241 virtual const char *getFieldProperty(int field, const char *propertyname) const = 0;
242
247 virtual int getFieldArraySize(any_ptr object, int field) const = 0;
248
257 virtual void setFieldArraySize(any_ptr object, int field, int size) const = 0;
258
270 virtual const char *getFieldDynamicTypeString(any_ptr object, int field, int i) const {return nullptr;}
271
280 virtual std::string getFieldValueAsString(any_ptr object, int field, int i) const = 0;
281
290 virtual void setFieldValueAsString(any_ptr object, int field, int i, const char *value) const = 0;
291
299 virtual cValue getFieldValue(any_ptr object, int field, int i) const = 0;
300
309 virtual void setFieldValue(any_ptr object, int field, int i, const cValue& value) const = 0;
310
316 virtual const char *getFieldStructName(int field) const = 0;
317
324 virtual any_ptr getFieldStructValuePointer(any_ptr object, int field, int i) const = 0;
325
334 virtual void setFieldStructValuePointer(any_ptr object, int field, int i, any_ptr ptr) const = 0;
335
345 virtual std::string getFieldArrayIndexString(any_ptr object, int field, int arrayIndex) const;
347};
348
349} // namespace omnetpp
350
351
352#endif
353
354
int64_t-based, base-10 fixed-point simulation time.
Definition simtime.h:67
static const SimTime parse(const char *s)
std::string ustr() const
A type-safe equivalent of the void* pointer.
Definition any_ptr.h:63
virtual const char * getFieldDeclaredOn(int field) const
virtual ~cClassDescriptor()
Definition cclassdescriptor.h:101
virtual bool doesSupport(cObject *obj) const
Definition cclassdescriptor.h:129
static cClassDescriptor * getDescriptorFor(const char *classname)
virtual const char ** getPropertyNames() const =0
virtual const char * getFieldName(int field) const =0
virtual std::string getFieldValueAsString(any_ptr object, int field, int i) const =0
virtual int getFieldCount() const =0
std::string getNamespace() const
virtual any_ptr getFieldStructValuePointer(any_ptr object, int field, int i) const =0
virtual void setFieldValue(any_ptr object, int field, int i, const cValue &value) const =0
virtual const char * getProperty(const char *propertyname) const =0
@ FD_ISRESIZABLE
whether field supports setFieldArraySize()
Definition cclassdescriptor.h:51
@ FD_ISARRAY
field is an array: int a[]; int a[10];
Definition cclassdescriptor.h:44
@ FD_ISCOBJECT
if ISCOMPOUND: basic type (T) subclasses from cObject
Definition cclassdescriptor.h:47
@ FD_ISEDITABLE
whether field supports setFieldValueAsString()
Definition cclassdescriptor.h:49
@ FD_ISREPLACEABLE
whether field supports setFieldStructValuePointer()
Definition cclassdescriptor.h:50
@ FD_ISCOMPOUND
basic type (T) is struct or class: T a; T *a; T a[10]; T *a[]
Definition cclassdescriptor.h:45
@ FD_ISCOWNEDOBJECT
if ISCOMPOUND: basic type (T) subclasses from cOwnedObject
Definition cclassdescriptor.h:48
@ FD_ISPOINTER
field is pointer or pointer array: T *a; T *a[]; T *a[10];
Definition cclassdescriptor.h:46
virtual const char * getFieldDynamicTypeString(any_ptr object, int field, int i) const
Definition cclassdescriptor.h:270
virtual void setFieldStructValuePointer(any_ptr object, int field, int i, any_ptr ptr) const =0
virtual std::string getFieldArrayIndexString(any_ptr object, int field, int arrayIndex) const
virtual unsigned int getFieldTypeFlags(int field) const =0
virtual void setFieldArraySize(any_ptr object, int field, int size) const =0
virtual int getFieldArraySize(any_ptr object, int field) const =0
virtual cClassDescriptor * getBaseClassDescriptor() const
static constexpr const char * UNPRINTABLE
Returned by getValueAsString() and getFieldValueAsString() for types that have no text representation...
Definition cclassdescriptor.h:56
virtual int findField(const char *fieldName) const
virtual const char * getFieldTypeString(int field) const =0
cClassDescriptor(const char *className, const char *baseClassName=nullptr)
virtual std::string getValueAsString(any_ptr object) const
Definition cclassdescriptor.h:170
virtual void setFieldValueAsString(any_ptr object, int field, int i, const char *value) const =0
virtual void setValueAsString(any_ptr object, const char *value) const
virtual const char * getFieldProperty(int field, const char *propertyname) const =0
int getInheritanceChainLength() const
virtual const char ** getFieldPropertyNames(int field) const =0
virtual cValue getFieldValue(any_ptr object, int field, int i) const =0
virtual const char * getFieldStructName(int field) const =0
static cClassDescriptor * getDescriptorFor(const cObject *object)
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition cobject.h:93
A variant-like value class used during evaluating NED expressions.
Definition cvalue.h:48
SimTime simtime_t
Represents simulation time.
Definition simtime_t.h:40