Gazebo Msgs
API Reference
11.0.1
insert_drive_file
Tutorials
library_books
Classes
toc
Namespaces
insert_drive_file
Files
launch
Gazebo Website
Index
List
Hierarchy
Members: All
Members: Functions
Members: Variables
Members: Typedefs
Members: Enumerations
Members: Enumerator
List
Members
Functions
Typedefs
Variables
Enumerations
Enumerator
src
gz-msgs
core
include
gz
msgs
convert
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
#include <gz/msgs/config.hh>
22
23
// Message Headers
24
#include "gz/msgs/boolean.pb.h"
25
#include "gz/msgs/double.pb.h"
26
#include "gz/msgs/float.pb.h"
27
#include "gz/msgs/int32.pb.h"
28
#include "gz/msgs/int64.pb.h"
29
#include "gz/msgs/stringmsg.pb.h"
30
#include "gz/msgs/time.pb.h"
31
#include "gz/msgs/uint32.pb.h"
32
#include "gz/msgs/uint64.pb.h"
33
34
// Data Headers
35
#include <chrono>
36
#include <string>
37
#include <utility>
38
39
namespace
gz::msgs
{
40
// Inline bracket to help doxygen filtering.
41
inline
namespace
GZ_MSGS_VERSION_NAMESPACE {
42
44
inline
void
Set
(gz::msgs::Time *_msg,
45
const
std::chrono::steady_clock::duration &_data)
46
{
47
std::pair<uint64_t, uint64_t>
timeSecAndNsecs =
48
gz::math::durationToSecNsec
(_data);
49
msgs::Time msg;
50
_msg->set_sec(timeSecAndNsecs.first);
51
_msg->set_nsec(
static_cast<
int32_t
>
(timeSecAndNsecs.second));
52
}
53
54
inline
void
Set
(std::chrono::steady_clock::duration *_data,
55
const
gz::msgs::Time &_msg)
56
{
57
*_data = (
58
std::chrono::seconds
(_msg.sec()) +
59
std::chrono::nanoseconds
(_msg.nsec()));
60
}
61
62
inline
gz::msgs::Time
Convert
(
const
std::chrono::steady_clock::duration &_data)
63
{
64
gz::msgs::Time ret;
65
Set
(&ret, _data);
66
return
ret;
67
}
68
69
inline
std::chrono::steady_clock::duration
70
Convert
(
const
gz::msgs::Time &_msg)
71
{
72
std::chrono::steady_clock::duration ret;
73
Set
(&ret, _msg);
74
return
ret;
75
}
76
78
inline
void
Set
(gz::msgs::StringMsg *_msg,
const
std::string
&_data)
79
{
80
_msg->set_data(_data);
81
}
82
83
inline
void
Set
(gz::msgs::StringMsg *_msg,
const
char
*_data)
84
{
85
_msg->set_data(_data);
86
}
87
88
inline
void
Set
(
std::string
*_data,
const
gz::msgs::StringMsg &_msg)
89
{
90
*_data = _msg.
data
();
91
}
92
93
inline
gz::msgs::StringMsg
Convert
(
const
std::string
&_data)
94
{
95
gz::msgs::StringMsg ret;
96
Set
(&ret, _data);
97
return
ret;
98
}
99
100
inline
std::string
Convert
(
const
gz::msgs::StringMsg &_msg)
101
{
102
std::string
ret;
103
Set
(&ret, _msg);
104
return
ret;
105
}
106
108
inline
void
Set
(gz::msgs::Boolean *_msg,
const
bool
&_data)
109
{
110
_msg->set_data(_data);
111
}
112
113
inline
void
Set
(
bool
*_data,
const
gz::msgs::Boolean &_msg)
114
{
115
*_data = _msg.data();
116
}
117
118
inline
gz::msgs::Boolean
Convert
(
const
bool
&_data)
119
{
120
gz::msgs::Boolean ret;
121
Set
(&ret, _data);
122
return
ret;
123
}
124
125
inline
bool
Convert
(
const
gz::msgs::Boolean &_msg)
126
{
127
bool
ret;
128
Set
(&ret, _msg);
129
return
ret;
130
}
131
133
inline
void
Set
(gz::msgs::Int32 *_msg,
const
int32_t &_data)
134
{
135
_msg->set_data(_data);
136
}
137
138
inline
void
Set
(int32_t *_data,
const
gz::msgs::Int32 &_msg)
139
{
140
*_data = _msg.data();
141
}
142
143
inline
gz::msgs::Int32
Convert
(
const
int32_t &_data)
144
{
145
gz::msgs::Int32 ret;
146
Set
(&ret, _data);
147
return
ret;
148
}
149
150
inline
int32_t
Convert
(
const
gz::msgs::Int32 &_msg)
151
{
152
int32_t ret;
153
Set
(&ret, _msg);
154
return
ret;
155
}
156
158
inline
void
Set
(gz::msgs::UInt32 *_msg,
const
uint32_t &_data)
159
{
160
_msg->set_data(_data);
161
}
162
163
inline
void
Set
(uint32_t *_data,
const
gz::msgs::UInt32 &_msg)
164
{
165
*_data = _msg.data();
166
}
167
168
inline
gz::msgs::UInt32
Convert
(
const
uint32_t &_data)
169
{
170
gz::msgs::UInt32 ret;
171
Set
(&ret, _data);
172
return
ret;
173
}
174
175
inline
uint32_t
Convert
(
const
gz::msgs::UInt32 &_msg)
176
{
177
uint32_t ret;
178
Set
(&ret, _msg);
179
return
ret;
180
}
181
183
inline
void
Set
(gz::msgs::Int64 *_msg,
const
int64_t &_data)
184
{
185
_msg->set_data(_data);
186
}
187
188
inline
void
Set
(int64_t *_data,
const
gz::msgs::Int64 &_msg)
189
{
190
*_data = _msg.data();
191
}
192
193
inline
gz::msgs::Int64
Convert
(
const
int64_t &_data)
194
{
195
gz::msgs::Int64 ret;
196
Set
(&ret, _data);
197
return
ret;
198
}
199
200
inline
int64_t
Convert
(
const
gz::msgs::Int64 &_msg)
201
{
202
int64_t ret;
203
Set
(&ret, _msg);
204
return
ret;
205
}
206
208
inline
void
Set
(gz::msgs::UInt64 *_msg,
const
uint64_t &_data)
209
{
210
_msg->set_data(_data);
211
}
212
213
inline
void
Set
(uint64_t *_data,
const
gz::msgs::UInt64 &_msg)
214
{
215
*_data = _msg.data();
216
}
217
218
inline
gz::msgs::UInt64
Convert
(
const
uint64_t &_data)
219
{
220
gz::msgs::UInt64 ret;
221
Set
(&ret, _data);
222
return
ret;
223
}
224
225
inline
uint64_t
Convert
(
const
gz::msgs::UInt64 &_msg)
226
{
227
uint64_t ret;
228
Set
(&ret, _msg);
229
return
ret;
230
}
231
233
inline
void
Set
(gz::msgs::Float *_msg,
const
float
&_data)
234
{
235
_msg->set_data(_data);
236
}
237
238
inline
void
Set
(
float
*_data,
const
gz::msgs::Float &_msg)
239
{
240
*_data = _msg.data();
241
}
242
243
inline
gz::msgs::Float
Convert
(
const
float
&_data)
244
{
245
gz::msgs::Float ret;
246
Set
(&ret, _data);
247
return
ret;
248
}
249
250
inline
float
Convert
(
const
gz::msgs::Float &_msg)
251
{
252
float
ret;
253
Set
(&ret, _msg);
254
return
ret;
255
}
256
258
inline
void
Set
(gz::msgs::Double *_msg,
const
double
&_data)
259
{
260
_msg->set_data(_data);
261
}
262
263
inline
void
Set
(
double
*_data,
const
gz::msgs::Double &_msg)
264
{
265
*_data = _msg.data();
266
}
267
268
inline
gz::msgs::Double
Convert
(
const
double
&_data)
269
{
270
gz::msgs::Double ret;
271
Set
(&ret, _data);
272
return
ret;
273
}
274
275
inline
double
Convert
(
const
gz::msgs::Double &_msg)
276
{
277
double
ret;
278
Set
(&ret, _msg);
279
return
ret;
280
}
281
}
// namespce
282
}
// namespace gz::msgs
283
#endif
// GZ_MSGS_CONVERT_VECTOR3_HH_