ice_conversions_templates.h
Go to the documentation of this file.
1#pragma once
2
4
5#define DEPRECATION_TO_ICE \
6 "This function is deprecated. Use armarx::toIce() from <ArmarXCore/core/ice_conversions.h> " \
7 "instead."
8#define DEPRECATION_FROM_ICE \
9 "This function is deprecated. Use armarx::fromIce() from <ArmarXCore/core/ice_conversions.h> " \
10 "instead."
11
12namespace armarx::armem
13{
14
15 // Same type
16 template <class T>
17 [[deprecated(DEPRECATION_TO_ICE)]] void
18 toIce(T& ice, const T& cpp)
19 {
20 ice = cpp;
21 }
22
23 template <class T>
24 [[deprecated(DEPRECATION_FROM_ICE)]] void
25 fromIce(const T& ice, T& cpp)
26 {
27 cpp = ice;
28 }
29
30 // Ice Handle
31 template <class IceT, class CppT>
32 [[deprecated(DEPRECATION_TO_ICE)]] void
33 toIce(::IceInternal::Handle<IceT>& ice, const CppT& cpp)
34 {
35 ice = new IceT();
36 toIce(*ice, cpp);
37 }
38
39 template <class IceT, class CppT>
40 [[deprecated(DEPRECATION_FROM_ICE)]] void
41 fromIce(const ::IceInternal::Handle<IceT>& ice, CppT& cpp)
42 {
43 if (ice)
44 {
45 fromIce(*ice, cpp);
46 }
47 }
48
49 // General return version
50 template <class IceT, class CppT>
51 [[deprecated(DEPRECATION_TO_ICE)]] IceT
52 toIce(const CppT& cpp)
53 {
54 IceT ice;
55 toIce(ice, cpp);
56 return ice;
57 }
58
59 template <class CppT, class IceT>
60 [[deprecated(DEPRECATION_FROM_ICE)]] CppT
61 fromIce(const IceT& ice)
62 {
63 CppT cpp;
64 fromIce(ice, cpp);
65 return cpp;
66 }
67
68 // std::unique_ptr
69
70 template <class IceT, class CppT>
71 [[deprecated(DEPRECATION_TO_ICE)]] void
72 toIce(IceT& ice, const std::unique_ptr<CppT>& cppPointer)
73 {
74 if (cppPointer)
75 {
76 toIce(ice, *cppPointer);
77 }
78 }
79
80 template <class IceT, class CppT>
81 [[deprecated(DEPRECATION_FROM_ICE)]] void
82 fromIce(const IceT& ice, std::unique_ptr<CppT>& cppPointer)
83 {
84 cppPointer = std::make_unique<CppT>();
85 fromIce(ice, *cppPointer);
86 }
87
88 // Ice Handle <-> std::unique_ptr
89
90 template <class IceT, class CppT>
91 [[deprecated(DEPRECATION_TO_ICE)]] void
92 toIce(::IceInternal::Handle<IceT>& ice, const std::unique_ptr<CppT>& cppPointer)
93 {
94 if (cppPointer)
95 {
96 ice = new IceT();
97 toIce(*ice, *cppPointer);
98 }
99 else
100 {
101 ice = nullptr;
102 }
103 }
104
105 template <class IceT, class CppT>
106 [[deprecated(DEPRECATION_FROM_ICE)]] void
107 fromIce(const ::IceInternal::Handle<IceT>& ice, std::unique_ptr<CppT>& cppPointer)
108 {
109 if (ice)
110 {
111 cppPointer = std::make_unique<CppT>();
112 fromIce(*ice, *cppPointer);
113 }
114 else
115 {
116 cppPointer = nullptr;
117 }
118 }
119
120 // std::vector
121
122 template <class IceT, class CppT>
123 [[deprecated(DEPRECATION_TO_ICE)]] void
124 toIce(std::vector<IceT>& ices, const std::vector<CppT>& cpps)
125 {
126 ices.clear();
127 ices.reserve(cpps.size());
128 for (const auto& cpp : cpps)
129 {
130 toIce(ices.emplace_back(), cpp);
131 }
132 }
133
134 template <class IceT, class CppT>
135 [[deprecated(DEPRECATION_FROM_ICE)]] void
136 fromIce(const std::vector<IceT>& ices, std::vector<CppT>& cpps)
137 {
138 cpps.clear();
139 cpps.reserve(ices.size());
140 for (const auto& ice : ices)
141 {
142 fromIce(ice, cpps.emplace_back());
143 }
144 }
145
146 template <class IceT, class CppT>
147 [[deprecated(DEPRECATION_TO_ICE)]] std::vector<IceT>
148 toIce(const std::vector<CppT>& cpps)
149 {
150 std::vector<IceT> ices;
151 toIce(ices, cpps);
152 return ices;
153 }
154
155 // std::map
156
157 template <class IceKeyT, class IceValueT, class CppKeyT, class CppValueT>
158 [[deprecated(DEPRECATION_TO_ICE)]] void
159 toIce(std::map<IceKeyT, IceValueT>& iceMap, const std::map<CppKeyT, CppValueT>& cppMap)
160 {
161 iceMap.clear();
162 for (const auto& [key, value] : cppMap)
163 {
164 iceMap.emplace(toIce<IceKeyT>(key), toIce<IceValueT>(value));
165 }
166 }
167
168 template <class IceKeyT, class IceValueT, class CppKeyT, class CppValueT>
169 [[deprecated(DEPRECATION_FROM_ICE)]] void
170 fromIce(const std::map<IceKeyT, IceValueT>& iceMap, std::map<CppKeyT, CppValueT>& cppMap)
171 {
172 cppMap.clear();
173 for (const auto& [key, value] : iceMap)
174 {
175 cppMap.emplace(fromIce<CppKeyT>(key), fromIce<CppValueT>(value));
176 }
177 }
178
179 template <class IceKeyT, class IceValueT, class CppKeyT, class CppValueT>
180 [[deprecated(DEPRECATION_TO_ICE)]] std::map<IceKeyT, IceValueT>
181 toIce(const std::map<CppKeyT, CppValueT>& cppMap)
182 {
183 std::map<IceKeyT, IceValueT> iceMap;
184 toIce(iceMap, cppMap);
185 return iceMap;
186 }
187} // namespace armarx::armem
#define DEPRECATION_TO_ICE
#define DEPRECATION_FROM_ICE
void fromIce(const data::MemoryID &ice, MemoryID &id)
void toIce(data::MemoryID &ice, const MemoryID &id)