29 template <
typename TEnum>
53 template <
typename TEnum>
55 EnumMap& instance = getInstance();
58 for (
auto value : input) {
61 const EnumIndex index = std::type_index(
typeid(TEnum));
62 instance.records.insert(index, std::move(map));
66 template <
typename TEnum>
67 static std::string
toString(
const TEnum value) {
68 return toString(
int(value), std::type_index(
typeid(TEnum)));
72 EnumMap& instance = getInstance();
81 for (
int i = 1; i <= value; i *= 2) {
82 if ((value & i) == 0) {
87 if (!result.empty()) {
90 result += pair->
value;
100 template <
typename TEnum>
103 return optionalCast<TEnum>(
id);
107 EnumMap& instance = getInstance();
110 for (
auto pair : record.
value()) {
111 if (pair.value.value == value) {
118 template <
typename TEnum>
120 return getDesc(std::type_index(
typeid(TEnum)));
124 EnumMap& instance = getInstance();
129 for (
auto pair : record.
value()) {
133 desc +=
" - " + pair.value.value +
": " + pair.value.desc;
139 template <
typename TEnum>
141 EnumMap& instance = getInstance();
142 const EnumIndex index = std::type_index(
typeid(TEnum));
147 for (
auto pair : record.
value()) {
148 enums.
push(TEnum(pair.key));
155 EnumMap& instance = getInstance();
160 for (
auto pair : record.
value()) {
161 enums.
push(pair.key);
167 static EnumMap& getInstance() {
174 template <
typename TEnum>
#define SPH_ASSERT(x,...)
Key-value associative container implemented as a sorted array.
uint32_t Size
Integral type used to index arrays (by default).
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
const NothingType NOTHING
Generic dynamically allocated resizable storage.
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
static Array< TEnum > getAll()
static std::string toString(const int value, const EnumIndex &index)
static Optional< TEnum > fromString(const std::string &value)
static std::string toString(const TEnum value)
static std::string getDesc()
static std::string getDesc(const EnumIndex &index)
static Optional< int > fromString(const std::string &value, const EnumIndex &index)
static EnumMap & addEnum(Array< EnumInputValue< TEnum >> &&input)
static Array< int > getAll(const EnumIndex &index)
Container of key-value pairs.
INLINE TValue & insert(const TKey &key, const TValue &value)
Adds a new element into the map or sets new value of element with the same key.
INLINE Type & value()
Returns the reference to the stored value.
std::string desc
Description.
std::string value
Text of the value.
Helper class for adding individual enums to the enum map.
RegisterEnum(Array< EnumInputValue< TEnum >> &&input)