CARLA
 
载入中...
搜索中...
未找到
test/Buffer.h
浏览该文件的文档.
1// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
9#include <carla/Buffer.h>
10
11#include <algorithm>
12#include <memory>
13#include <ostream>
14#include <string>
15
16namespace util {
17namespace buffer {
18
19 using carla::Buffer;
20
21 using shared_buffer = std::shared_ptr<Buffer>;
22 using const_shared_buffer = std::shared_ptr<const Buffer>;
23
24 static inline shared_buffer make_empty(size_t size = 0u) {
25 return size == 0u ?
26 std::make_shared<Buffer>() :
27 std::make_shared<Buffer>(size);
28 }
29
30 shared_buffer make_random(size_t size);
31
32 template <typename T>
33 static inline shared_buffer make(const T &buffer) {
34 return std::make_shared<Buffer>(boost::asio::buffer(buffer));
35 }
36
37 static inline std::string as_string(const Buffer &buf) {
38 return {reinterpret_cast<const char *>(buf.data()), buf.size()};
39 }
40
41 std::string to_hex_string(const Buffer &buf, size_t length = 16u);
42
43} // namespace buffer
44} // namespace util
45
46namespace carla {
47
48 static inline std::ostream &operator<<(std::ostream &out, const Buffer &buf) {
49 out << "[" << buf.size() << " bytes] " << util::buffer::to_hex_string(buf);
50 return out;
51 }
52
53 static inline bool operator==(const Buffer &lhs, const Buffer &rhs) {
54 return
55 (lhs.size() == rhs.size()) &&
56 std::equal(lhs.begin(), lhs.end(), rhs.begin());
57 }
58
59 static inline bool operator!=(const Buffer &lhs, const Buffer &rhs) {
60 return !(lhs == rhs);
61 }
62
63} // namespace carla
A piece of raw data.
const_iterator begin() const noexcept
const value_type * data() const noexcept
Direct access to the allocated memory or nullptr if no memory is allocated.
size_type size() const noexcept
const_iterator end() const noexcept
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
static std::ostream & operator<<(std::ostream &out, const Buffer &buf)
Definition test/Buffer.h:48
static bool operator==(const Buffer &lhs, const Buffer &rhs)
Definition test/Buffer.h:53
static bool operator!=(const Buffer &lhs, const Buffer &rhs)
Definition test/Buffer.h:59
static std::string as_string(const Buffer &buf)
Definition test/Buffer.h:37
static shared_buffer make_empty(size_t size=0u)
Definition test/Buffer.h:24
std::shared_ptr< Buffer > shared_buffer
Definition test/Buffer.h:21
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:22
static shared_buffer make(const T &buffer)
Definition test/Buffer.h:33