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