-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconfig_value.cpp
More file actions
56 lines (50 loc) · 1.64 KB
/
Copy pathconfig_value.cpp
File metadata and controls
56 lines (50 loc) · 1.64 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "config/config_value.h"
#include <fmt/ranges.h>
#include <boost/functional/hash.hpp>
#include <boost/lexical_cast.hpp>
#include "config/config_exception.h"
#include "config/source/yaml_file.h"
#include "silo/common/panic.h"
namespace silo::config {
ConfigValueType ConfigValue::getValueType() const {
if (std::holds_alternative<std::string>(value)) {
return ConfigValueType::STRING;
}
if (std::holds_alternative<std::filesystem::path>(value)) {
return ConfigValueType::PATH;
}
if (std::holds_alternative<int32_t>(value)) {
return ConfigValueType::INT32;
}
if (std::holds_alternative<uint32_t>(value)) {
return ConfigValueType::UINT32;
}
if (std::holds_alternative<uint16_t>(value)) {
return ConfigValueType::UINT16;
}
if (std::holds_alternative<bool>(value)) {
return ConfigValueType::BOOL;
}
if (std::holds_alternative<std::vector<std::string>>(value)) {
return ConfigValueType::LIST;
}
SILO_UNREACHABLE();
}
std::string ConfigValue::toString() const {
return std::visit(
[](const auto& value) -> std::string {
using T = std::decay_t<decltype(value)>;
if constexpr (std::is_same_v<T, std::string>) {
return fmt::format("'{}'", value);
} else if constexpr (std::is_same_v<T, std::filesystem::path>) {
return fmt::format("'{}'", value.string());
} else if constexpr (std::is_same_v<T, std::vector<std::string>>) {
return fmt::format("{}", fmt::join(value, ","));
} else {
return fmt::format("{}", value);
}
},
value
);
}
} // namespace silo::config