CARLA
 
载入中...
搜索中...
未找到
TF2Error.cpp
浏览该文件的文档.
1// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/*!
16 * @file TF2Error.cpp
17 * This source file contains the definition of the described types in the IDL file.
18 *
19 * This file was generated by the tool gen.
20 */
21
22#ifdef _WIN32
23// Remove linker warning LNK4221 on Visual Studio
24namespace {
25char dummy;
26} // namespace
27#endif // _WIN32
28
29#include "TF2Error.h"
30#include <fastcdr/Cdr.h>
31
32#include <fastcdr/exceptions/BadParamException.h>
33using namespace eprosima::fastcdr::exception;
34
35#include <utility>
36
37#define tf2_msgs_msg_TF2Error_max_cdr_typesize 264ULL;
38#define tf2_msgs_msg_TF2Error_max_key_cdr_typesize 0ULL;
39
41{
42 // 将 m_error 初始化为 0
43 // m_error 是一个字节类型(octet),用于表示错误的代码或状态
44 m_error = 0;
45
46 // 将 m_error_string 初始化为空字符串
47 // m_error_string 是一个字符串,用于描述错误的详细信息
48 m_error_string = "";
49}
50
51
55
57 const TF2Error& x)
58{
59 // 将输入对象 x 的 m_error 成员变量值赋给当前对象的 m_error
60 m_error = x.m_error;
61
62 // 将输入对象 x 的 m_error_string 成员变量值赋给当前对象的 m_error_string
63 m_error_string = x.m_error_string;
64}
65
66
68 TF2Error&& x) noexcept
69{
70 // 将输入对象 x 的 m_error 成员变量值赋给当前对象的 m_error
71 m_error = x.m_error;
72
73 // 使用 std::move 将输入对象 x 的 m_error_string 移动到当前对象的 m_error_string
74 // 这里使用 std::move 表示将 x.m_error_string 的资源转移到当前对象,避免不必要的拷贝
75 m_error_string = std::move(x.m_error_string);
76}
77
78
80 const TF2Error& x)
81{
82 m_error = x.m_error;
83 m_error_string = x.m_error_string;
84
85 return *this;
86}
87
89 TF2Error&& x) noexcept
90{
91 m_error = x.m_error;
92 m_error_string = std::move(x.m_error_string);
93
94 return *this;
95}
96
98 const TF2Error& x) const
99{
100 return (m_error == x.m_error && m_error_string == x.m_error_string);
101}
102
104 const TF2Error& x) const
105{
106 return !(*this == x);
107}
108
115
117 const tf2_msgs::msg::TF2Error& data,
118 size_t current_alignment)
119{
121 current_alignment += 1 + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);
122 current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.error_string().size() + 1;
123
125}
126
128 eprosima::fastcdr::Cdr& scdr) const
129{
130 // 将 m_error 成员变量序列化到 CDR 流中
131 // scdr 是用于序列化的 Cdr 对象,"<<" 运算符表示将数据写入流中
132 scdr << m_error;
133
134 // 将 m_error_string 的 C 字符串(即 m_error_string.c_str())序列化到 CDR 流中
135 // 这里使用 c_str() 将 std::string 转换为 C 风格字符串(const char*),
136 // 因为 FastCDR 库需要 C 风格的字符串来进行序列化
137 scdr << m_error_string.c_str();
138}
139
140
142 eprosima::fastcdr::Cdr& dcdr)
143{
144 // 从数据流中反序列化成员变量 m_error 和 m_error_string
145 dcdr >> m_error; // 反序列化错误码
146 dcdr >> m_error_string; // 反序列化错误信息字符串
147}
148
149/*!
150 * @brief 设置成员 error 的新值
151 * @param _error 新的错误码值
152 */
154 uint8_t _error)
155{
156 m_error = _error; // 更新成员变量 m_error 的值
157}
158
159/*!
160 * @brief 返回成员 error 的值
161 * @return 成员 error 的值
162 */
164{
165 return m_error; // 返回当前错误码的值
166}
167
168/*!
169 * @brief 返回成员 error 的引用
170 * @return 成员 error 的引用
171 */
173{
174 return m_error; // 返回 m_error 的引用,以供修改
175}
176
177/*!
178 * @brief 复制新值到成员 error_string
179 * @param _error_string 新的错误信息字符串
180 */
182 const std::string& _error_string)
183{
184 m_error_string = _error_string; // 将新的错误字符串复制给成员变量 m_error_string
185}
186
187/*!
188 * @brief 移动新值到成员 error_string
189 * @param _error_string 新的错误信息字符串
190 */
192 std::string&& _error_string)
193{
194 m_error_string = std::move(_error_string); // 直接移动错误字符串到成员变量 m_error_string
195}
196
197/*!
198 * @brief 返回成员 error_string 的常量引用
199 * @return error_string 的常量引用
200 */
201const std::string& tf2_msgs::msg::TF2Error::error_string() const
202{
203 return m_error_string; // 返回 m_error_string 的常量引用,不允许修改
204}
205
206/*!
207 * @brief 返回成员 error_string 的引用
208 * @return member error_string 的引用
209 */
211{
212 return m_error_string; // 返回 m_error_string 的引用,以供修改
213}
214
215
217 size_t current_alignment)
218{
219 // 静态转换 current_alignment 为 void,表示这个参数当前没有被使用
220 // 该行代码的目的是消除未使用变量的编译警告
221 static_cast<void>(current_alignment);
222
223 // 返回最大键的 CDR 序列化大小
224 // tf2_msgs_msg_TF2Error_max_key_cdr_typesize 是一个常量,表示 TF2Error 类型的键在 CDR 序列化格式中的最大大小
226}
227
228
230{
231 return false;
232}
233
235 eprosima::fastcdr::Cdr& scdr) const
236{
237 (void) scdr;
238}
return current_alignment initial_alignment
#define tf2_msgs_msg_TF2Error_max_key_cdr_typesize
Definition TF2Error.cpp:38
#define tf2_msgs_msg_TF2Error_max_cdr_typesize
Definition TF2Error.cpp:37
eProsima_user_DllExport bool operator!=(const TF2Error &x) const
Definition TF2Error.cpp:103
static eProsima_user_DllExport size_t getMaxCdrSerializedSize(size_t current_alignment=0)
Definition TF2Error.cpp:109
eProsima_user_DllExport TF2Error & operator=(const TF2Error &x)
Definition TF2Error.cpp:79
std::string m_error_string
Definition TF2Error.h:234
eProsima_user_DllExport ~TF2Error()
Definition TF2Error.cpp:52
eProsima_user_DllExport void error_string(const std::string &_error_string)
复制新值到成员 error_string
Definition TF2Error.cpp:181
eProsima_user_DllExport bool operator==(const TF2Error &x) const
Definition TF2Error.cpp:97
eProsima_user_DllExport void deserialize(eprosima::fastcdr::Cdr &cdr)
Definition TF2Error.cpp:141
eProsima_user_DllExport TF2Error()
Definition TF2Error.cpp:40
eProsima_user_DllExport void serialize(eprosima::fastcdr::Cdr &cdr) const
Definition TF2Error.cpp:127
eProsima_user_DllExport uint8_t error() const
返回成员 error 的值
Definition TF2Error.cpp:163
static eProsima_user_DllExport size_t getKeyMaxCdrSerializedSize(size_t current_alignment=0)
Definition TF2Error.cpp:216
eProsima_user_DllExport void serializeKey(eprosima::fastcdr::Cdr &cdr) const
Definition TF2Error.cpp:234
eProsima_user_DllExport const std::string & error_string() const
返回成员 error_string 的常量引用
Definition TF2Error.cpp:201
static eProsima_user_DllExport bool isKeyDefined()
Definition TF2Error.cpp:229
static eProsima_user_DllExport size_t getCdrSerializedSize(const tf2_msgs::msg::TF2Error &data, size_t current_alignment=0)
Definition TF2Error.cpp:116