40 #ifndef __BASE_CIRCLEBUF_HH__
41 #define __BASE_CIRCLEBUF_HH__
104 template <
class OutputIterator>
105 void peek(OutputIterator out,
size_t len)
const {
116 template <
class OutputIterator>
119 "Trying to read past end of circular buffer.\n");
121 const off_t real_start((offset +
_start) %
buf.size());
122 if (real_start + len <=
buf.size()) {
123 std::copy(
buf.begin() + real_start,
124 buf.begin() + real_start +
len,
127 const size_t head_size(
buf.size() - real_start);
128 const size_t tail_size(len - head_size);
129 std::copy(
buf.begin() + real_start,
buf.end(),
131 std::copy(
buf.begin(),
buf.begin() + tail_size,
142 template <
class OutputIterator>
156 template <
class InputIterator>
160 if (len >
buf.size()) {
161 in += len -
buf.size();
165 const size_t next(
_stop %
buf.size());
166 const size_t head_len(std::min(
buf.size() - next,
len));
168 std::copy(in, in + head_len,
buf.begin() + next);
169 std::copy(in + head_len, in + len,
buf.begin());
232 template <
class OutputIterator>
234 template <
class OutputIterator>
237 template <
class InputIterator>
240 "Trying to overfill FIFO buffer.\n");
249 template <
typename T>
255 param.
peek(temp.begin(), temp.size());
259 template <
typename T>
268 param.
write(temp.cbegin(), temp.size());
271 template <
typename T>
277 param.
peek(temp.begin(), temp.size());
281 template <
typename T>
290 "Trying to unserialize data into too small FIFO\n");
293 param.
write(temp.cbegin(), temp.size());
296 #endif // __BASE_CIRCLEBUF_HH__
void write(InputIterator in, size_t len)
size_t size() const
Return the number of elements stored in the buffer.
const std::string & name()
Circular buffer backed by a vector.
void normalize()
Normalize the start and stop pointers to ensure that pointer invariants hold after updates...
bool empty() const
Is the buffer empty?
panic_if(!root,"Invalid expression\n")
CircleBuf< value_type > buf
void peek(OutputIterator out, size_t len) const
void write(InputIterator in, size_t len)
Add elements to the end of the ring buffers and advance.
void arrayParamOut(CheckpointOut &cp, const std::string &name, const CircleBuf< T > ¶m)
void peek(OutputIterator out, size_t len) const
Copy buffer contents without advancing the read pointer.
void flush()
Remove all the elements in the buffer.
void read(OutputIterator out, size_t len)
Copy buffer contents and advance the read pointer.
std::ostream CheckpointOut
std::vector< value_type > buf
void peek(OutputIterator out, off_t offset, size_t len) const
Copy buffer contents without advancing the read pointer.
size_t capacity() const
Return the maximum number of elements that can be stored in the buffer at any one time...
void arrayParamIn(CheckpointIn &cp, const std::string &name, CircleBuf< T > ¶m)
fatal_if(p->js_features.size() > 16,"Too many job slot feature registers specified (%i)\n", p->js_features.size())
void read(OutputIterator out, size_t len)
Simple FIFO implementation backed by a circular buffer.