35 static auto ToString(
const T& value) -> std::string =
delete;
40 static auto FromString(std::string_view str) -> std::optional<T> =
delete;
48concept Configurable =
requires(
const T& value,
const Value& val, std::string_view str) {
61 if (!value.IsBoolean()) {
64 return value.Get<
bool>();
67 static auto ToString(
bool value) -> std::string {
return value ?
"true" :
"false"; }
69 static auto FromString(std::string_view str) -> std::optional<bool>
71 if (str ==
"true" || str ==
"1" || str ==
"yes" || str ==
"on") {
74 if (str ==
"false" || str ==
"0" || str ==
"no" || str ==
"off") {
87 if (!value.IsInteger()) {
90 return value.Get<
int>();
93 static auto ToString(
int value) -> std::string {
return std::to_string(value); }
95 static auto FromString(std::string_view str) -> std::optional<int>
99 int result = std::stoi(std::string(str), &pos);
100 if (pos != str.size()) {
117 if (!value.IsInteger()) {
120 return value.Get<std::int64_t>();
123 static auto ToString(std::int64_t value) -> std::string {
return std::to_string(value); }
125 static auto FromString(std::string_view str) -> std::optional<std::int64_t>
129 std::int64_t result = std::stoll(std::string(str), &pos);
130 if (pos != str.size()) {
147 if (!value.IsNumber()) {
150 return value.Get<
double>();
153 static auto ToString(
double value) -> std::string {
return std::to_string(value); }
155 static auto FromString(std::string_view str) -> std::optional<double>
159 double result = std::stod(std::string(str), &pos);
160 if (pos != str.size()) {
177 if (!value.IsNumber()) {
180 return value.Get<
float>();
183 static auto ToString(
float value) -> std::string {
return std::to_string(value); }
185 static auto FromString(std::string_view str) -> std::optional<float>
189 float result = std::stof(std::string(str), &pos);
190 if (pos != str.size()) {
207 if (!value.IsString()) {
210 return value.Get<std::string>();
213 static auto ToString(
const std::string& value) -> std::string {
return value; }
215 static auto FromString(std::string_view str) -> std::optional<std::string> {
return std::string(str); }
A self-contained, recursive value type for configuration data.
Definition value.h:26
Concept constraining types that can be used as configuration values.
Definition traits.h:48
C++20 compile-time type-safe configuration library.
Definition conf.h:13
static auto Serialize(bool value) -> Value
Definition traits.h:57
static auto Deserialize(const Value &value) -> std::optional< bool >
Definition traits.h:59
static auto FromString(std::string_view str) -> std::optional< bool >
Definition traits.h:69
static auto ToString(bool value) -> std::string
Definition traits.h:67
static auto Deserialize(const Value &value) -> std::optional< double >
Definition traits.h:145
static auto ToString(double value) -> std::string
Definition traits.h:153
static auto FromString(std::string_view str) -> std::optional< double >
Definition traits.h:155
static auto Serialize(double value) -> Value
Definition traits.h:143
static auto ToString(float value) -> std::string
Definition traits.h:183
static auto FromString(std::string_view str) -> std::optional< float >
Definition traits.h:185
static auto Deserialize(const Value &value) -> std::optional< float >
Definition traits.h:175
static auto Serialize(float value) -> Value
Definition traits.h:173
static auto Serialize(int value) -> Value
Definition traits.h:83
static auto FromString(std::string_view str) -> std::optional< int >
Definition traits.h:95
static auto Deserialize(const Value &value) -> std::optional< int >
Definition traits.h:85
static auto ToString(int value) -> std::string
Definition traits.h:93
static auto Deserialize(const Value &value) -> std::optional< std::int64_t >
Definition traits.h:115
static auto ToString(std::int64_t value) -> std::string
Definition traits.h:123
static auto FromString(std::string_view str) -> std::optional< std::int64_t >
Definition traits.h:125
static auto Serialize(std::int64_t value) -> Value
Definition traits.h:113
static auto FromString(std::string_view str) -> std::optional< std::string >
Definition traits.h:215
static auto Deserialize(const Value &value) -> std::optional< std::string >
Definition traits.h:205
static auto ToString(const std::string &value) -> std::string
Definition traits.h:213
static auto Serialize(const std::string &value) -> Value
Definition traits.h:203
Primary template for configuration type traits.
Definition traits.h:21
static auto Deserialize(const Value &value) -> std::optional< T >=delete
Deserializes a value from a Value node.
static auto ToString(const T &value) -> std::string=delete
Converts a value to a human-readable string.
static auto FromString(std::string_view str) -> std::optional< T >=delete
Parses a value from a string (e.g., from environment variables).
static auto Serialize(const T &value) -> Value=delete
Serializes a value to a Value node.