This commit is contained in:
2025-10-03 12:11:21 +03:00
parent 962504ed98
commit 5fe2788cd7
4 changed files with 93 additions and 6 deletions

View File

@@ -249,6 +249,31 @@ public:
return res;
}
template <typename T>
bool update(std::string_view key, const T& value)
{
auto it = _configDB.find(key);
if (it == _configDB.end()) {
return false;
}
bool ok;
std::visit(
[&value, &ok](auto& val) {
using v_t = std::decay_t<decltype(val)>;
if constexpr (std::convertible_to<T, v_t>) {
val = static_cast<v_t>(value);
ok = true;
} else {
ok = false;
}
},
it->second);
return ok;
}
protected:
std::unordered_map<std::string_view, variant_from_tuple_t<deduce_val_types_t<DESCR_T>>> _configDB;
@@ -453,11 +478,12 @@ class Asibfm700MountConfig : protected ConfigHolder<decltype(Asibfm700MountConfi
using base_t = ConfigHolder<decltype(Asibfm700MountConfigDefaults)>;
public:
using base_t::update;
using base_t::value;
Asibfm700MountConfig() : base_t(Asibfm700MountConfigDefaults)
{
update();
updateAll();
}
~Asibfm700MountConfig() = default;
@@ -481,7 +507,7 @@ public:
ec = base_t::parse(buffer, deserializer);
if (!ec) {
update();
updateAll();
}
} catch (std::ios_base::failure const& ex) {
ec = ex.code();
@@ -497,6 +523,17 @@ public:
return ec;
}
template <typename T>
bool update(std::string_view key, const T& value)
{
bool ok = base_t::update(key, value);
if (ok) {
updateAll();
}
return ok;
}
std::chrono::milliseconds hardwarePollingPeriod{};
mcc::MccAngle siteLatitude{};
@@ -517,7 +554,7 @@ public:
Asibfm700PCM::pcm_data_t pcmData{};
protected:
void update()
void updateAll()
{
hardwarePollingPeriod = std::get<decltype(hardwarePollingPeriod)>(this->_configDB["hardwarePollingPeriod"]);

View File

@@ -62,6 +62,11 @@ int main()
std::cout << "refr w: " << acfg.refractWavelength << "\n";
acfg.update("refractWavelength", 0.3);
auto e = acfg.value<double>("refractWavelength");
std::cout << "refr w: " << e.value_or(0.0) << "\n";
std::cout << "refr w: " << acfg.refractWavelength << "\n";
return 0;
}