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