Gazebo Msgs

API Reference

10.1.1
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
38namespace gz::msgs {
39// Inline bracket to help doxygen filtering.
40inline namespace GZ_MSGS_VERSION_NAMESPACE {
41
43inline 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(timeSecAndNsecs.second);
51}
52
53inline 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
61inline 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
68inline std::chrono::steady_clock::duration
69Convert(const gz::msgs::Time &_msg)
70{
71 std::chrono::steady_clock::duration ret;
72 Set(&ret, _msg);
73 return ret;
74}
75
77inline void Set(gz::msgs::StringMsg *_msg, const std::string &_data)
78{
79 _msg->set_data(_data);
80}
81
82inline void Set(gz::msgs::StringMsg *_msg, const char *_data)
83{
84 _msg->set_data(_data);
85}
86
87inline void Set(std::string *_data, const gz::msgs::StringMsg &_msg)
88{
89 *_data = _msg.data();
90}
91
92inline gz::msgs::StringMsg Convert(const std::string &_data)
93{
94 gz::msgs::StringMsg ret;
95 Set(&ret, _data);
96 return ret;
97}
98
99inline std::string Convert(const gz::msgs::StringMsg &_msg)
100{
101 std::string ret;
102 Set(&ret, _msg);
103 return ret;
104}
105
107inline void Set(gz::msgs::Boolean *_msg, const bool &_data)
108{
109 _msg->set_data(_data);
110}
111
112inline void Set(bool *_data, const gz::msgs::Boolean &_msg)
113{
114 *_data = _msg.data();
115}
116
117inline gz::msgs::Boolean Convert(const bool &_data)
118{
119 gz::msgs::Boolean ret;
120 Set(&ret, _data);
121 return ret;
122}
123
124inline bool Convert(const gz::msgs::Boolean &_msg)
125{
126 bool ret;
127 Set(&ret, _msg);
128 return ret;
129}
130
132inline void Set(gz::msgs::Int32 *_msg, const int32_t &_data)
133{
134 _msg->set_data(_data);
135}
136
137inline void Set(int32_t *_data, const gz::msgs::Int32 &_msg)
138{
139 *_data = _msg.data();
140}
141
142inline gz::msgs::Int32 Convert(const int32_t &_data)
143{
144 gz::msgs::Int32 ret;
145 Set(&ret, _data);
146 return ret;
147}
148
149inline int32_t Convert(const gz::msgs::Int32 &_msg)
150{
151 int32_t ret;
152 Set(&ret, _msg);
153 return ret;
154}
155
157inline void Set(gz::msgs::UInt32 *_msg, const uint32_t &_data)
158{
159 _msg->set_data(_data);
160}
161
162inline void Set(uint32_t *_data, const gz::msgs::UInt32 &_msg)
163{
164 *_data = _msg.data();
165}
166
167inline gz::msgs::UInt32 Convert(const uint32_t &_data)
168{
169 gz::msgs::UInt32 ret;
170 Set(&ret, _data);
171 return ret;
172}
173
174inline uint32_t Convert(const gz::msgs::UInt32 &_msg)
175{
176 uint32_t ret;
177 Set(&ret, _msg);
178 return ret;
179}
180
182inline void Set(gz::msgs::Int64 *_msg, const int64_t &_data)
183{
184 _msg->set_data(_data);
185}
186
187inline void Set(int64_t *_data, const gz::msgs::Int64 &_msg)
188{
189 *_data = _msg.data();
190}
191
192inline gz::msgs::Int64 Convert(const int64_t &_data)
193{
194 gz::msgs::Int64 ret;
195 Set(&ret, _data);
196 return ret;
197}
198
199inline int64_t Convert(const gz::msgs::Int64 &_msg)
200{
201 int64_t ret;
202 Set(&ret, _msg);
203 return ret;
204}
205
207inline void Set(gz::msgs::UInt64 *_msg, const uint64_t &_data)
208{
209 _msg->set_data(_data);
210}
211
212inline void Set(uint64_t *_data, const gz::msgs::UInt64 &_msg)
213{
214 *_data = _msg.data();
215}
216
217inline gz::msgs::UInt64 Convert(const uint64_t &_data)
218{
219 gz::msgs::UInt64 ret;
220 Set(&ret, _data);
221 return ret;
222}
223
224inline uint64_t Convert(const gz::msgs::UInt64 &_msg)
225{
226 uint64_t ret;
227 Set(&ret, _msg);
228 return ret;
229}
230
232inline void Set(gz::msgs::Float *_msg, const float &_data)
233{
234 _msg->set_data(_data);
235}
236
237inline void Set(float *_data, const gz::msgs::Float &_msg)
238{
239 *_data = _msg.data();
240}
241
242inline gz::msgs::Float Convert(const float &_data)
243{
244 gz::msgs::Float ret;
245 Set(&ret, _data);
246 return ret;
247}
248
249inline float Convert(const gz::msgs::Float &_msg)
250{
251 float ret;
252 Set(&ret, _msg);
253 return ret;
254}
255
257inline void Set(gz::msgs::Double *_msg, const double &_data)
258{
259 _msg->set_data(_data);
260}
261
262inline void Set(double *_data, const gz::msgs::Double &_msg)
263{
264 *_data = _msg.data();
265}
266
267inline gz::msgs::Double Convert(const double &_data)
268{
269 gz::msgs::Double ret;
270 Set(&ret, _data);
271 return ret;
272}
273
274inline 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_