Gazebo Msgs

API Reference

10.4.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  _msg->set_sec(timeSecAndNsecs.first);
49  _msg->set_nsec(static_cast<int32_t>(timeSecAndNsecs.second));
50 }
51 
52 inline void Set(std::chrono::steady_clock::duration *_data,
53  const gz::msgs::Time &_msg)
54 {
55  *_data = (
56  std::chrono::seconds(_msg.sec()) +
57  std::chrono::nanoseconds(_msg.nsec()));
58 }
59 
60 inline gz::msgs::Time Convert(const std::chrono::steady_clock::duration &_data)
61 {
62  gz::msgs::Time ret;
63  Set(&ret, _data);
64  return ret;
65 }
66 
67 inline std::chrono::steady_clock::duration
68 Convert(const gz::msgs::Time &_msg)
69 {
70  std::chrono::steady_clock::duration ret;
71  Set(&ret, _msg);
72  return ret;
73 }
74 
76 inline void Set(gz::msgs::StringMsg *_msg, const std::string &_data)
77 {
78  _msg->set_data(_data);
79 }
80 
81 inline void Set(gz::msgs::StringMsg *_msg, const char *_data)
82 {
83  _msg->set_data(_data);
84 }
85 
86 inline void Set(std::string *_data, const gz::msgs::StringMsg &_msg)
87 {
88  *_data = _msg.data();
89 }
90 
91 inline gz::msgs::StringMsg Convert(const std::string &_data)
92 {
93  gz::msgs::StringMsg ret;
94  Set(&ret, _data);
95  return ret;
96 }
97 
98 inline std::string Convert(const gz::msgs::StringMsg &_msg)
99 {
100  std::string ret;
101  Set(&ret, _msg);
102  return ret;
103 }
104 
106 inline void Set(gz::msgs::Boolean *_msg, const bool &_data)
107 {
108  _msg->set_data(_data);
109 }
110 
111 inline void Set(bool *_data, const gz::msgs::Boolean &_msg)
112 {
113  *_data = _msg.data();
114 }
115 
116 inline gz::msgs::Boolean Convert(const bool &_data)
117 {
118  gz::msgs::Boolean ret;
119  Set(&ret, _data);
120  return ret;
121 }
122 
123 inline bool Convert(const gz::msgs::Boolean &_msg)
124 {
125  bool ret;
126  Set(&ret, _msg);
127  return ret;
128 }
129 
131 inline void Set(gz::msgs::Int32 *_msg, const int32_t &_data)
132 {
133  _msg->set_data(_data);
134 }
135 
136 inline void Set(int32_t *_data, const gz::msgs::Int32 &_msg)
137 {
138  *_data = _msg.data();
139 }
140 
141 inline gz::msgs::Int32 Convert(const int32_t &_data)
142 {
143  gz::msgs::Int32 ret;
144  Set(&ret, _data);
145  return ret;
146 }
147 
148 inline int32_t Convert(const gz::msgs::Int32 &_msg)
149 {
150  int32_t ret;
151  Set(&ret, _msg);
152  return ret;
153 }
154 
156 inline void Set(gz::msgs::UInt32 *_msg, const uint32_t &_data)
157 {
158  _msg->set_data(_data);
159 }
160 
161 inline void Set(uint32_t *_data, const gz::msgs::UInt32 &_msg)
162 {
163  *_data = _msg.data();
164 }
165 
166 inline gz::msgs::UInt32 Convert(const uint32_t &_data)
167 {
168  gz::msgs::UInt32 ret;
169  Set(&ret, _data);
170  return ret;
171 }
172 
173 inline uint32_t Convert(const gz::msgs::UInt32 &_msg)
174 {
175  uint32_t ret;
176  Set(&ret, _msg);
177  return ret;
178 }
179 
181 inline void Set(gz::msgs::Int64 *_msg, const int64_t &_data)
182 {
183  _msg->set_data(_data);
184 }
185 
186 inline void Set(int64_t *_data, const gz::msgs::Int64 &_msg)
187 {
188  *_data = _msg.data();
189 }
190 
191 inline gz::msgs::Int64 Convert(const int64_t &_data)
192 {
193  gz::msgs::Int64 ret;
194  Set(&ret, _data);
195  return ret;
196 }
197 
198 inline int64_t Convert(const gz::msgs::Int64 &_msg)
199 {
200  int64_t ret;
201  Set(&ret, _msg);
202  return ret;
203 }
204 
206 inline void Set(gz::msgs::UInt64 *_msg, const uint64_t &_data)
207 {
208  _msg->set_data(_data);
209 }
210 
211 inline void Set(uint64_t *_data, const gz::msgs::UInt64 &_msg)
212 {
213  *_data = _msg.data();
214 }
215 
216 inline gz::msgs::UInt64 Convert(const uint64_t &_data)
217 {
218  gz::msgs::UInt64 ret;
219  Set(&ret, _data);
220  return ret;
221 }
222 
223 inline uint64_t Convert(const gz::msgs::UInt64 &_msg)
224 {
225  uint64_t ret;
226  Set(&ret, _msg);
227  return ret;
228 }
229 
231 inline void Set(gz::msgs::Float *_msg, const float &_data)
232 {
233  _msg->set_data(_data);
234 }
235 
236 inline void Set(float *_data, const gz::msgs::Float &_msg)
237 {
238  *_data = _msg.data();
239 }
240 
241 inline gz::msgs::Float Convert(const float &_data)
242 {
243  gz::msgs::Float ret;
244  Set(&ret, _data);
245  return ret;
246 }
247 
248 inline float Convert(const gz::msgs::Float &_msg)
249 {
250  float ret;
251  Set(&ret, _msg);
252  return ret;
253 }
254 
256 inline void Set(gz::msgs::Double *_msg, const double &_data)
257 {
258  _msg->set_data(_data);
259 }
260 
261 inline void Set(double *_data, const gz::msgs::Double &_msg)
262 {
263  *_data = _msg.data();
264 }
265 
266 inline gz::msgs::Double Convert(const double &_data)
267 {
268  gz::msgs::Double ret;
269  Set(&ret, _data);
270  return ret;
271 }
272 
273 inline double Convert(const gz::msgs::Double &_msg)
274 {
275  double ret;
276  Set(&ret, _msg);
277  return ret;
278 }
279 } // namespce
280 } // namespace gz::msgs
281 #endif // GZ_MSGS_CONVERT_VECTOR3_HH_