cvaluemap.h Source File

API: cvaluemap.h Source File
API
cvaluemap.h
1//==========================================================================
2// CVALUEMAP.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_CVALUEMAP_H
17#define __OMNETPP_CVALUEMAP_H
18
19#include <string>
20#include <map>
21#include "cvalue.h"
22#include "cvaluecontainer.h"
23
24namespace omnetpp {
25
36class SIM_API cValueMap : public cValueContainer
37{
38 private:
39 std::map<std::string,cValue> fields;
40
41 private:
42 void copy(const cValueMap& other);
43
44 public:
45 // internal, for inspectors only:
46 typedef std::map<std::string,cValue>::value_type Entry;
47 const Entry& getEntry(int k) const;
48 static std::string entryToStr(const Entry& e) {return e.first + " : " + e.second.str();}
49
50 public:
53
62 cValueMap(const cValueMap& other) : cValueContainer(other) {copy(other);}
63
67 explicit cValueMap(const char *name=nullptr) : cValueContainer(name) {}
68
73 virtual ~cValueMap();
74
83
86
96 virtual cValueMap *dup() const override {return new cValueMap(*this);}
97
102 virtual std::string str() const override;
103
108 virtual void forEachChild(cVisitor *v) override;
110
113
117 virtual int size() const {return fields.size();}
118
122 virtual void clear();
123
127 virtual void set(const char *key, const cValue& value);
128
132 virtual bool containsKey(const char *key) const;
133
137 virtual const cValue& get(const char *key) const;
138
142 const cValue& operator[](const char *key) const {return get(key);}
143
147 virtual void erase(const char *key);
148
152 const std::map<std::string,cValue>& getFields() const {return fields;}
154};
155
156
157} // namespace omnetpp
158
159#endif
160
161
cValueContainer(const char *name=nullptr)
Definition cvaluecontainer.h:49
virtual void erase(const char *key)
const cValue & operator[](const char *key) const
Definition cvaluemap.h:142
virtual int size() const
Definition cvaluemap.h:117
virtual bool containsKey(const char *key) const
virtual const cValue & get(const char *key) const
cValueMap & operator=(const cValueMap &other)
cValueMap(const char *name=nullptr)
Definition cvaluemap.h:67
virtual ~cValueMap()
cValueMap(const cValueMap &other)
Definition cvaluemap.h:62
virtual void clear()
virtual void forEachChild(cVisitor *v) override
virtual void set(const char *key, const cValue &value)
virtual std::string str() const override
const std::map< std::string, cValue > & getFields() const
Definition cvaluemap.h:152
virtual cValueMap * dup() const override
Definition cvaluemap.h:96
A variant-like value class used during evaluating NED expressions.
Definition cvalue.h:48
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition cvisitor.h:57