28#ifndef CMSIS_PLUS_POSIX_DRIVER_CIRCULAR_BUFFER_H_
29#define CMSIS_PLUS_POSIX_DRIVER_CIRCULAR_BUFFER_H_
31#if defined(__cplusplus)
71 std::size_t high_water_mark,
72 std::size_t low_water_mark = 0);
184 std::size_t
const size_;
185 std::size_t
const high_water_mark_;
186 std::size_t
const low_water_mark_;
192 std::size_t
volatile len_;
228 std::size_t high_water_mark,
229 std::size_t low_water_mark) :
232 high_water_mark_ (high_water_mark <= size_ ? high_water_mark : siz),
233 low_water_mark_ (low_water_mark)
235 assert (low_water_mark_ <= high_water_mark_);
261 back_ = front_ =
const_cast<value_type*
volatile > (buf_);
264 std::memset (
static_cast<void*
> (
const_cast<value_type*
> (buf_)),
'?',
287 return (len_ >= size_);
295 return (len_ >= high_water_mark_);
303 return (len_ <= low_water_mark_);
310 return !above_high_water_mark ();
317 return !below_low_water_mark ();
345 if (
static_cast<std::size_t
> (back_ - buf_) >= size_)
348 back_ =
const_cast<value_type*
volatile > (buf_);
359 assert (buf !=
nullptr);
361 std::size_t len = count;
362 if (count > (size_ - len_))
372 std::size_t sizeToEnd =
static_cast<std::size_t
> (size_
373 -
static_cast<std::size_t
> (back_ - buf_));
374 if (len <= sizeToEnd)
376 std::memcpy (back_, buf, len);
378 if (
static_cast<std::size_t
> (back_ - buf_) >= size_)
381 back_ =
const_cast<value_type*
volatile > (buf_);
387 std::memcpy (back_, buf, sizeToEnd);
388 back_ =
const_cast<value_type*
volatile > (buf_);
389 std::memcpy (back_, buf + sizeToEnd, len - sizeToEnd);
390 back_ += (len - sizeToEnd);
400 std::size_t adjust = count;
401 if (count > (size_ - len_))
403 adjust = size_ - len_;
412 if (back_ >= (buf_ + size_))
442 assert (buf !=
nullptr);
452 if (
static_cast<std::size_t
> (front_ - buf_) >= size_)
454 front_ =
const_cast<value_type*
volatile > (buf_);
466 assert (buf !=
nullptr);
468 std::size_t len = siz;
474 std::size_t sizeToEnd = size_
475 -
static_cast<std::size_t
> (front_ - buf_);
476 if (len <= sizeToEnd)
478 std::memcpy (buf, front_, len);
480 if (
static_cast<std::size_t
> (front_ - buf_) >= size_)
482 front_ =
const_cast<value_type*
volatile > (buf_);
488 std::memcpy (buf, front_, sizeToEnd);
489 front_ =
const_cast<value_type*
volatile > (buf_);
490 std::memcpy (buf + sizeToEnd, front_, len - sizeToEnd);
491 front_ += (len - sizeToEnd);
506 std::size_t adjust = count;
513 if (front_ >= (buf_ + size_))
527 assert (ppbuf !=
nullptr);
531 std::size_t sizeToEnd = size_
532 -
static_cast<std::size_t
> (front_ - buf_);
533 std::size_t len = sizeToEnd;
546 assert (ppbuf !=
nullptr);
550 std::size_t sizeToEnd = size_ -
static_cast<std::size_t
> (back_ - buf_);
551 std::size_t len = sizeToEnd;
552 if (len > (size_ - len_))
565 __PRETTY_FUNCTION__, buf_, size_, len_,
566 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.