OMNeT++ Simulation Library  6.0.3
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 
24 namespace omnetpp {
25 
36 class 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 
81  cValueMap& operator=(const cValueMap& other);
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 
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::cValueMap::cValueMap
cValueMap(const char *name=nullptr)
Definition: cvaluemap.h:67
omnetpp::cValueMap::dup
virtual cValueMap * dup() const override
Definition: cvaluemap.h:96
omnetpp::cVisitor
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition: cvisitor.h:56
omnetpp::cValueMap::cValueMap
cValueMap(const cValueMap &other)
Definition: cvaluemap.h:62
omnetpp::cValueMap::size
virtual int size() const
Definition: cvaluemap.h:117
omnetpp::cValueMap::operator[]
const cValue & operator[](const char *key) const
Definition: cvaluemap.h:142
omnetpp::cValueMap
Key-value container class based on std::map<std::string,cValue>.
Definition: cvaluemap.h:36
omnetpp::cValueMap::getFields
const std::map< std::string, cValue > & getFields() const
Definition: cvaluemap.h:152