OMNeT++ Simulation Library  6.0.3
cenum.h
1 //==========================================================================
2 // CENUM.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_CENUM_H
17 #define __OMNETPP_CENUM_H
18 
19 #include "cownedobject.h"
20 
21 namespace omnetpp {
22 
32 class SIM_API cEnum : public cOwnedObject
33 {
34  private:
35  std::map<int,std::string> valueToNameMap;
36  std::map<std::string,int> nameToValueMap;
37  std::vector<std::string> tmpNames;
38 
39  private:
40  void copy(const cEnum& other);
41 
42  public:
43  // internal: helper for the Register_Enum() macro
44  cEnum *registerNames(const char *nameList);
45  // internal: helper for the Register_Enum() macro
46  cEnum *registerValues(int first, ...);
47  cEnum *registerValues() {return this;} // for empty enum
48 
49  public:
55  explicit cEnum(const char *name=nullptr);
56 
69  cEnum(const char *name, const char *str, ...);
70 
74  cEnum(const cEnum& cenum);
75 
79  virtual ~cEnum() {}
80 
85  cEnum& operator=(const cEnum& list);
87 
90 
95  virtual cEnum *dup() const override {return new cEnum(*this);}
96 
100  virtual std::string str() const override;
102 
108  void insert(int value, const char *name);
109 
121  void bulkInsert(const char *name1, ...);
122 
127  const char *getStringFor(int value);
128 
133  int lookup(const char *name, int fallback=-1);
134 
138  int resolve(const char *name);
139 
143  std::map<std::string,int> getNameValueMap() const {return nameToValueMap;}
145 
153  static cEnum *find(const char *enumName, const char *contextNamespace=nullptr);
154 
158  static cEnum *get(const char *enumName, const char *contextNamespace=nullptr);
160 
161 };
162 
163 } // namespace omnetpp
164 
165 
166 #endif
167 
omnetpp::cEnum::getNameValueMap
std::map< std::string, int > getNameValueMap() const
Definition: cenum.h:143
omnetpp::cEnum::~cEnum
virtual ~cEnum()
Definition: cenum.h:79
omnetpp::cEnum::dup
virtual cEnum * dup() const override
Definition: cenum.h:95
omnetpp::cEnum
Provides string representation for enums.
Definition: cenum.h:32
omnetpp::cOwnedObject
A cObject that keeps track of its owner. It serves as base class for many classes in the OMNeT++ libr...
Definition: cownedobject.h:105