CARLA
 
载入中...
搜索中...
未找到
test/Buffer.h
浏览该文件的文档.
1// 版权所有 (c) 2017 Universitat Autonoma 计算机视觉中心 (CVC)
2// 巴塞罗那 (UAB)。
3//
4// 本作品根据 MIT 许可证的条款进行许可。
5//有关副本,请参阅 <https://opensource.org/licenses/MIT>。
6
7#pragma once
8// 引入 carla 的 Buffer 类
9#include <carla/Buffer.h>
10// 引入一些标准库头文件和 boost 的 asio 库头文件
11#include <algorithm>
12#include <memory>
13#include <ostream>
14#include <string>
15// 定义一个命名空间 util,用于存放实用工具函数
16namespace util {
17// 在 util 命名空间下再定义一个命名空间 buffer,用于存放与缓冲区相关的工具函数
18namespace buffer {
19// 使用 carla 命名空间中的 Buffer 类
20 using carla::Buffer;
21// 定义两个类型别名,分别是指向 Buffer 的共享指针和指向常量 Buffer 的共享指针
22 using shared_buffer = std::shared_ptr<Buffer>;
23 using const_shared_buffer = std::shared_ptr<const Buffer>;
24// 静态内联函数,创建一个空的共享指针指向的 Buffer,如果指定了大小则创建指定大小的 Buffer
25 static inline shared_buffer make_empty(size_t size = 0u) {
26 return size == 0u ?
27 std::make_shared<Buffer>() :
28 std::make_shared<Buffer>(size);
29 }
30// 声明一个函数,用于创建随机内容的 Buffer
31 shared_buffer make_random(size_t size);
32// 模板函数,将一个给定的缓冲区对象转换为共享指针指向的 Buffer
33 template <typename T>
34 static inline shared_buffer make(const T &buffer) {
35 return std::make_shared<Buffer>(boost::asio::buffer(buffer));
36 }
37// 将一个 Buffer 对象转换为字符串
38 static inline std::string as_string(const Buffer &buf) {
39 return {reinterpret_cast<const char *>(buf.data()), buf.size()};
40 }
41// 将一个 Buffer 对象转换为十六进制字符串,可指定输出的长度
42 std::string to_hex_string(const Buffer &buf, size_t length = 16u);
43
44} //命名空间缓冲区
45} // 命名空间实用程序
46// 为 carla 命名空间定义输出流操作符重载
47namespace carla {
48// 重载输出流操作符,用于将 Buffer 对象输出到输出流中
49 static inline std::ostream &operator<<(std::ostream &out, const Buffer &buf) {
50 out << "[" << buf.size() << " bytes] " << util::buffer::to_hex_string(buf);
51 return out;
52 }
53// 重载相等操作符,用于比较两个 Buffer 对象是否相等
54 static inline bool operator==(const Buffer &lhs, const Buffer &rhs) {
55 return
56 (lhs.size() == rhs.size()) &&
57 std::equal(lhs.begin(), lhs.end(), rhs.begin());
58 }
59// 重载不等操作符,用于比较两个 Buffer 对象是否不相等
60 static inline bool operator!=(const Buffer &lhs, const Buffer &rhs) {
61 return !(lhs == rhs);
62 }
63
64} //命名空间 carla
一块原始数据。 请注意,如果需要更多容量,则会分配一个新的内存块,并 删除旧的内存块。这意味着默认情况下,缓冲区只能增长。要释放内存,使用 clear 或 pop。
const_iterator begin() const noexcept
const value_type * data() const noexcept
直接访问分配的内存,如果没有分配内存则返回 nullptr。
size_type size() const noexcept
const_iterator end() const noexcept
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
static std::ostream & operator<<(std::ostream &out, const Buffer &buf)
Definition test/Buffer.h:49
static bool operator==(const Buffer &lhs, const Buffer &rhs)
Definition test/Buffer.h:54
static bool operator!=(const Buffer &lhs, const Buffer &rhs)
Definition test/Buffer.h:60
static std::string as_string(const Buffer &buf)
Definition test/Buffer.h:38
static shared_buffer make_empty(size_t size=0u)
Definition test/Buffer.h:25
std::shared_ptr< Buffer > shared_buffer
Definition test/Buffer.h:22
std::string to_hex_string(const Buffer &buf, size_t length)
shared_buffer make_random(size_t size)
std::shared_ptr< const Buffer > const_shared_buffer
Definition test/Buffer.h:23
static shared_buffer make(const T &buffer)
Definition test/Buffer.h:34