Util.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package robdekon
17 * @author Christoph Pohl ( christoph dot pohl at kit dot edu )
18 * @date 07.09.22
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25#include <memory>
26#include <numeric>
27
29
30#include <cxxabi.h>
31
33{
34
35 inline std::string
36 pathToName(const std::shared_ptr<data::Variant>& v)
37 {
38 auto vector = v->getPath().getPath();
39 auto path = v->getPath();
40 path.setDelimeter(".");
41 path.setRootIdentifier("");
42 auto string = path.toString();
43 return string.substr(1, string.size());
44 }
45
46 template <typename DataInputT, typename TypeInputT>
47 std::map<std::string,
48 std::pair<typename std::remove_const<DataInputT>::type,
49 typename std::remove_const<TypeInputT>::type>>
50 getObjectElements(DataInputT& o, TypeInputT& t)
51 {
52 std::map<std::string, std::pair<data::VariantPtr, type::VariantPtr>> ret;
55
57
58 if (x)
59 {
60 for (const auto& [key, e] : x->getElements())
61 {
62 auto ct = y->getMemberType(key);
63 ret.insert({key, {e, ct}});
64 }
65 }
66 return ret;
67 }
68
69 template <typename DataInputT, typename TypeInputT>
70 std::map<std::string,
71 std::pair<typename std::remove_const<DataInputT>::type,
72 typename std::remove_const<TypeInputT>::type>>
73 getDictElements(DataInputT& o, TypeInputT& t)
74 {
75 std::map<std::string,
76 std::pair<typename std::remove_const<DataInputT>::type,
77 typename std::remove_const<TypeInputT>::type>>
78 ret;
81
82 auto ac = y ? y->getAcceptedType() : nullptr;
83
84 if (x)
85 {
86 for (const auto& [key, e] : x->getElements())
87 {
88 ret.insert({key, {e, ac}});
89 }
90 }
91 return ret;
92 }
93
94 template <typename DataInputT, typename TypeInputT>
95 std::vector<std::pair<typename std::remove_const<DataInputT>::type,
96 typename std::remove_const<TypeInputT>::type>>
97 getListElements(DataInputT& o, TypeInputT& t)
98 {
99 std::vector<std::pair<typename std::remove_const<DataInputT>::type,
100 typename std::remove_const<TypeInputT>::type>>
101 ret;
104
105 auto ac = y ? y->getAcceptedType() : nullptr;
106
107 if (x)
108 {
109 for (const auto& e : x->getElements())
110 {
111 ret.emplace_back(e, ac);
112 }
113 }
114 return ret;
115 }
116
117 template <typename DataInputT, typename TypeInputT>
118 std::pair<std::pair<typename std::remove_const<DataInputT>::type,
119 typename std::remove_const<TypeInputT>::type>,
120 std::pair<typename std::remove_const<DataInputT>::type,
121 typename std::remove_const<TypeInputT>::type>>
122 getPairElements(DataInputT& o, TypeInputT& t)
123 {
126
128
129 if (x)
130 {
131 auto e0 = x->getElement(0);
132 auto ac0 = y->getFirstAcceptedType();
133 auto e1 = x->getElement(1);
134 auto ac1 = y->getSecondAcceptedType();
135 return {{e0, ac0}, {e1, ac1}};
136 }
137 return {};
138 }
139
140 template <typename DataInputT, typename TypeInputT>
141 std::vector<std::pair<typename std::remove_const<DataInputT>::type,
142 typename std::remove_const<TypeInputT>::type>>
143 getTupleElements(DataInputT& o, TypeInputT& t)
144 {
145 std::vector<std::pair<data::VariantPtr, type::VariantPtr>> ret;
148
150
151 if (x)
152 {
153 unsigned int i = 0;
154 for (const auto& e : x->getElements())
155 {
156 auto ac = y->getAcceptedType(i++);
157 ret.emplace_back(e, ac);
158 }
159 }
160 return ret;
161 }
162} // namespace armarx::aron::component_config
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
std::pair< std::pair< typename std::remove_const< DataInputT >::type, typename std::remove_const< TypeInputT >::type >, std::pair< typename std::remove_const< DataInputT >::type, typename std::remove_const< TypeInputT >::type > > getPairElements(DataInputT &o, TypeInputT &t)
Definition Util.h:122
std::string pathToName(const std::shared_ptr< data::Variant > &v)
Definition Util.h:36
std::map< std::string, std::pair< typename std::remove_const< DataInputT >::type, typename std::remove_const< TypeInputT >::type > > getObjectElements(DataInputT &o, TypeInputT &t)
Definition Util.h:50
std::vector< std::pair< typename std::remove_const< DataInputT >::type, typename std::remove_const< TypeInputT >::type > > getListElements(DataInputT &o, TypeInputT &t)
Definition Util.h:97
std::map< std::string, std::pair< typename std::remove_const< DataInputT >::type, typename std::remove_const< TypeInputT >::type > > getDictElements(DataInputT &o, TypeInputT &t)
Definition Util.h:73
std::vector< std::pair< typename std::remove_const< DataInputT >::type, typename std::remove_const< TypeInputT >::type > > getTupleElements(DataInputT &o, TypeInputT &t)
Definition Util.h:143
This file offers overloads of toIce() and fromIce() functions for STL container types.