Timur A. Fatkhullin 3d769d79eb ...
2025-10-01 06:26:50 +03:00

68 lines
1.5 KiB
C++

#include <iostream>
#include "../asibfm700_configfile.h"
template <typename VT>
struct rec_t {
std::string_view key;
VT value;
};
static std::string_view cfg_str = R"--(A = 11
B=3.3
# this is comment
C = WWWWWeeeWWWW
E = 10,20, 40, 32
)--";
int main()
{
auto desc = std::make_tuple(rec_t{"A", 1}, rec_t{"B", 2.2}, rec_t{"C", std::string("EEE")}, rec_t{"D", 3.3},
rec_t{"E", std::vector<int>{1, 2, 3}});
asibfm700::ConfigHolder ch(desc);
// auto err = ch.parse(cfg_str, [](auto s, auto &v) {
// if constexpr (std::is_arithmetic_v<std::decay_t<decltype(v)>>) {
// v = 77;
// } else {
// v = std::string{s.begin(), s.end()};
// }
// return true;
// });
auto err = ch.parse(cfg_str);
auto v = ch.value<float>("A");
std::cout << v.value() << "\n";
// auto v2 = ch.value<std::string>("D");
auto v2 = ch.value<std::string>("C");
std::cout << v2.value_or("<no value>") << "\n";
auto v3 = ch.value<std::vector<int>>("E");
std::cout << "[";
for (auto& el : v3.value_or({0, 0, 0})) {
std::cout << el << " ";
}
std::cout << "]\n";
std::ofstream fst("/tmp/cfg.cfg");
fst << asibfm700::Asibfm700MountConfigString;
fst.close();
asibfm700::Asibfm700MountConfig acfg;
auto ec = acfg.load("/tmp/cfg.cfg");
std::cout << "EC (load) = " << ec.message() << "\n";
std::cout << "refr w: " << acfg.refractWavelength << "\n";
return 0;
}