CARLA
 
载入中...
搜索中...
未找到
CarlaPublisher.h
浏览该文件的文档.
1// Copyright (c) 2022 Computer Vision Center (CVC) at the Universitat Autonoma de Barcelona (UAB).
2// This work is licensed under the terms of the MIT license.
3// For a copy, see <https://opensource.org/licenses/MIT>.
4
5#pragma once // 定义全局宏,指定使用 C++11 ABI 版本为 0,可能影响 C++ 标准库的行为,如动态链接库中符号的解析方式等
6#define _GLIBCXX_USE_CXX11_ABI 0
7// 引入 C++ 标准字符串库,用于处理字符串相关操作
8#include <string>
9
10namespace carla {
11namespace ros2 {
12// CarlaPublisher 类定义,作为发布者的基类,为具体类型发布者提供基础框架和通用接口
14 public: // 获取帧 ID 的函数,返回 const 引用,避免不必要的拷贝,且不允许外部修改返回值
15 const std::string& frame_id() const { return _frame_id; } // 获取名称的函数,返回 const 引用,避免拷贝,且不允许外部修改返回值
16 const std::string& name() const { return _name; } // 获取父级名称的函数,返回 const 引用,避免拷贝,且不允许外部修改返回值
17 const std::string& parent() const { return _parent; }
18 // 设置帧 ID 的函数,通过右值引用接受参数,使用 std::move 高效转移资源所有权,避免拷贝
19 void frame_id(std::string&& frame_id) { _frame_id = std::move(frame_id); } // 设置名称的函数,通过右值引用接受参数,使用 std::move 高效转移资源所有权,避免拷贝
20 void name(std::string&& name) { _name = std::move(name); } // 设置父级名称的函数,通过右值引用接受参数,使用 std::move 高效转移资源所有权,避免拷贝
21 void parent(std::string&& parent) { _parent = std::move(parent); }
22 // 纯虚函数,用于获取发布者发布的数据类型,具体类型发布者必须实现此函数
23 virtual const char* type() const = 0;
24
25 public: // 默认构造函数,使用编译器生成的默认构造函数实现
26 CarlaPublisher() = default; // 析构函数,使用编译器生成的默认析构函数实现,析构函数在子类中可能会被重写以释放特定资源
27 virtual ~CarlaPublisher() = default;
28
29 protected: // 存储帧 ID 的字符串成员变量,初始化为空字符串
30 std::string _frame_id = "";//存储名称的字符串成员变量,初始化为空字符串
31 std::string _name = ""; // 存储父级名称的字符串成员变量,初始化为空字符串
32 std::string _parent = "";
33 };
34}
35}
const std::string & parent() const
void parent(std::string &&parent)
virtual ~CarlaPublisher()=default
void name(std::string &&name)
virtual const char * type() const =0
const std::string & frame_id() const
void frame_id(std::string &&frame_id)
const std::string & name() const
CARLA模拟器的主命名空间。
Definition Carla.cpp:139