16 #ifndef __OMNETPP_CENUM_H
17 #define __OMNETPP_CENUM_H
19 #include <initializer_list>
20 #include "cownedobject.h"
36 std::map<intval_t,std::string> valueToNameMap;
37 std::map<std::string,intval_t> nameToValueMap;
38 std::vector<std::string> tmpNames;
41 void copy(
const cEnum& other);
45 cEnum *registerNames(
const char *nameList);
48 cEnum *registerValues(
const std::initializer_list<T>& values) {
50 for (T value : values)
51 insert((
intval_t)value, tmpNames[i++].c_str());
57 void addPairs(
const std::initializer_list<std::pair<const char*,T>> pairList) {
58 for (
const auto& pair : pairList)
59 insert((
intval_t)pair.second, pair.first);
64 [[deprecated(
"Use Register_Enum_Custom() macro instead of Register_Enum2()")]]
65 void bulkInsert(
const char *name1, ...);
73 explicit cEnum(
const char *name=
nullptr);
104 virtual std::string str()
const override;
112 void insert(
intval_t value,
const char *name);
118 const char *getStringFor(
intval_t value);
134 const std::map<std::string,intval_t>&
getNameValueMap()
const {
return nameToValueMap;}
144 static cEnum *find(
const char *enumName,
const char *contextNamespace=
nullptr);
149 static cEnum *get(
const char *enumName,
const char *contextNamespace=
nullptr);