bitrl & cuberl Documentation
Simulation engine for reinforcement learning agents
Loading...
Searching...
No Matches
std_map_utils.h
Go to the documentation of this file.
1
#ifndef STD_MAP_UTILS_H
2
#define STD_MAP_UTILS_H
3
9
10
#include <any>
11
#include <map>
12
#include <stdexcept>
13
#include <unordered_map>
14
15
namespace
bitrl
16
{
17
namespace
utils
18
{
19
24
template
<
typename
OutT>
25
OutT
resolve
(
const
std::string &name,
const
std::map<std::string, std::any> &
input
)
26
{
27
28
auto
itr
=
input
.find(name);
29
30
if
(
itr
==
input
.end())
31
{
32
throw
std::logic_error(
"Property: "
+ name +
" not in input"
);
33
}
34
35
return
std::any_cast<OutT>(
itr
->second);
36
}
37
42
template
<
typename
OutT>
43
OutT
resolve
(
const
std::string &name,
const
std::unordered_map<std::string, std::any> &
input
)
44
{
45
auto
itr
=
input
.find(name);
46
47
if
(
itr
==
input
.end())
48
{
49
throw
std::logic_error(
"Property: "
+ name +
" not in input"
);
50
}
51
52
try
53
{
54
return
std::any_cast<OutT>(
itr
->second);
55
}
56
catch
(
const
std::bad_any_cast &)
57
{
58
throw
std::logic_error(
"Property: "
+ name +
" has unexpected type"
);
59
}
60
}
61
62
}
// namespace utils
63
}
// namespace bitrl
64
65
#endif
bitrl::utils::resolve
OutT resolve(const std::string &name, const std::map< std::string, std::any > &input)
Definition
std_map_utils.h:25
bitrl
Definition
bitrl_consts.h:14
libs
bitrl
src
bitrl
utils
std_map_utils.h
Generated by
1.9.8