OMNeT++ Simulation Library  5.6.1
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 "cstringpool.h"
25 #include "cproperties.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  // property names, keys and values are all stringpooled to reduce memory consumption
51  static cStringPool stringPool;
52 
53  cProperties *ownerp;
54 
55  const char *propindex;
56  mutable const char *propfullname;
57 
58  typedef std::vector<const char *> CharPtrVector;
59  CharPtrVector keyv;
60  std::vector<CharPtrVector> valuesv;
61 
62  private:
63  void copy(const cProperty& other);
64 
65  protected:
66  static void releaseValues(CharPtrVector& vals);
67  int findKey(const char *key) const;
68  CharPtrVector& getValuesVector(const char *key) const;
69 
70  public:
71  // internal: merge a property onto this one
72  virtual void updateWith(const cProperty *property);
73 
74  // internal: locks the object against modifications. It cannot be unlocked
75  // -- one must copy contents to an unlocked object, or call dup()
76  // (new objects are created in unlocked state).
77  virtual void lock() {setFlag(FL_ISLOCKED, true);}
78 
79  // internal:
80  virtual bool isLocked() const {return flags&FL_ISLOCKED;}
81 
82  // internal: set the containing cProperties
83  virtual void setOwner(cProperties *p) {ownerp = p;}
84 
85  public:
88 
92  explicit cProperty(const char *name=nullptr, const char *index=nullptr);
93 
97  cProperty(const cProperty& other) : cNamedObject(other) {setFlag(FL_ISLOCKED,false); propindex=propfullname=nullptr; copy(other);}
98 
102  virtual ~cProperty();
103 
107  cProperty& operator=(const cProperty& other);
109 
116  virtual void setName(const char *name) override;
117 
121  virtual const char *getFullName() const override;
122 
126  virtual cProperty *dup() const override {return new cProperty(*this);}
127 
131  virtual std::string str() const override;
132 
136  virtual void parsimPack(cCommBuffer *buffer) const override;
137 
141  virtual void parsimUnpack(cCommBuffer *buffer) override;
143 
150  virtual void setIndex(const char *index);
151 
158  virtual const char *getIndex() const;
159 
163  virtual void setIsImplicit(bool b);
164 
170  virtual bool isImplicit() const;
171 
176  virtual const std::vector<const char *>& getKeys() const;
177 
182  virtual bool containsKey(const char *key) const;
183 
188  virtual void addKey(const char *key);
189 
196  virtual int getNumValues(const char *key) const;
197 
206  virtual void setNumValues(const char *key, int size);
207 
213  virtual const char *getValue(const char *key="", int index=0) const;
214 
224  virtual void setValue(const char *key, int index, const char *value);
225 
229  virtual void erase(const char *key);
231 };
232 
233 } // namespace omnetpp
234 
235 
236 #endif
237 
238 
Extends cObject with a name string. Also includes a "flags" member, with bits open for use by subclas...
Definition: cnamedobject.h:36
cProperty(const cProperty &other)
Definition: cproperty.h:97
Stores a (NED) property with its (possibly compound) value.
Definition: cproperty.h:38
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41
Definition: cabstracthistogram.h:21
A collection of properties (cProperty).
Definition: cproperties.h:34
virtual cProperty * dup() const override
Definition: cproperty.h:126
Reference-counted storage for strings.
Definition: cstringpool.h:36