tue_config
test
test_yaml_and_show.cpp
Go to the documentation of this file.
1
#include <
tue/config/reader.h
>
2
#include <
tue/config/writer.h
>
3
#include <
tue/config/data.h
>
4
5
#include <
tue/config/yaml_emitter.h
>
6
7
#include <
tue/config/binary_writer.h
>
8
#include <
tue/config/binary_reader.h
>
9
10
#include <
tue/config/reader_writer.h
>
11
12
#include <
tue/config/write.h
>
13
#include <
tue/config/read.h
>
14
15
#include "../src/loaders/loader_functions.h"
16
17
#include <
iostream
>
18
#include <
sstream
>
19
#include <
vector
>
20
21
// ----------------------------------------------------------------------------------------------------
22
23
int
main
(
int
argc,
char
**argv)
24
{
25
if
(argc < 2)
26
{
27
std::cout
<<
"Usage: test_yaml_and_show YAML [resolve_env resolve_file resolve_rospkg]"
<<
std::endl
;
28
return
1;
29
}
30
31
std::string
filename = argv[1];
32
tue::config::DataPointer
data;
33
34
tue::config::ResolveConfig
resolve_config;
35
if
(argc >= 5)
36
{
37
bool
parsing_error =
false
;
38
std::vector<bool*>
resolve_config_values = { &resolve_config.
env
, &resolve_config.
file
, &resolve_config.
rospkg
};
39
for
(uint index = 2; index<5; ++index)
40
{
41
std::string
arg(argv[index]);
42
char
* pEnd;
43
int
i =
static_cast<
int
>
(
std::strtol
(arg.
c_str
(), &pEnd, 10));
44
if
(pEnd[0] == 0)
45
{
46
*resolve_config_values[index-2] = i;
47
continue
;
48
}
49
50
bool
b;
51
if
(
tue::config::strToBool
(arg, b))
52
{
53
*resolve_config_values[index-2] = b;
54
continue
;
55
}
56
parsing_error =
true
;
57
std::cerr
<<
"Could not resolve '"
<< arg <<
"' to a boolean"
<<
std::endl
;
58
}
59
if
(parsing_error)
60
return
1;
61
}
62
63
std::cout
<< resolve_config.
env
<<
std::endl
<< resolve_config.
file
<<
std::endl
<< resolve_config.
rospkg
<<
std::endl
;
64
65
try
66
{
67
data =
tue::config::fromFile
(filename, resolve_config);
68
}
69
catch
(
tue::config::ParseException
& e)
70
{
71
std::cout
<<
"Error: "
<< e.
what
() <<
std::endl
;
72
return
0;
73
}
74
tue::config::toStream
(
std::cout
, data,
tue::config::YAML
, 2);
75
76
return
0;
77
}
std::strtol
T strtol(T... args)
sstream
std::string
binary_reader.h
vector
tue::config::DataPointer
Definition:
data_pointer.h:17
tue::config::fromFile
DataPointer fromFile(const std::string &filename, const ResolveConfig &resolve_config=ResolveConfig::defaultConfig())
Definition:
read.cpp:38
tue::config::toStream
void toStream(std::ostream &s, const DataConstPointer &data, WriteType write_type, int indent_size=0)
Definition:
write.cpp:169
tue::config::strToBool
bool strToBool(std::string s, bool &rhs)
strToBool Converts a string to a boolean of matches one of the following: y, n, yes,...
Definition:
loader_functions.cpp:10
std::cerr
tue::config::ParseException
Definition:
read.h:17
tue::config::ResolveConfig::env
bool env
Definition:
resolve_config.h:29
iostream
std::cout
tue::config::YAML
@ YAML
Definition:
write.h:15
std::string::c_str
T c_str(T... args)
reader.h
tue::config::ResolveConfig::rospkg
bool rospkg
Definition:
resolve_config.h:33
tue::config::ResolveConfig::file
bool file
Definition:
resolve_config.h:31
reader_writer.h
std::endl
T endl(T... args)
tue::config::ParseException::what
const char * what() const
Definition:
read.h:25
main
int main(int argc, char **argv)
Definition:
test_yaml_and_show.cpp:23
data.h
tue::config::ResolveConfig
Class to config the resolve behaviour of a loader.
Definition:
resolve_config.h:16
binary_writer.h
write.h
read.h
writer.h
yaml_emitter.h
Generated on Sun Feb 23 2025 04:34:23 for tue_config by
1.8.17