Gazebo Msgs

API Reference

10.3.0
StdTypes.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 #ifndef GZ_MSGS_CONVERT_STDTYPES_HH_
18 #define GZ_MSGS_CONVERT_STDTYPES_HH_
19 
20 #include <gz/math/Helpers.hh>
21 
22 // Message Headers
23 #include "gz/msgs/boolean.pb.h"
24 #include "gz/msgs/double.pb.h"
25 #include "gz/msgs/float.pb.h"
26 #include "gz/msgs/int32.pb.h"
27 #include "gz/msgs/int64.pb.h"
28 #include "gz/msgs/stringmsg.pb.h"
29 #include "gz/msgs/time.pb.h"
30 #include "gz/msgs/uint32.pb.h"
31 #include "gz/msgs/uint64.pb.h"
32 
33 // Data Headers
34 #include <chrono>
35 #include <string>
36 #include <utility>
37 
38 namespace gz::msgs {
39 // Inline bracket to help doxygen filtering.
40 inline namespace GZ_MSGS_VERSION_NAMESPACE {
41 
43 inline void Set(gz::msgs::Time *_msg,
44  const std::chrono::steady_clock::duration &_data)
45 {
46  std::pair<uint64_t, uint64_t> timeSecAndNsecs =
48  msgs::Time msg;
49  _msg->set_sec(timeSecAndNsecs.first);
50  _msg->set_nsec(static_cast<int32_t>(timeSecAndNsecs.second));
51 }
52 
53 inline void Set(std::chrono::steady_clock::duration *_data,
54  const gz::msgs::Time &_msg)
55 {
56  *_data = (
57  std::chrono::seconds(_msg.sec()) +
58  std::chrono::nanoseconds(_msg.nsec()));
59 }
60 
61 inline gz::msgs::Time Convert(const std::chrono::steady_clock::duration &_data)
62 {
63  gz::msgs::Time ret;
64  Set(&ret, _data);
65  return ret;
66 }
67 
68 inline std::chrono::steady_clock::duration
69 Convert(const gz::msgs::Time &_msg)
70 {
71  std::chrono::steady_clock::duration ret;
72  Set(&ret, _msg);
73  return ret;
74 }
75 
77 inline void Set(gz::msgs::StringMsg *_msg, const std::string &_data)
78 {
79  _msg->set_data(_data);
80 }
81 
82 inline void Set(gz::msgs::StringMsg *_msg, const char *_data)
83 {
84  _msg->set_data(_data);
85 }
86 
87 inline void Set(std::string *_data, const gz::msgs::StringMsg &_msg)
88 {
89  *_data = _msg.data();
90 }
91 
92 inline gz::msgs::StringMsg Convert(const std::string &_data)
93 {
94  gz::msgs::StringMsg ret;
95  Set(&ret, _data);
96  return ret;
97 }
98 
99 inline std::string Convert(const gz::msgs::StringMsg &_msg)
100 {
101  std::string ret;
102  Set(&ret, _msg);
103  return ret;
104 }
105 
107 inline void Set(gz::msgs::Boolean *_msg, const bool &_data)
108 {
109  _msg->set_data(_data);
110 }
111 
112 inline void Set(bool *_data, const gz::msgs::Boolean &_msg)
113 {
114  *_data = _msg.data();
115 }
116 
117 inline gz::msgs::Boolean Convert(const bool &_data)
118 {
119  gz::msgs::Boolean ret;
120  Set(&ret, _data);
121  return ret;
122 }
123 
124 inline bool Convert(const gz::msgs::Boolean &_msg)
125 {
126  bool ret;
127  Set(&ret, _msg);
128  return ret;
129 }
130 
132 inline void Set(gz::msgs::Int32 *_msg, const int32_t &_data)
133 {
134  _msg->set_data(_data);
135 }
136 
137 inline void Set(int32_t *_data, const gz::msgs::Int32 &_msg)
138 {
139  *_data = _msg.data();
140 }
141 
142 inline gz::msgs::Int32 Convert(const int32_t &_data)
143 {
144  gz::msgs::Int32 ret;
145  Set(&ret, _data);
146  return ret;
147 }
148 
149 inline int32_t Convert(const gz::msgs::Int32 &_msg)
150 {
151  int32_t ret;
152  Set(&ret, _msg);
153  return ret;
154 }
155 
157 inline void Set(gz::msgs::UInt32 *_msg, const uint32_t &_data)
158 {
159  _msg->set_data(_data);
160 }
161 
162 inline void Set(uint32_t *_data, const gz::msgs::UInt32 &_msg)
163 {
164  *_data = _msg.data();
165 }
166 
167 inline gz::msgs::UInt32 Convert(const uint32_t &_data)
168 {
169  gz::msgs::UInt32 ret;
170  Set(&ret, _data);
171  return ret;
172 }
173 
174 inline uint32_t Convert(const gz::msgs::UInt32 &_msg)
175 {
176  uint32_t ret;
177  Set(&ret, _msg);
178  return ret;
179 }
180 
182 inline void Set(gz::msgs::Int64 *_msg, const int64_t &_data)
183 {
184  _msg->set_data(_data);
185 }
186 
187 inline void Set(int64_t *_data, const gz::msgs::Int64 &_msg)
188 {
189  *_data = _msg.data();
190 }
191 
192 inline gz::msgs::Int64 Convert(const int64_t &_data)
193 {
194  gz::msgs::Int64 ret;
195  Set(&ret, _data);
196  return ret;
197 }
198 
199 inline int64_t Convert(const gz::msgs::Int64 &_msg)
200 {
201  int64_t ret;
202  Set(&ret, _msg);
203  return ret;
204 }
205 
207 inline void Set(gz::msgs::UInt64 *_msg, const uint64_t &_data)
208 {
209  _msg->set_data(_data);
210 }
211 
212 inline void Set(uint64_t *_data, const gz::msgs::UInt64 &_msg)
213 {
214  *_data = _msg.data();
215 }
216 
217 inline gz::msgs::UInt64 Convert(const uint64_t &_data)
218 {
219  gz::msgs::UInt64 ret;
220  Set(&ret, _data);
221  return ret;
222 }
223 
224 inline uint64_t Convert(const gz::msgs::UInt64 &_msg)
225 {
226  uint64_t ret;
227  Set(&ret, _msg);
228  return ret;
229 }
230 
232 inline void Set(gz::msgs::Float *_msg, const float &_data)
233 {
234  _msg->set_data(_data);
235 }
236 
237 inline void Set(float *_data, const gz::msgs::Float &_msg)
238 {
239  *_data = _msg.data();
240 }
241 
242 inline gz::msgs::Float Convert(const float &_data)
243 {
244  gz::msgs::Float ret;
245  Set(&ret, _data);
246  return ret;
247 }
248 
249 inline float Convert(const gz::msgs::Float &_msg)
250 {
251  float ret;
252  Set(&ret, _msg);
253  return ret;
254 }
255 
257 inline void Set(gz::msgs::Double *_msg, const double &_data)
258 {
259  _msg->set_data(_data);
260 }
261 
262 inline void Set(double *_data, const gz::msgs::Double &_msg)
263 {
264  *_data = _msg.data();
265 }
266 
267 inline gz::msgs::Double Convert(const double &_data)
268 {
269  gz::msgs::Double ret;
270  Set(&ret, _data);
271  return ret;
272 }
273 
274 inline double Convert(const gz::msgs::Double &_msg)
275 {
276  double ret;
277  Set(&ret, _msg);
278  return ret;
279 }
280 } // namespce
281 } // namespace gz::msgs
282 #endif // GZ_MSGS_CONVERT_VECTOR3_HH_