From 8e5e3631ba6d48e1069a1ea518e81437d4818f39 Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Fri, 22 May 2026 09:28:25 +0300 Subject: [PATCH] fixes --- include/mcc/mcc_keyvalue.h | 45 ++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/include/mcc/mcc_keyvalue.h b/include/mcc/mcc_keyvalue.h index 6841048..d6be799 100644 --- a/include/mcc/mcc_keyvalue.h +++ b/include/mcc/mcc_keyvalue.h @@ -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(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 -concept mcc_variant_valid_type_c = requires { !std::is_array_v && !std::is_void_v && !std::is_reference_v; }; +concept mcc_record_value_c = requires { !std::is_array_v && !std::is_void_v && !std::is_reference_v; }; template concept mcc_keyvalue_record_c = requires(T t) { requires std::same_as; // key name is immutable!!! - requires mcc_variant_valid_type_c; // value is mutable - requires mcc_variant_valid_type_c; // default value is mutable + requires mcc_record_value_c; // value is mutable + requires mcc_record_value_c; // default value is mutable requires mcc_serialization_params_c; // serialization parameters }; @@ -152,7 +152,7 @@ public: } - std::array keys() const + constexpr std::array keys() const { return [this](std::index_sequence) { return std::array{std::get(_keyValue).key...}; @@ -200,28 +200,32 @@ public: template std::error_code setValue(R const& key, const T& value) { - return setValue(std::string_view{key}, value); + return setValue(std::string_view{key}, value); } template 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) { + if constexpr (std::assignable_from) { rec.value = value; } else if constexpr (std::constructible_from) { rec.value = VT(value); - } else if constexpr (std::assignable_from) { - rec.value = value; } else { return MccKeyValueHolderErrorCode::ERROR_INCOMPATIBLE_TYPE; } return MccKeyValueHolderErrorCode::ERROR_OK; }); + + if (!ec) { + _changedKey.insert(hash); + } + + return ec; } template (_keyValue).key; using val_t = std::remove_cvref_t(_keyValue).value)>; - val_t& val_ptr = std::get(_keyValue).value; - if (is_default) { - val_ptr = std::get(_keyValue).default_value; - } + const val_t& val = is_default ? std::get(_keyValue).default_value : std::get(_keyValue).value; std::string buff; // auto err = MccSerializer{}(buff, std::get(_keyValue).value, // std::get(_keyValue).serial_pars); - auto err = MccSerializer{}(buff, val_ptr, std::get(_keyValue).serial_pars); + auto err = MccSerializer{}(buff, val, std::get(_keyValue).serial_pars); if (err) { return MccKeyValueHolderErrorCode::ERROR_SERIAL; } else { @@ -480,14 +483,14 @@ protected: } }; -template +template struct mcc_simple_kv_record_t { const std::string_view key; T value, default_value; mcc_serialization_params_t serial_pars; }; -template +template static mcc_simple_kv_record_t mcc_make_simple_kv_record( std::string_view key, T const& def_value,