Robot Raconteur Companion C++ Library
Toggle main menu visibility
Loading...
Searching...
No Matches
include
RobotRaconteurCompanion
InfoParser
yaml
yaml_loader_enums.h
1
#pragma once
2
#include <string>
3
#include "yaml-cpp/yaml.h"
4
#include <
RobotRaconteurCompanion/StdRobDef/StdRobDefAll.h
>
5
#include "yaml_loader_enums_impl.h"
6
7
namespace
RobotRaconteur
8
{
9
namespace
Companion
10
{
11
namespace
InfoParser
12
{
13
namespace
yaml
14
{
15
16
template
<
typename
T>
17
T parse_enum(
const
YAML::Node& node,
const
std::string& key,
bool
optional)
18
{
19
if
(node[key])
20
{
21
return
string_to_enum_traits<T>::string_to_enum(node[key].as<std::string>(), node[key]);
22
}
23
else
24
{
25
if
(optional)
26
{
27
return
T();
28
}
29
else
30
{
31
throw
RobotRaconteur::InvalidArgumentException(
"Key not found: "
+ key);
32
}
33
}
34
}
35
36
template
<
typename
T>
37
RobotRaconteur::RRListPtr<RRArray<int32_t> > parse_enum_list(
const
YAML::Node& node,
const
std::string& key,
38
bool
optional)
39
{
40
if
(node[key])
41
{
42
auto
ret = RobotRaconteur::AllocateEmptyRRList<RRArray<int32_t> >();
43
std::vector<std::string> vals = node[key].as<std::vector<std::string> >();
44
for
(
const
auto
& v : vals)
45
{
46
ret->push_back(
47
RobotRaconteur::ScalarToRRArray((int32_t)string_to_enum_traits<T>::string_to_enum(v, node[key])));
48
}
49
return
ret;
50
}
51
else
52
{
53
if
(optional)
54
{
55
return
RobotRaconteur::AllocateEmptyRRList<RRArray<int32_t> >();
56
}
57
else
58
{
59
throw
RobotRaconteur::InvalidArgumentException(
"Key not found: "
+ key);
60
}
61
}
62
}
63
64
template
<
typename
T>
65
uint32_t parse_enum_flags(
const
YAML::Node& node,
const
std::string& key,
bool
optional)
66
{
67
if
(node[key])
68
{
69
uint32_t ret = 0;
70
std::vector<std::string> vals = node[key].as<std::vector<std::string> >();
71
for
(
const
auto
& v : vals)
72
{
73
ret |= ((int32_t)string_to_enum_traits<T>::string_to_enum(v, node[key]));
74
}
75
return
ret;
76
}
77
else
78
{
79
if
(optional)
80
{
81
return
0;
82
}
83
else
84
{
85
throw
RobotRaconteur::InvalidArgumentException(
"Key not found: "
+ key);
86
}
87
}
88
}
89
90
}
// namespace yaml
91
}
// namespace InfoParser
92
}
// namespace Companion
93
}
// namespace RobotRaconteur
StdRobDefAll.h
Generated by
1.17.0