using structs to define type conversions

pull/2673/head
Bailey Chittle 3 years ago
parent 037f083cbe
commit 94551310b3

@ -11,100 +11,60 @@ namespace details {
// template<typename T>
// concept composable = std::same_as<T, bool> || std::integral<T> || std::floating_point<T> || std::convertible_to<T, std::string_view>;
struct attr
struct Key
{
std::string key;
std::string value;
std::string _key;
public:
// string overloads
attr(string_view_t k, string_view_t v)
{
scramble(key, k);
scramble(value, v);
Key(string_view_t k) {
scramble(_key, k);
}
Key(std::string&& k) {
scramble(_key, k);
}
Key(const char* k) {
scramble(_key, k);
}
};
// does not convert to string_view when using initializer list constructors...
// so we have an overload for raw c-strings
attr(const char* k, const char* v)
: attr{string_view_t{k}, string_view_t{v}}
{}
attr(std::string const& k, std::string const& v)
: attr{string_view_t{k}, string_view_t{v}}
{}
attr(std::string&& k, std::string&& v)
: attr{string_view_t{k}, string_view_t{v}}
{}
struct Value
{
std::string _value;
// integer overloads
attr(string_view_t k, long v)
: value{std::to_string(v)}
{
scramble(key, k);
Value(string_view_t v) {
scramble(_value, v);
}
attr(string_view_t k, long long v)
: value{std::to_string(v)}
{
scramble(key, k);
Value(std::string&& v) {
scramble(_value, v);
}
attr(string_view_t k, unsigned long v)
: value{std::to_string(v)}
{
scramble(key, k);
Value(const char* v) {
scramble(_value, v);
}
attr(string_view_t k, unsigned long long v)
: value{std::to_string(v)}
{
scramble(key, k);
Value(long v) {
_value = std::to_string(v);
}
attr(string_view_t k, bool v)
: value{v ? "true" : "false"}
{
scramble(key, k);
Value(long long v) {
_value = std::to_string(v);
}
attr(std::string const& k, long v)
: attr{string_view_t{k}, v}
{}
attr(std::string const& k, long long v)
: attr{string_view_t{k}, v}
{}
attr(std::string const& k, unsigned long v)
: attr{string_view_t{k}, v}
{}
attr(std::string const& k, unsigned long long v)
: attr{string_view_t{k}, v}
{}
attr(std::string const& k, bool v)
: attr{string_view_t{k}, v}
{}
attr(std::string&& k, long v)
: attr{string_view_t{k}, v}
{}
attr(std::string&& k, long long v)
: attr{string_view_t{k}, v}
{}
attr(std::string&& k, unsigned long v)
: attr{string_view_t{k}, v}
{}
Value(unsigned long v) {
_value = std::to_string(v);
}
Value(unsigned long long v) {
_value = std::to_string(v);
}
Value(bool v) {
_value = v ? "true" : "false";
}
};
attr(std::string&& k, unsigned long long v)
: attr{string_view_t{k}, v}
{}
struct attr
{
std::string key;
std::string value;
attr(std::string&& k, bool v)
: attr{string_view_t{k}, v}
{}
public:
attr(Key&& k, Value&& v) : key(std::move(k._key)), value(std::move(v._value)) {}
attr(Key const& k, Value const& v) : key(k._key), value(v._value) {}
};
} // namespace details

Loading…
Cancel
Save