OMNeT++ Simulation Library  6.0.3
cproperties.h
1 //==========================================================================
2 // CPROPERTIES.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_CPROPERTIES_H
17 #define __OMNETPP_CPROPERTIES_H
18 
19 #include <vector>
20 #include "simkerneldefs.h"
21 #include "globals.h"
22 #include "cobject.h"
23 
24 namespace omnetpp {
25 
26 class cProperty;
27 
28 
34 class SIM_API cProperties : public cObject
35 {
36  protected:
37  bool isLocked = false;
38  int refCount = 0;
39  std::vector<cProperty *> properties;
40 
41  private:
42  void copy(const cProperties& other);
43 
44  public:
45  // internal: locks the object and all contained properties against modifications.
46  // The object cannot be unlocked -- one must copy contents to an unlocked
47  // object, or call dup() (new objects are created in unlocked state).
48  virtual void lock();
49 
50  // internal: increment/decrement reference count
51  int addRef() {return ++refCount;}
52  int removeRef() {return --refCount;}
53 
54  public:
60  explicit cProperties() {}
61 
65  cProperties(const cProperties& other) : cObject(other) {refCount=0; isLocked=false; copy(other);}
66 
70  virtual ~cProperties();
71 
75  cProperties& operator=(const cProperties& other);
77 
83  virtual cProperties *dup() const override {return new cProperties(*this);}
84 
88  virtual const char *getName() const override {return "properties";}
89 
93  virtual std::string str() const override;
94 
98  virtual void parsimPack(cCommBuffer *buffer) const override;
99 
103  virtual void parsimUnpack(cCommBuffer *buffer) override;
105 
111  virtual int getNumProperties() const {return properties.size();}
112 
118  virtual const std::vector<const char *> getNames() const;
119 
123  virtual cProperty *get(int k) const;
124 
131  virtual cProperty *get(const char *name, const char *index=nullptr) const;
132 
149  virtual bool getAsBool(const char *name, const char *index=nullptr) const;
150 
157  virtual std::vector<const char *> getIndicesFor(const char *name) const;
158 
162  virtual void add(cProperty *p);
163 
167  virtual void remove(int k);
169 };
170 
171 } // namespace omnetpp
172 
173 
174 #endif
175 
176 
omnetpp::cObject
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition: cobject.h:92
omnetpp::cProperties::getNumProperties
virtual int getNumProperties() const
Definition: cproperties.h:111
omnetpp::cProperties::dup
virtual cProperties * dup() const override
Definition: cproperties.h:83
omnetpp::cProperties::cProperties
cProperties(const cProperties &other)
Definition: cproperties.h:65
omnetpp::cProperties
A collection of properties (cProperty).
Definition: cproperties.h:34
omnetpp::cProperties::cProperties
cProperties()
Definition: cproperties.h:60
omnetpp::cProperties::getName
virtual const char * getName() const override
Definition: cproperties.h:88
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