cproperties.h Source File

API: cproperties.h Source File
API
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
24namespace omnetpp {
25
26class cProperty;
27
28
34class 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:
57
60 explicit cProperties() {}
61
65 cProperties(const cProperties& other) : cObject(other) {refCount=0; isLocked=false; copy(other);}
66
70 virtual ~cProperties();
71
77
80
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
108
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
Buffer for the communications layer of parallel simulation.
Definition ccommbuffer.h:42
cObject()
Definition cobject.h:124
virtual void add(cProperty *p)
cProperties()
Definition cproperties.h:60
virtual const std::vector< const char * > getNames() const
cProperties(const cProperties &other)
Definition cproperties.h:65
virtual void parsimPack(cCommBuffer *buffer) const override
cProperties & operator=(const cProperties &other)
virtual cProperty * get(int k) const
virtual void parsimUnpack(cCommBuffer *buffer) override
virtual cProperty * get(const char *name, const char *index=nullptr) const
virtual void remove(int k)
virtual const char * getName() const override
Definition cproperties.h:88
virtual bool getAsBool(const char *name, const char *index=nullptr) const
virtual std::vector< const char * > getIndicesFor(const char *name) const
virtual cProperties * dup() const override
Definition cproperties.h:83
virtual std::string str() const override
virtual int getNumProperties() const
Definition cproperties.h:111
Stores a (NED) property with its (possibly compound) value.
Definition cproperty.h:39