OMNeT++ API 6.1
Discrete Event Simulation Library
cproperty.h
1 //==========================================================================
2 // CPROPERTY.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_CPROPERTY_H
17 #define __OMNETPP_CPROPERTY_H
18 
19 #include <map>
20 #include <vector>
21 #include "simkerneldefs.h"
22 #include "globals.h"
23 #include "cobject.h"
24 #include "cproperties.h"
25 #include "opp_pooledstring.h"
26 
27 namespace omnetpp {
28 
29 
38 class SIM_API cProperty : public cNamedObject
39 {
40  public:
41  static const char *DEFAULTKEY;
42 
43  private:
44  enum {
45  FL_ISLOCKED = 4,
46  FL_ISIMPLICIT = 8,
47  };
48 
49  protected:
50  cProperties *ownerp = nullptr;
51 
52  opp_staticpooledstring indexString = nullptr;
53  mutable opp_staticpooledstring fullName = nullptr;
54 
55  struct Value {
57  opp_staticpooledstring originFile;
58  opp_staticpooledstring originType;
59  };
60  typedef std::vector<Value> ValueList;
61  std::vector<opp_staticpooledstring> keyv;
62  std::vector<ValueList> valuesv;
63 
64  private:
65  void copy(const cProperty& other);
66 
67  protected:
68  int findKey(const char *key) const;
69  ValueList& getValuesVector(const char *key);
70  const ValueList& getValuesVector(const char *key) const;
71 
72  public:
73  // internal: locks the object against modifications. It cannot be unlocked
74  // -- one must copy contents to an unlocked object, or call dup()
75  // (new objects are created in unlocked state).
76  virtual void lock() {setFlag(FL_ISLOCKED, true);}
77 
78  // internal:
79  virtual bool isLocked() const {return flags&FL_ISLOCKED;}
80 
81  // internal: set the containing cProperties
82  virtual void setOwner(cProperties *p) {ownerp = p;}
83 
84  // internal: print values in NED syntax
85  virtual void printValues(std::ostream& os) const;
86 
87  public:
90 
94  explicit cProperty(const char *name=nullptr, const char *index=nullptr);
95 
99  cProperty(const cProperty& other) : cNamedObject(other) {setFlag(FL_ISLOCKED,false); indexString=fullName=nullptr; copy(other);}
100 
104  virtual ~cProperty();
105 
109  cProperty& operator=(const cProperty& other);
111 
118  virtual void setName(const char *name) override;
119 
123  virtual const char *getFullName() const override;
124 
128  virtual cProperty *dup() const override {return new cProperty(*this);}
129 
134  virtual std::string str() const override;
135 
139  virtual void parsimPack(cCommBuffer *buffer) const override;
140 
144  virtual void parsimUnpack(cCommBuffer *buffer) override;
146 
153  virtual void setIndex(const char *index);
154 
161  virtual const char *getIndex() const;
162 
166  virtual void setIsImplicit(bool b);
167 
173  virtual bool isImplicit() const;
174 
179  virtual std::vector<const char *> getKeys() const;
180 
185  virtual bool containsKey(const char *key) const;
186 
191  virtual void addKey(const char *key);
192 
196  virtual int getNumKeys() const {return keyv.size();}
197 
204  virtual int getNumValues(const char *key) const;
205 
214  virtual void setNumValues(const char *key, int size);
215 
221  virtual const char *getValue(const char *key="", int index=0) const;
222 
229  virtual const char *getValueOriginFile(const char *key="", int index=0) const;
230 
237  virtual const char *getValueOriginType(const char *key="", int index=0) const;
238 
248  virtual void setValue(const char *key, int index, const char *value, const char *originFile=nullptr, const char *originType=nullptr);
249 
253  virtual void erase(const char *key);
254 
262  virtual void updateWith(const cProperty *other);
264 };
265 
266 } // namespace omnetpp
267 
268 
269 #endif
270 
271 
omnetpp::cProperty::cProperty
cProperty(const cProperty &other)
Definition: cproperty.h:99
omnetpp::cProperty::getNumKeys
virtual int getNumKeys() const
Definition: cproperty.h:196
omnetpp::cProperties
A collection of properties (cProperty).
Definition: cproperties.h:34
omnetpp::opp_staticpooledstring
Definition: opp_pooledstring.h:29
omnetpp::cNamedObject
Extends cObject with a name string. Also includes a "flags" member, with bits open for use by subclas...
Definition: cnamedobject.h:34
omnetpp::cProperty::dup
virtual cProperty * dup() const override
Definition: cproperty.h:128
omnetpp::cProperty
Stores a (NED) property with its (possibly compound) value.
Definition: cproperty.h:38
omnetpp::cCommBuffer
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41