NAME ## Map NAME::_map = NAME ## Map();\
NAME ## Iterator NAME::_iterator = NAME ## Iterator(&NAME::_map);\
\
const NAME* NAME::_default = &NAME::DEFAULT;\
\
NAME::NAME()\
{\
}\
\
NAME::NAME(int value)\
:
AEnum(fromValue(value))\
{\
}\
\
NAME::NAME(
const String& key)\
{\
}\
\
NAME::NAME(
const String& key,
int value,
const String& descr)\
:
AEnum(key, value, descr)\
{\
if (_map.find(value) != _map.end())\
throw("Duplicated item");\
_map[value] = this;\
}\
\
NAME::~NAME()\
{\
}\
\
size_t NAME::getSize()\
{\
return _map.size();\
}\
\
NAME ## Iterator NAME::getIterator()\
{\
auto it(_iterator);\
it.toFront();\
return it;\
}\
\
void NAME::printAll()\
{\
auto it(getIterator());\
while (it.hasNext())\
{\
(*it).printEnum();\
it.toNext();\
}\
}\
auto it(getIterator());\
while (it.hasNext())\
{\
keys.push_back((*it).getKey());\
it.toNext();\
}\
return keys;\
}\
auto it(getIterator());\
while (it.hasNext())\
{\
descr.push_back((*it).getDescr());\
it.toNext();\
}\
return descr;\
}\
\
bool NAME::existsKey(
const String& key)\
{\
auto it = _map.begin();\
while (it != _map.end())\
{\
if (it->second->getKey() == key)\
return true;\
it++;\
}\
return false;\
}\
\
bool NAME::existsValue(int value)\
{\
return (_map.find(value) != _map.end());\
}\
\
const NAME& NAME::fromKey(
const String& key)\
{\
auto it = _map.begin();\
while (it != _map.end())\
{\
if (it->second->getKey() ==
toUpper(key))\
return (*(it->second));\
it++;\
}\
std::cout << "Unknown key " << key << " for enum " << #NAME << std::endl;\
return *_default;\
}\
\
const NAME& NAME::fromValue(int value)\
{\
if (existsValue(value))\
return (*(_map[value]));\
std::cout << "Unknown value " << value << " for enum " << #NAME << std::endl;\
return *_default;\
}\
\
{\
std::vector<NAME> vec;\
for (auto v : keys)\
vec.push_back(fromKey(v));\
return vec;\
}\
\
std::vector<NAME> NAME::fromValues(
const VectorInt& values)\
{\
std::vector<NAME> vec;\
for (auto v : values)\
vec.push_back(fromValue(v));\
return vec;\
}\
\
NAME::E ## NAME NAME::toEnum() const\
{\
return static_cast<E ## NAME>(getValue());\
\
NAME ## Iterator::NAME ## Iterator(NAME ## Map* map) \
: _stditer(map->begin())\
, _refmap(map)\
{\
}\
\
const NAME& NAME ## Iterator::operator*() const\
{\
return (*(_stditer->second));\
}\
\
bool NAME ## Iterator::hasNext() const\
{\
return (_stditer != _refmap->end());\
}\
\
const NAME& NAME ## Iterator::toNext()\
{\
return (*((_stditer++)->second));\
}\
\
const NAME& NAME ## Iterator::toFront()\
{\
_stditer = _refmap->begin();\
return (*(_stditer->second));\
}\
\
const NAME& NAME ## Iterator::getEnum() const\
{\
return (*(_stditer->second));\
}\
\
int NAME ## Iterator::getValue() const\
{\
return (_stditer->second->getValue());\
}\
\
const
String& NAME ## Iterator::getKey() const\
{\
return (_stditer->second->getKey());\
}\
\
const
String& NAME ## Iterator::getDescr() const\
{\
return (_stditer->second->getDescr());\
}\
\
VectorT< String > VectorString
Definition: VectorT.hpp:298
GSTLEARN_EXPORT String toUpper(const String &string)
Definition: String.cpp:51
#define ENUM_IMPLS(NAME,...)
Definition: AEnum.hpp:90
Definition: VectorT.hpp:31
#define EXPAND(x)
Definition: RepeatMacroOrig.hpp:15
std::string String
Definition: geoslib_define.h:18