OMNeT++ Simulation Library  5.6.1
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 
48  public:
54  explicit cEnum(const char *name=nullptr);
55 
68  cEnum(const char *name, const char *str, ...);
69 
73  cEnum(const cEnum& cenum);
74 
78  virtual ~cEnum();
79 
84  cEnum& operator=(const cEnum& list);
86 
89 
94  virtual cEnum *dup() const override {return new cEnum(*this);}
95 
99  virtual std::string str() const override;
101 
107  void insert(int value, const char *name);
108 
120  void bulkInsert(const char *name1, ...);
121 
126  const char *getStringFor(int value);
127 
132  int lookup(const char *name, int fallback=-1);
133 
137  int resolve(const char *name);
138 
142  std::map<std::string,int> getNameValueMap() const {return nameToValueMap;}
144 
152  static cEnum *find(const char *enumName, const char *contextNamespace=nullptr);
153 
157  static cEnum *get(const char *enumName, const char *contextNamespace=nullptr);
159 
160 };
161 
162 } // namespace omnetpp
163 
164 
165 #endif
166 
virtual cEnum * dup() const override
Definition: cenum.h:94
A cObject that keeps track of its owner. It serves as base class for many classes in the OMNeT++ libr...
Definition: cownedobject.h:104
Provides string representation for enums.
Definition: cenum.h:32
Definition: cabstracthistogram.h:21
std::map< std::string, int > getNameValueMap() const
Definition: cenum.h:142