-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathmain.cpp
41 lines (33 loc) · 993 Bytes
/
main.cpp
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
#include <UDRefl/UDRefl.hpp>
#include <iostream>
using namespace Ubpa;
using namespace Ubpa::UDRefl;
enum class Color {
Red,
Green,
Blue
};
int main() {
Mngr.RegisterType<Color>();
Mngr.AddField<Color::Red>("Red");
Mngr.AddField<Color::Green>("Green");
Mngr.AddField<Color::Blue>("Blue");
for (auto&& [name, color] : VarRange_of<Color>)
std::cout << name.GetView() << ": " << static_cast<int>(color.As<const Color>()) << std::endl;
// enumerator -> name
Color c = Color::Red;
for (auto&& [color_name, color] : VarRange_of<Color, FieldFlag::Unowned>) {
if (color == c) {
std::cout << "name of " << static_cast<int>(c) << " : " << color_name.GetView() << std::endl;
break;
}
}
// name -> enumerator
std::string_view name = "Green";
for (auto&& [color_name, color] : VarRange_of<Color, FieldFlag::Unowned>) {
if (color_name.Is(name)) {
std::cout << "value of " << name << " : " << static_cast<int>(color.As<const Color>()) << std::endl;
break;
}
}
}