TPIK  1.0
Task Priority Inverse Kinematics
Loading...
Searching...
No Matches
ConfHelpers.h
Go to the documentation of this file.
1#include <iostream>
2#include <libconfig.h++>
3
4namespace tpik {
5
6namespace tc
7{
8const char* const none = "\033[0m";
9const char* const redL = "\033[1;31m";
10}
11
17template <typename A>
18bool GetParam(const libconfig::Setting& confObj, A& param, const std::string& name) noexcept(false)
19{
20 if (!confObj.lookupValue(name, param)){
21 std::cerr << tc::redL << "GetParam() Error: <" << name << "> lookup failed." << tc::none << std::endl;
22 return false;
23 }
24
25
26 return true;
27}
28
29template <typename A>
30bool GetParam(const libconfig::Config& confObj, A& param, const std::string& name) noexcept(false)
31{
32 if (!confObj.lookupValue(name, param)){
33 std::cerr << tc::redL << "GetParam() Error: <" << name << "> lookup failed." << tc::none << std::endl;
34 return false;
35 }
36
37 return true;
38}
39
45template <typename A>
46bool GetParamVector(const libconfig::Setting& confObj, A& param, const std::string& name) noexcept(false)
47{
48 try {
49 const libconfig::Setting& settings = confObj.lookup(name);
50 param.resize(settings.getLength());
51 for (int n = 0; n < settings.getLength(); n++) {
52
53 param(n) = settings[n];
54 }
55 } catch (const libconfig::SettingNotFoundException) {
56 std::cerr << tc::redL << "GetParamVector() Error: <" << name << "> lookup failed." << std::endl;
57 return false;
58 }
59
60
61 return true;
62}
63
64template <typename A>
65bool GetParamVector(const libconfig::Config& confObj, A& param, const std::string& name) noexcept(false)
66{
67 try {
68 const libconfig::Setting& settings = confObj.lookup(name);
69 param.resize(settings.getLength());
70 for (int n = 0; n < settings.getLength(); n++) {
71
72 param(n) = settings[n];
73 }
74 } catch (const libconfig::SettingNotFoundException) {
75 std::cerr << tc::redL << "GetParamVector() Error: <" << name << "> lookup failed." << std::endl;
76 return false;
77 }
78
79
80 return true;
81}
82
83}
const char *const redL
Definition ConfHelpers.h:9
const char *const none
Definition ConfHelpers.h:8
Definition Action.h:9
bool GetParam(const libconfig::Setting &confObj, A &param, const std::string &name) noexcept(false)
SetParam functor.
Definition ConfHelpers.h:18
bool GetParamVector(const libconfig::Setting &confObj, A &param, const std::string &name) noexcept(false)
SetParam functor.
Definition ConfHelpers.h:46