-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathenums.cpp
More file actions
42 lines (36 loc) · 1.26 KB
/
Copy pathenums.cpp
File metadata and controls
42 lines (36 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2019 The MMapper Authors
// Author: Nils Schimmelmann <[email protected]> (Jahara)
#include "enums.h"
#include "../global/enums.h"
#include "mmapper2character.h"
#include <array>
#include <vector>
#define DEFINE_GETTER(E, N, name) \
const MMapper::Array<E, N> &name() \
{ \
static const auto things = ::enums::genEnumValues<E, N>(); \
return things; \
}
#define DEFINE_GETTER_DEFINED(E, N, name) \
const std::vector<E> &name() \
{ \
static const auto things = std::invoke([]() { \
static_assert(std::is_enum_v<E>); \
std::vector<E> result; \
for (const E x : ::enums::genEnumValues<E, N>()) { \
if (x != E::UNDEFINED) { \
result.emplace_back(x); \
} \
} \
return result; \
}); \
return things; \
}
namespace enums {
DEFINE_GETTER_DEFINED(CharacterPositionEnum, NUM_CHARACTER_POSITIONS, getAllCharacterPositions)
DEFINE_GETTER_DEFINED(CharacterTypeEnum, NUM_CHARACTER_TYPES, getAllCharacterTypes)
DEFINE_GETTER(CharacterAffectEnum, NUM_CHARACTER_AFFECTS, getAllCharacterAffects)
} // namespace enums
#undef DEFINE_GETTER
#undef DEFINE_GETTER_DEFINED