OMNeT++ API 6.1
Discrete Event Simulation Library
cvalueholder.h
1 //==========================================================================
2 // CVALUEHOLDER.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_CVALUEHOLDER_H
17 #define __OMNETPP_CVALUEHOLDER_H
18 
19 #include <string>
20 #include <vector>
21 #include "cvalue.h"
22 #include "cvaluecontainer.h"
23 
24 
25 namespace omnetpp {
26 
37 class SIM_API cValueHolder : public cValueContainer
38 {
39  private:
40  cValue value;
41 
42  private:
43  void copy(const cValueHolder& other);
44 
45  public:
48 
57  cValueHolder(const cValueHolder& other) : cValueContainer(other) {copy(other);}
58 
62  explicit cValueHolder(const char *name=nullptr) : cValueContainer(name) {}
63 
67  explicit cValueHolder(const char *name, const cValue& value) : cValueContainer(name), value(value) {takeValue(this->value);}
68 
73  virtual ~cValueHolder() {dropAndDeleteValue(value);}
74 
81  cValueHolder& operator=(const cValueHolder& other);
83 
86 
96  virtual cValueHolder *dup() const override {return new cValueHolder(*this);}
97 
102  virtual std::string str() const override {return value.str();}
103 
108  virtual void forEachChild(cVisitor* v) override;
110 
116  const cValue& get() const {return value;}
117 
121  void set(const cValue& v) {dropAndDeleteValue(value); value = v; takeValue(value);}
123 
124 };
125 
126 
127 } // namespace omnetpp
128 
129 #endif
130 
131 
omnetpp::cValueHolder::~cValueHolder
virtual ~cValueHolder()
Definition: cvalueholder.h:73
omnetpp::cValueHolder::get
const cValue & get() const
Definition: cvalueholder.h:116
omnetpp::cValueContainer
Common base class for cValue-based containers.
Definition: cvaluecontainer.h:32
omnetpp::cValue
A variant-like value class used during evaluating NED expressions.
Definition: cvalue.h:47
omnetpp::cValue::str
std::string str() const
omnetpp::cVisitor
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition: cvisitor.h:56
omnetpp::cValueHolder::cValueHolder
cValueHolder(const cValueHolder &other)
Definition: cvalueholder.h:57
omnetpp::cValueHolder::cValueHolder
cValueHolder(const char *name, const cValue &value)
Definition: cvalueholder.h:67
omnetpp::cValueHolder::set
void set(const cValue &v)
Definition: cvalueholder.h:121
omnetpp::cValueHolder
cOwnedObject-based container/wrapper to hold a single cValue.
Definition: cvalueholder.h:37
omnetpp::cValueHolder::dup
virtual cValueHolder * dup() const override
Definition: cvalueholder.h:96
omnetpp::cValueHolder::cValueHolder
cValueHolder(const char *name=nullptr)
Definition: cvalueholder.h:62
omnetpp::cValueHolder::str
virtual std::string str() const override
Definition: cvalueholder.h:102