37 static auto ToString(
const T& value) -> std::string =
delete;
42 static auto FromString(std::string_view str) -> std::optional<T> =
delete;
50concept Configurable =
requires(
const T& value,
const Value& val, std::string_view str) {
63 if (!value.Fits<
bool>()) {
66 return value.Get<
bool>();
69 static auto ToString(
bool value) -> std::string {
return value ?
"true" :
"false"; }
71 static auto FromString(std::string_view str) -> std::optional<bool>
73 if (str ==
"true" || str ==
"1" || str ==
"yes" || str ==
"on") {
76 if (str ==
"false" || str ==
"0" || str ==
"no" || str ==
"off") {
92 if (!value.Fits<
int>()) {
95 return value.Get<
int>();
98 static auto ToString(
int value) -> std::string {
return std::to_string(value); }
100 static auto FromString(std::string_view str) -> std::optional<int>
104 int result = std::stoi(std::string(str), &pos);
105 if (pos != str.size()) {
122 if (!value.Fits<std::int64_t>()) {
125 return value.Get<std::int64_t>();
128 static auto ToString(std::int64_t value) -> std::string {
return std::to_string(value); }
130 static auto FromString(std::string_view str) -> std::optional<std::int64_t>
134 std::int64_t result = std::stoll(std::string(str), &pos);
135 if (pos != str.size()) {
152 if (!value.Fits<
double>()) {
155 return value.Get<
double>();
158 static auto ToString(
double value) -> std::string {
return std::to_string(value); }
160 static auto FromString(std::string_view str) -> std::optional<double>
164 double result = std::stod(std::string(str), &pos);
165 if (pos != str.size()) {
183 if (!value.Fits<
float>()) {
186 return value.Get<
float>();
189 static auto ToString(
float value) -> std::string {
return std::to_string(value); }
191 static auto FromString(std::string_view str) -> std::optional<float>
195 float result = std::stof(std::string(str), &pos);
196 if (pos != str.size()) {
213 if (!value.Fits<std::string>()) {
216 return value.Get<std::string>();
219 static auto ToString(
const std::string& value) -> std::string {
return value; }
221 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:32
Concept constraining types that can be used as configuration values.
Definition traits.h:50
C++20 compile-time type-safe configuration library.
Definition conf.h:17
static auto Serialize(bool value) -> Value
Definition traits.h:59
static auto Deserialize(const Value &value) -> std::optional< bool >
Definition traits.h:61
static auto FromString(std::string_view str) -> std::optional< bool >
Definition traits.h:71
static auto ToString(bool value) -> std::string
Definition traits.h:69
static auto Deserialize(const Value &value) -> std::optional< double >
Definition traits.h:150
static auto ToString(double value) -> std::string
Definition traits.h:158
static auto FromString(std::string_view str) -> std::optional< double >
Definition traits.h:160
static auto Serialize(double value) -> Value
Definition traits.h:148
static auto ToString(float value) -> std::string
Definition traits.h:189
static auto FromString(std::string_view str) -> std::optional< float >
Definition traits.h:191
static auto Deserialize(const Value &value) -> std::optional< float >
Definition traits.h:180
static auto Serialize(float value) -> Value
Definition traits.h:178
static auto Serialize(int value) -> Value
Definition traits.h:85
static auto FromString(std::string_view str) -> std::optional< int >
Definition traits.h:100
static auto Deserialize(const Value &value) -> std::optional< int >
Definition traits.h:87
static auto ToString(int value) -> std::string
Definition traits.h:98
static auto Deserialize(const Value &value) -> std::optional< std::int64_t >
Definition traits.h:120
static auto ToString(std::int64_t value) -> std::string
Definition traits.h:128
static auto FromString(std::string_view str) -> std::optional< std::int64_t >
Definition traits.h:130
static auto Serialize(std::int64_t value) -> Value
Definition traits.h:118
static auto FromString(std::string_view str) -> std::optional< std::string >
Definition traits.h:221
static auto Deserialize(const Value &value) -> std::optional< std::string >
Definition traits.h:211
static auto ToString(const std::string &value) -> std::string
Definition traits.h:219
static auto Serialize(const std::string &value) -> Value
Definition traits.h:209
Primary template for configuration type traits.
Definition traits.h:23
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.