CARLA
 
载入中...
搜索中...
未找到
TwistPubSubTypes.h
浏览该文件的文档.
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 TwistPubSubTypes.h
17 * 此头文件包含序列化函数的声明。
18 *
19 * 此文件是由工具 fastcdrgen 生成的。
20 */
21
22#ifndef _FAST_DDS_GENERATED_GEOMETRY_MSGS_MSG_TWIST_PUBSUBTYPES_H_
23#define _FAST_DDS_GENERATED_GEOMETRY_MSGS_MSG_TWIST_PUBSUBTYPES_H_
24
25#include <fastdds/dds/topic/TopicDataType.hpp>// 引入 Fast DDS 主题数据类型的头文件
26#include <fastrtps/utils/md5.h>// 引入 MD5 哈希的头文件
27
28#include "Twist.h"// 引入 Twist 类型的定义
29
30#include "Vector3PubSubTypes.h"// 引入 Vector3 类型的定义
31// 检查生成的 API 版本是否与当前安装的 Fast DDS 兼容
32#if !defined(GEN_API_VER) || (GEN_API_VER != 1)
33#error \
34 Generated Twist is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen.
35#endif // GEN_API_VER
36//定义了一个名为geometry_msgs的命名空间
37namespace geometry_msgs
38{
39//在geometry_msgs命名空间内又定义了一个名为msg的嵌套命名空间,进一步细化代码的组织结构
40 namespace msg
41 {
42//这是一个预处理器指令 如果SWIG未被定义,那么从这一行开始到对应的# 如果SWIG已经被定义,这部分代码将被跳过。这通常用于防止头文件的多重包含
43 #ifndef SWIG
44//定义了一个名为detail的嵌套命名空间,这是在msg命名空间内部的更深层次的命名空间,用于将特定功能相关的代码分组
45 namespace detail {
46// 用于获取 Twist 类中成员的偏移量
47//定义一个模板,有两个模板参数 用于根据不同的类型来获取特定的类型信息
48 template<typename Tag, typename Tag::type M>
49 //开始定义一个名为Twist_rob的结构体模板
50 struct Twist_rob
51 {
52 //在Twist_rob结构体模板内定义了一个友元函数get,它是一个常量表达式函数(constexpr) 这里通过Tag模板类型来确定返回类型
53 friend constexpr typename Tag::type get(
54 Tag) //接受一个类型为Tag的参数
55 {
56 //这里的M是在模板参数中定义的类型,它应该是与Twist类成员相关的某种类型
57 return M;// 返回成员 M
58 }
59 };
60// 定义 Twist_f 结构体,用于获取 Twist 类中的 Vector3 类型成员
61 struct Twist_f
62 {
63 //定义了一个类型别名type,它表示Twist类中的geometry_msgs::msg::Vector3类型成员的指针类型
64 typedef geometry_msgs::msg::Vector3 Twist::* type;// 定义类型为 Twist 中的 Vector3 成员
65 //定义了一个友元常量表达式函数get,返回类型是前面定义的type
66 friend constexpr type get(
67 Twist_f);
68 };
69// 实例化 Twist_rob 以获取 m_angular 成员的偏移量
71// 获取类型 T 中 Tag 成员的偏移量
72//定义了一个名为Twist_offset_of的函数模板,有两个模板参数T和Tag
73 template <typename T, typename Tag>
74 //开始定义Twist_offset_of函数模板,它是一个内联(inline)的常量表达式函数(constexpr),返回类型为size_t
75 inline size_t constexpr Twist_offset_of() {
76 //计算T类型中Tag成员的偏移量 最后获取这个结果的地址并转换为size_t类型返回
77 return ((::size_t) &reinterpret_cast<char const volatile&>((((T*)0)->*get(Tag()))));
78 }
79 }
80 #endif
81
82 /*!
83 * @brief 此类表示用户在 IDL 文件中定义的类型 Twist 的 TopicDataType。
84 * @ingroup TWIST
85 */
86//定义了一个名为TwistPubSubType的类,它继承自eprosima::fastdds::dds::TopicDataType类
87 class TwistPubSubType : public eprosima::fastdds::dds::TopicDataType
88 {
89 public:
90
91//构造函数用于创建类的对象时进行初始化操作
92 typedef Twist type;// 定义类型别名为 Twist
93
95
96//定义了析构函数
97//析构函数用于在对象生命周期结束时进行清理操作,比如释放构造函数中分配的资源等,同样这里没有给出具体的实现细节
98 eProsima_user_DllExport virtual ~TwistPubSubType() override;// 析构函数
99// 序列化数据
100//将data转换为一种适合传输或者存储的格式,存储到payload中
101// 它返回一个bool类型,表示序列化是否成功。如果序列化过程中出现错误,比如数据格式不正确、内存不足等,可能会返回false
102 eProsima_user_DllExport virtual bool serialize(
103 void* data,
104 eprosima::fastrtps::rtps::SerializedPayload_t* payload) override;
105// 反序列化数据
106// 这个函数与序列化函数相反,它将payload(已经序列化的数据)转换为原始的数据格式,并存储到data中
107//同样返回一个bool类型
108 eProsima_user_DllExport virtual bool deserialize(
109 eprosima::fastrtps::rtps::SerializedPayload_t* payload,
110 void* data) override;
111// 获取序列化大小提供者
112//这个函数的目的是获取数据序列化后的大小 它接受一个数据指针data,根据数据内容返回序列化后的大小
113//返回值是一个std::function类型,可以用来灵活地表示一个可调用对象,计算序列化大小
114 eProsima_user_DllExport virtual std::function<uint32_t()> getSerializedSizeProvider(
115 void* data) override;
116// 获取数据的键
117 eProsima_user_DllExport virtual bool getKey(
118 void* data,
119 eprosima::fastrtps::rtps::InstanceHandle_t* ihandle,
120//有一个默认参数force_md5,如果设置为true,可能会强制使用MD5算法之类的方式来获取键值
121//函数返回一个bool值,表示是否成功获取键值
122 bool force_md5 = false) override;
123// 创建数据实例
124//返回一个指向创建的数据实例的指针。返回的指针类型为void*,可以在后续进行类型转换来使用具体的数据类型
125 eProsima_user_DllExport virtual void* createData() override;
126// 删除数据实例
127//它接受一个指向数据实例的指针data,释放该数据实例占用的资源
128 eProsima_user_DllExport virtual void deleteData(
129 void* data) override;
130
131 #ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
132// 检查数据类型是否有界
133// eProsima_user_DllExport用于在动态链接库(DLL)场景下,使这个函数可以被外部模块使用 inline表示这个函数是内联函数
134 eProsima_user_DllExport inline bool is_bounded() const override
135 {
136 return true;// 表示此数据类型是有界的
137 }
138//预处理器指令的结束部分
139 #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
140
141//一个预处理器指令
142 #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
143// 检查数据类型是否是简单类型
144 eProsima_user_DllExport inline bool is_plain() const override
145 {
146 return is_plain_impl();// 调用实现函数检查
147 }
148//与前面的#ifdef对应,结束条件编译部分
149 #endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
150// 在给定内存中构造 Twist 对象
151 #ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
152 eProsima_user_DllExport inline bool construct_sample(
153// 函数接受一个void*类型的参数memory,这个指针可能指向一块已经分配好的内存区域 表示函数不修改成员变量且重写基类虚函数
154 void* memory) const override
155 {
156 new (memory) Twist();// 在给定内存中构造 Twist 对象
157 return true;// 返回成功
158 }
159
160 #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
161//定义了一个名为m_md5的MD5类型的成员变量 用于处理MD5哈希相关的操作,这个成员变量可能用于存储与数据相关的MD5哈希值
162 MD5 m_md5;// MD5 哈希
163// 定义了一个名为m_keyBuffer的无符号字符指针类型的成员变量
164 unsigned char* m_keyBuffer;// 键缓冲区
165 private:
166// 检查此数据类型是否是简单类型的实现
167 static constexpr bool is_plain_impl()
168 {
169 //detail::Twist_f>() 调用Twist_offset_of函数模传递Twist和detail::Twist_f作为模板参数用于计算Twist类型中与detail::Twist_f相关的偏移量 sizeof(geometry获取geometry相关类型的大小
170 //进行一个比较操作(48ULL是一个无符号长整型常量)
171 return 48ULL == (detail::Twist_offset_of<Twist, detail::Twist_f>() + sizeof(geometry_msgs::msg::Vector3));
172
173 }};
174 }
175}
176
177//一个预处理器指令的结束部分,与前面的#ifndef对应
178#endif // _FAST_DDS_GENERATED_GEOMETRY_MSGS_MSG_TWIST_PUBSUBTYPES_H_
#define eProsima_user_DllExport
Definition CameraInfo.h:44
Traits::size_t size_t
此类表示用户在 IDL 文件中定义的类型 Twist 的 TopicDataType。 <>
static constexpr bool is_plain_impl()
此类表示用户在 IDL 文件中定义的 Vector3 结构。 <>
Definition Vector3.h:72
size_t constexpr Twist_offset_of()
geometry_msgs::msg::Vector3 Twist::* type
friend constexpr type get(Twist_f)
friend constexpr Tag::type get(Tag)