NAME ## Map NAME::_map =
NAME ## Map();\
NAME ## Iterator NAME::_iterator =
NAME ## Iterator(&NAME::_map);\
\
const
NAME* NAME::_default = &NAME::DEFAULT;
\
{\
:
AEnum(fromValue(value))\
{\
{\
:
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();\
}\
}\
\
VectorString NAME::getAllKeys()\
{\
VectorString keys;\
auto it(getIterator());\
while (it.hasNext())\
{\
keys.push_back((*it).getKey());\
it.toNext();\
}\
return keys;\
}\
\
VectorString NAME::getAllDescr()\
{\
VectorString descr;\
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());\
}\
\
{\
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());\
\
: _stditer(map->begin())\
, _refmap(map)\
{\
}\
\
const
NAME&
NAME ## Iterator::operator*() const\
{\
return (*(_stditer->second));\
}\
\
bool
NAME ## Iterator::hasNext() const\
{\
return (_stditer != _refmap->end());\
}\
\
{\
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());\
}\
\
{\
return (_stditer->second->getKey());\
}\
\
{\
return (_stditer->second->getDescr());\
}\
\
#define ENUM_IMPLS(NAME,...)
Definition: AEnum.hpp:85
GSTLEARN_EXPORT String toUpper(const String &string)
Definition: String.cpp:48