13#ifndef CMSIS_PLUS_POSIX_DRIVER_CIRCULAR_BUFFER_H_
14#define CMSIS_PLUS_POSIX_DRIVER_CIRCULAR_BUFFER_H_
16#if defined(__cplusplus)
56 std::size_t high_water_mark,
57 std::size_t low_water_mark = 0);
169 std::size_t
const size_;
170 std::size_t
const high_water_mark_;
171 std::size_t
const low_water_mark_;
177 std::size_t
volatile len_;
213 std::size_t high_water_mark,
214 std::size_t low_water_mark) :
217 high_water_mark_ (high_water_mark <= size_ ? high_water_mark : siz),
218 low_water_mark_ (low_water_mark)
220 assert (low_water_mark_ <= high_water_mark_);
246 back_ = front_ =
const_cast<value_type*
volatile > (buf_);
249 std::memset (
static_cast<void*
> (
const_cast<value_type*
> (buf_)),
'?',
272 return (len_ >= size_);
280 return (len_ >= high_water_mark_);
288 return (len_ <= low_water_mark_);
295 return !above_high_water_mark ();
302 return !below_low_water_mark ();
330 if (
static_cast<std::size_t
> (back_ - buf_) >= size_)
333 back_ =
const_cast<value_type*
volatile > (buf_);
344 assert (buf !=
nullptr);
346 std::size_t len = count;
347 if (count > (size_ - len_))
357 std::size_t sizeToEnd =
static_cast<std::size_t
> (size_
358 -
static_cast<std::size_t
> (back_ - buf_));
359 if (len <= sizeToEnd)
361 std::memcpy (back_, buf, len);
363 if (
static_cast<std::size_t
> (back_ - buf_) >= size_)
366 back_ =
const_cast<value_type*
volatile > (buf_);
372 std::memcpy (back_, buf, sizeToEnd);
373 back_ =
const_cast<value_type*
volatile > (buf_);
374 std::memcpy (back_, buf + sizeToEnd, len - sizeToEnd);
375 back_ += (len - sizeToEnd);
385 std::size_t adjust = count;
386 if (count > (size_ - len_))
388 adjust = size_ - len_;
397 if (back_ >= (buf_ + size_))
427 assert (buf !=
nullptr);
437 if (
static_cast<std::size_t
> (front_ - buf_) >= size_)
439 front_ =
const_cast<value_type*
volatile > (buf_);
451 assert (buf !=
nullptr);
453 std::size_t len = siz;
459 std::size_t sizeToEnd = size_
460 -
static_cast<std::size_t
> (front_ - buf_);
461 if (len <= sizeToEnd)
463 std::memcpy (buf, front_, len);
465 if (
static_cast<std::size_t
> (front_ - buf_) >= size_)
467 front_ =
const_cast<value_type*
volatile > (buf_);
473 std::memcpy (buf, front_, sizeToEnd);
474 front_ =
const_cast<value_type*
volatile > (buf_);
475 std::memcpy (buf + sizeToEnd, front_, len - sizeToEnd);
476 front_ += (len - sizeToEnd);
491 std::size_t adjust = count;
498 if (front_ >= (buf_ + size_))
512 assert (ppbuf !=
nullptr);
516 std::size_t sizeToEnd = size_
517 -
static_cast<std::size_t
> (front_ - buf_);
518 std::size_t len = sizeToEnd;
531 assert (ppbuf !=
nullptr);
535 std::size_t sizeToEnd = size_ -
static_cast<std::size_t
> (back_ - buf_);
536 std::size_t len = sizeToEnd;
537 if (len > (size_ - len_))
550 __PRETTY_FUNCTION__, buf_, size_, len_,
551 high_water_mark_, low_water_mark_);
Circular buffer class template.
std::size_t pop_front(value_type *buf)
std::size_t back_contiguous_buffer(value_type **ppbuf)
bool below_high_water_mark(void) const
std::size_t advance_front(std::size_t count)
std::size_t size(void) const
circular_buffer(const value_type *buf, std::size_t size, std::size_t high_water_mark, std::size_t low_water_mark=0)
std::size_t front_contiguous_buffer(value_type **ppbuf)
bool below_low_water_mark(void) const
bool above_high_water_mark(void) const
T value_type
Standard type definition.
std::size_t push_back(value_type v)
bool above_low_water_mark(void) const
const value_type & operator[](std::size_t idx) const
std::size_t advance_back(std::size_t count)
std::size_t length(void) const
int printf(const char *format,...)
Write a formatted string to the trace device.