30 #ifndef FOREIGN_FIFO_BUFFER_HXX
31 #define FOREIGN_FIFO_BUFFER_HXX
65 :head(0), tail(0), capacity(0), data(n) {}
68 :head(0), tail(0), capacity(_capacity), data(_data) {}
71 :head(src.head), tail(src.tail),
72 capacity(src.capacity), data(src.data) {
79 capacity = src.capacity;
86 std::swap(head, other.
head);
87 std::swap(tail, other.
tail);
89 std::swap(data, other.
data);
93 return data ==
nullptr;
115 assert(_data !=
nullptr);
116 assert(_capacity > 0);
119 capacity = _capacity;
124 assert(new_capacity >= tail - head);
126 std::move(data + head, data + tail, new_data);
128 capacity = new_capacity;
142 return head == 0 && tail ==
capacity;
152 else if (tail == capacity)
155 return Range(data + tail, capacity - tail);
159 if (tail + n <= capacity)
163 const size_type in_use = tail -
head;
164 const size_type required_capacity = in_use + n;
165 if (required_capacity > capacity)
169 assert(tail + n <= capacity);
178 assert(tail <= capacity);
179 assert(n <= capacity);
180 assert(tail + n <= capacity);
194 return Range(data + head, tail - head);
201 assert(tail <= capacity);
202 assert(head <= tail);
204 assert(head + n <= tail);
209 size_type
Read(pointer_type p, size_type n) {
213 std::copy_n(range.data, n, p);
226 size_t n = std::min(r.size, w.size);
228 std::move(r.data, r.data + n, w.data);
239 assert(head <= capacity);
240 assert(tail <= capacity);
241 assert(tail >= head);
243 std::move(data + head, data + tail, data);
void Swap(ForeignFifoBuffer< T > &other)
ForeignFifoBuffer(ForeignFifoBuffer &&src)
void MoveBuffer(T *new_data, size_type new_capacity)
size_type Read(pointer_type p, size_type n)
constexpr ForeignFifoBuffer(std::nullptr_t n)
Range::pointer_type pointer_type
A reference to a memory area that is writable.
bool WantWrite(size_type n)
void Consume(size_type n)
Marks a chunk as consumed.
constexpr bool IsEmpty() const
constexpr bool IsNull() const
constexpr size_type GetAvailable() const
constexpr bool IsFull() const
ForeignFifoBuffer & operator=(ForeignFifoBuffer &&src)
Range::const_pointer_type const_pointer_type
constexpr size_type GetCapacity() const
Range Write()
Prepares writing.
A first-in-first-out buffer: you can append data at the end, and read data from the beginning...
constexpr bool IsDefined() const
void SetBuffer(T *_data, size_type _capacity)
constexpr Range Read() const
Return a buffer range which may be read.
constexpr ForeignFifoBuffer(T *_data, size_type _capacity)
void Append(size_type n)
Expands the tail of the buffer, after data has been written to the buffer returned by write()...
size_type MoveFrom(ForeignFifoBuffer< T > &src)
Move as much data as possible from the specified buffer.
const T * const_pointer_type
WritableBuffer< T > Range