fixes
This commit is contained in:
@@ -49,12 +49,12 @@ namespace mcc::impl
|
||||
struct MccKeyValueHolderCategory : public std::error_category {
|
||||
MccKeyValueHolderCategory() : std::error_category() {}
|
||||
|
||||
const char* name() const noexcept
|
||||
const char* name() const noexcept override
|
||||
{
|
||||
return "MCC-KEYVALUEHOLDER-ERR-CATEGORY";
|
||||
}
|
||||
|
||||
std::string message(int ec) const
|
||||
std::string message(int ec) const override
|
||||
{
|
||||
MccKeyValueHolderErrorCode err = static_cast<MccKeyValueHolderErrorCode>(ec);
|
||||
|
||||
@@ -90,14 +90,14 @@ inline std::error_code make_error_code(MccKeyValueHolderErrorCode ec)
|
||||
|
||||
// to follow std::variant requirements (not references, not array, not void)
|
||||
template <typename T>
|
||||
concept mcc_variant_valid_type_c = requires { !std::is_array_v<T> && !std::is_void_v<T> && !std::is_reference_v<T>; };
|
||||
concept mcc_record_value_c = requires { !std::is_array_v<T> && !std::is_void_v<T> && !std::is_reference_v<T>; };
|
||||
|
||||
|
||||
template <typename T>
|
||||
concept mcc_keyvalue_record_c = requires(T t) {
|
||||
requires std::same_as<decltype(t.key), const std::string_view>; // key name is immutable!!!
|
||||
requires mcc_variant_valid_type_c<decltype(t.value)>; // value is mutable
|
||||
requires mcc_variant_valid_type_c<decltype(t.default_value)>; // default value is mutable
|
||||
requires mcc_record_value_c<decltype(t.value)>; // value is mutable
|
||||
requires mcc_record_value_c<decltype(t.default_value)>; // default value is mutable
|
||||
requires mcc_serialization_params_c<decltype(t.serial_pars)>; // serialization parameters
|
||||
};
|
||||
|
||||
@@ -152,7 +152,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
std::array<std::string_view, NUMBER_OF_RECORDS> keys() const
|
||||
constexpr std::array<std::string_view, NUMBER_OF_RECORDS> keys() const
|
||||
{
|
||||
return [this]<size_t... Is>(std::index_sequence<Is...>) {
|
||||
return std::array<std::string_view, NUMBER_OF_RECORDS>{std::get<Is>(_keyValue).key...};
|
||||
@@ -200,28 +200,32 @@ public:
|
||||
template <std::ranges::contiguous_range R, typename T>
|
||||
std::error_code setValue(R const& key, const T& value)
|
||||
{
|
||||
return setValue<T>(std::string_view{key}, value);
|
||||
return setValue(std::string_view{key}, value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::error_code setValue(std::string_view key, const T& value)
|
||||
{
|
||||
return forKey(key, [&value](auto& rec) -> std::error_code {
|
||||
const size_t hash = utils::FNV1aHash(key);
|
||||
|
||||
auto ec = forHash(hash, [&value](auto& rec) -> std::error_code {
|
||||
using VT = decltype(rec.value);
|
||||
if constexpr (requires(VT v) { v = value; }) {
|
||||
rec.value = value;
|
||||
} else if constexpr (std::convertible_to<T, VT>) {
|
||||
if constexpr (std::assignable_from<VT&, T>) {
|
||||
rec.value = value;
|
||||
} else if constexpr (std::constructible_from<VT, T>) {
|
||||
rec.value = VT(value);
|
||||
} else if constexpr (std::assignable_from<VT, T>) {
|
||||
rec.value = value;
|
||||
} else {
|
||||
return MccKeyValueHolderErrorCode::ERROR_INCOMPATIBLE_TYPE;
|
||||
}
|
||||
|
||||
return MccKeyValueHolderErrorCode::ERROR_OK;
|
||||
});
|
||||
|
||||
if (!ec) {
|
||||
_changedKey.insert(hash);
|
||||
}
|
||||
|
||||
return ec;
|
||||
}
|
||||
|
||||
template <traits::mcc_input_char_range R,
|
||||
@@ -262,6 +266,8 @@ public:
|
||||
for (auto const& el : recs) {
|
||||
rec = mcc::utils::trimSpaces(el, utils::TrimType::TRIM_LEFT);
|
||||
|
||||
inline_comm = {};
|
||||
|
||||
if (rec.size()) {
|
||||
auto found = std::ranges::search(rec, COMMENT_SEQ);
|
||||
if (found.begin() != rec.end()) { // there was the comment sequence in record
|
||||
@@ -290,7 +296,7 @@ public:
|
||||
return MccKeyValueHolderErrorCode::ERROR_DESERIAL;
|
||||
}
|
||||
|
||||
// _changedKey.insert(key_hash);
|
||||
_changedKey.insert(key_hash);
|
||||
|
||||
return MccKeyValueHolderErrorCode::ERROR_OK;
|
||||
});
|
||||
@@ -440,15 +446,12 @@ protected:
|
||||
auto key = std::get<I>(_keyValue).key;
|
||||
using val_t = std::remove_cvref_t<decltype(std::get<I>(_keyValue).value)>;
|
||||
|
||||
val_t& val_ptr = std::get<I>(_keyValue).value;
|
||||
if (is_default) {
|
||||
val_ptr = std::get<I>(_keyValue).default_value;
|
||||
}
|
||||
const val_t& val = is_default ? std::get<I>(_keyValue).default_value : std::get<I>(_keyValue).value;
|
||||
|
||||
std::string buff;
|
||||
// auto err = MccSerializer<val_t>{}(buff, std::get<I>(_keyValue).value,
|
||||
// std::get<I>(_keyValue).serial_pars);
|
||||
auto err = MccSerializer<val_t>{}(buff, val_ptr, std::get<I>(_keyValue).serial_pars);
|
||||
auto err = MccSerializer<val_t>{}(buff, val, std::get<I>(_keyValue).serial_pars);
|
||||
if (err) {
|
||||
return MccKeyValueHolderErrorCode::ERROR_SERIAL;
|
||||
} else {
|
||||
@@ -480,14 +483,14 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
template <mcc_variant_valid_type_c T>
|
||||
template <mcc_record_value_c T>
|
||||
struct mcc_simple_kv_record_t {
|
||||
const std::string_view key;
|
||||
T value, default_value;
|
||||
mcc_serialization_params_t serial_pars;
|
||||
};
|
||||
|
||||
template <mcc_variant_valid_type_c T>
|
||||
template <mcc_record_value_c T>
|
||||
static mcc_simple_kv_record_t<T> mcc_make_simple_kv_record(
|
||||
std::string_view key,
|
||||
T const& def_value,
|
||||
|
||||
Reference in New Issue
Block a user