...
This commit is contained in:
54
mcc/tests/cfg_test.cpp
Normal file
54
mcc/tests/cfg_test.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "../../asibfm700/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";
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user