76 ConfigValue(
const ConfigValue& other)
81 new (&this->s) std::string(other.s);
95 case Type::StringArray:
96 new (&this->sa) std::vector<std::string>(other.sa);
101 this->type = other.type;
102 this->section = other.section;
103 this->description = other.description;
106 ConfigValue& operator=(
const ConfigValue& other) =
delete;
108 ConfigValue(ConfigValue&& other)
noexcept
113 new (&this->s) std::string(other.s);
114 this->s = std::move(other.s);
128 case Type::StringArray:
129 new (&this->sa) std::vector<std::string>(other.sa);
130 this->sa = std::move(other.sa);
135 this->type = other.type;
136 this->section = other.section;
139 ConfigValue& operator=(ConfigValue&& other)
noexcept
141 if (this->type == Type::String && other.type != Type::String)
143 this->s.~basic_string();
145 else if (this->type == Type::StringArray && other.type != Type::StringArray)
152 if (this->type != Type::String)
154 new (&this->s) std::string(other.s);
156 this->s = std::move(other.s);
170 case Type::StringArray:
171 if (this->type != Type::StringArray)
173 new (&this->sa) std::vector<std::string>(other.sa);
175 this->sa = std::move(other.sa);
180 this->type = other.type;
181 this->section = other.section;
185 virtual ~ConfigValue()
noexcept
187 if (type == Type::String)
189 this->s.~basic_string();
191 else if (type == Type::StringArray)
198 explicit ConfigValue(
const std::string& s)
200 new(&this->s) std::string(s);
204 explicit ConfigValue(
const char* lpsz)
206 new(&this->s) std::string(lpsz ==
nullptr ?
"" : lpsz);
210 explicit ConfigValue(
int i)
216 explicit ConfigValue(
bool b)
228 explicit ConfigValue(
char c)
234 explicit ConfigValue(
const std::vector<std::string>& sa)
236 new(&this->sa) std::vector<std::string>(sa);
237 type = Type::StringArray;
249 return std::to_string(this->i);
251 return this->b ?
"true" :
"false";
255 return std::string(1, this->c);
256 case Type::StringArray:
257 return MiKTeX::Util::StringUtil::Flatten(this->sa, MiKTeX::Util::PathNameUtil::PathNameDelimiter);
259 throw ConfigurationError(
"no conversion from undefined configuration value to string.");
261 throw ConfigurationError(
"no conversion to string from type: " + std::to_string(
static_cast<int>(this->type)));
272 return std::stoi(this->s);
282 throw ConfigurationError(
"no conversion from undefined configuration value to integer.");
284 throw ConfigurationError(
"no conversion to integer from type: " + std::to_string(
static_cast<int>(this->type)));
296 || this->s ==
"disable"
299 || this->s ==
"false"
305 else if (this->s ==
"1"
306 || this->s ==
"enable"
324 else if (this->i == 1)
330 throw ConfigurationError(
"cannot convert to boolean from int: " + std::to_string(this->i));
345 throw ConfigurationError(
"cannot convert to boolean from tri-state: " + std::to_string(
static_cast<int>(this->t)));
354 else if (this->c ==
'1'
362 throw ConfigurationError(
"cannot convert to boolean from char: " + std::string(1, this->c));
365 throw ConfigurationError(
"no conversion from undefined configuration value to boolean.");
367 throw ConfigurationError(
"no conversion to boolean from type: " + std::to_string(
static_cast<int>(this->type)));
379 || this->s ==
"disable"
382 || this->s ==
"false"
388 else if (this->s ==
"1"
389 || this->s ==
"enable"
398 else if (this->s ==
""
401 || this->s ==
"undetermined")
414 else if (this->i == 1)
418 else if (this->i == 2)
424 throw ConfigurationError(
"cannot convert to tri-state from int: " + std::to_string(this->i));
437 else if (this->c ==
'1'
443 else if (this->c ==
'2'
450 throw ConfigurationError(
"cannot convert to tri-state from char: " + std::string(1, this->c));
453 throw ConfigurationError(
"no conversion from undefined configuration value to tri-state.");
455 throw ConfigurationError(
"no conversion to tri-state from type: " + std::to_string(
static_cast<int>(this->type)));
466 if (this->s.length() != 1)
472 if (this->i < CHAR_MIN || this->i > CHAR_MAX)
474 throw ConfigurationError(
"cannot convert to char from int: " + std::to_string(this->i));
476 return (
char)this->i;
478 return this->b ?
't' :
'f';
484 throw ConfigurationError(
"no conversion from undefined configuration value to char.");
486 throw ConfigurationError(
"no conversion from type to char from type: " + std::to_string(
static_cast<int>(this->type)));
497 return std::stoll(this->s);
499 return (std::time_t)this->i;
501 throw ConfigurationError(
"no conversion from undefined configuration value to time_t.");
503 throw ConfigurationError(
"no conversion from time_t from type: " + std::to_string(
static_cast<int>(this->type)));
514 return MiKTeX::Util::StringUtil::Split(this->s, MiKTeX::Util::PathNameUtil::PathNameDelimiter);
515 case Type::StringArray:
518 throw ConfigurationError(
"no conversion from undefined configuration value to string array.");
520 throw ConfigurationError(
"no conversion from to string array from type: " + std::to_string(
static_cast<int>(this->type)));
536 Type type = Type::None;
540 Type GetType()
const;
546 return type != Type::None;
551 std::string GetSection()
const;
555 std::string GetDescription()
const;
564 std::vector<std::string> sa;
568 std::string description;