UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
write_buffer.hpp
1
42#ifndef UFO_UTILITY_WRITE_BUFFER_HPP
43#define UFO_UTILITY_WRITE_BUFFER_HPP
44
45// UFO
46#include <ufo/utility/io/base_buffer.hpp>
47#include <ufo/utility/io/dir.hpp>
48
49// STL
50#include <cstddef>
51#include <istream>
52#include <memory>
53
54namespace ufo
55{
56class WriteBuffer : virtual public BaseBuffer
57{
58 public:
59 using size_type = BaseBuffer::size_type;
60 using pos_type = BaseBuffer::pos_type;
61 using offset_type = BaseBuffer::offset_type;
62
63 WriteBuffer() = default;
64 WriteBuffer(WriteBuffer const& other);
65 WriteBuffer(WriteBuffer&&) = default;
66
67 WriteBuffer& operator=(WriteBuffer const& rhs);
68 WriteBuffer& operator=(WriteBuffer&&) = default;
69
70 virtual ~WriteBuffer() = default;
71
72 template <class T>
73 WriteBuffer& write(T const& t)
74 {
75 return write(&t, sizeof(t));
76 }
77
78 WriteBuffer& write(void const* src, size_type count);
79
80 WriteBuffer& write(std::istream& in, size_type count);
81
82 template <class T>
83 void writeAt(pos_type pos, T const& t)
84 {
85 writeAt(pos, &t, sizeof(t));
86 }
87
88 void writeAt(pos_type pos, void const* src, size_type count);
89
90 void writeAt(pos_type pos, std::istream& in, size_type count);
91
92 template <class T>
93 void writeAt(offset_type off, IODir dir, T const& t)
94 {
95 writeAt(off, dir, &t, sizeof(t));
96 }
97
98 void writeAt(offset_type off, IODir dir, void const* src, size_type count);
99
100 void writeAt(offset_type off, IODir dir, std::istream& in, size_type count);
101
102 void reserve(size_type new_cap);
103
104 virtual void clear();
105
106 [[nodiscard]] std::byte* data();
107
108 [[nodiscard]] size_type capacity() const noexcept;
109
110 [[nodiscard]] pos_type writePos() const noexcept;
111
112 WriteBuffer& writeSeek(pos_type pos) noexcept;
113
114 WriteBuffer& writeSeek(offset_type off, IODir dir) noexcept;
115
116 template <class T>
117 WriteBuffer& writeSeek(T const& t, pos_type count) noexcept
118 {
119 return writeSeek(sizeof(t) * count);
120 }
121
122 template <class T>
123 WriteBuffer& writeSeek(T const& t, offset_type count_signed, IODir dir) noexcept
124 {
125 return writeSeek(sizeof(t) * count_signed, dir);
126 }
127
128 [[nodiscard]] size_type writeLeft() const noexcept;
129
130 protected:
131 struct FreeDeleter {
132 void operator()(void* p) const noexcept { std::free(p); }
133 };
134
135 std::unique_ptr<std::byte, FreeDeleter> data_;
136 size_type size_{};
137 size_type cap_{};
138 pos_type pos_{};
139};
140} // namespace ufo
141#endif // UFO_UTILITY_WRITE_BUFFER_HPP
All vision-related classes and functions.
Definition cloud.hpp:49