wren
Vulkan-based game engine
Toggle main menu visibility
Loading...
Searching...
No Matches
enums.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <boost/algorithm/string.hpp>
4
#include <boost/describe.hpp>
5
#include <string>
6
7
#include "
concepts.hpp
"
8
9
namespace
wren::utils
{
10
11
template
<DescribedEnum E>
12
auto
enum_to_string
(E e) -> std::string {
13
std::string r =
"(unamed)"
;
14
boost::mp11::mp_for_each<boost::describe::describe_enumerators<E>>(
15
[&](
auto
d) {
16
if
(e == d.value) r = std::string(d.name);
17
});
18
return
r;
19
}
20
21
template
<DescribedEnum E>
22
auto
string_to_enum
(
const
std::string_view& name,
bool
case_insensitive =
false
)
23
-> std::optional<E> {
24
bool
found =
false
;
25
26
E r = {};
27
28
boost::mp11::mp_for_each<boost::describe::describe_enumerators<E>>(
29
[&](
auto
d) {
30
const
std::string described = d.name;
31
if
(!found) {
32
if
(case_insensitive && boost::iequals(name, described)) {
33
found =
true
;
34
r = d.value;
35
}
else
if
(!case_insensitive && name == described) {
36
found =
true
;
37
r = d.value;
38
}
39
}
40
});
41
42
if
(found) {
43
return
r;
44
}
45
46
return
std::nullopt;
47
}
48
49
}
// namespace wren::utils
concepts.hpp
wren::utils
Definition
binary_reader.hpp:5
wren::utils::string_to_enum
auto string_to_enum(const std::string_view &name, bool case_insensitive=false) -> std::optional< E >
Definition
enums.hpp:22
wren::utils::enum_to_string
auto enum_to_string(E e) -> std::string
Definition
enums.hpp:12
wren_utils
include
wren
utils
enums.hpp
Generated by
1.17.0