12#ifndef CMSIS_PLUS_POSIX_DRIVER_CIRCULAR_BUFFER_H_
13#define CMSIS_PLUS_POSIX_DRIVER_CIRCULAR_BUFFER_H_
15#if defined(__cplusplus)
54 std::size_t high_water_mark,
55 std::size_t low_water_mark = 0);
167 std::size_t
const size_;
168 std::size_t
const high_water_mark_;
169 std::size_t
const low_water_mark_;
175 std::size_t
volatile len_;
208 template <
typename T>
211 std::size_t high_water_mark,
212 std::size_t low_water_mark)
215 high_water_mark_ (high_water_mark <= size_ ? high_water_mark
217 low_water_mark_ (low_water_mark)
219 assert (low_water_mark_ <= high_water_mark_);
224 template <
typename T>
232 template <
typename T>
240 template <
typename T>
244 back_ = front_ =
const_cast<value_type* volatile
> (buf_);
247 std::memset (
static_cast<void*
> (
const_cast<value_type*
> (buf_)),
'?',
252 template <
typename T>
259 template <
typename T>
266 template <
typename T>
270 return (len_ >= size_);
273 template <
typename T>
278 return (len_ >= high_water_mark_);
281 template <
typename T>
286 return (len_ <= low_water_mark_);
289 template <
typename T>
293 return !above_high_water_mark ();
296 template <
typename T>
300 return !below_low_water_mark ();
303 template <
typename T>
310 template <
typename T>
317 template <
typename T>
328 if (
static_cast<std::size_t
> (back_ - buf_) >= size_)
331 back_ =
const_cast<value_type* volatile
> (buf_);
338 template <
typename T>
342 assert (buf !=
nullptr);
344 std::size_t len = count;
345 if (count > (size_ - len_))
355 std::size_t sizeToEnd =
static_cast<std::size_t
> (
356 size_ -
static_cast<std::size_t
> (back_ - buf_));
357 if (len <= sizeToEnd)
359 std::memcpy (back_, buf, len);
361 if (
static_cast<std::size_t
> (back_ - buf_) >= size_)
364 back_ =
const_cast<value_type* volatile
> (buf_);
370 std::memcpy (back_, buf, sizeToEnd);
371 back_ =
const_cast<value_type* volatile
> (buf_);
372 std::memcpy (back_, buf + sizeToEnd, len - sizeToEnd);
373 back_ += (len - sizeToEnd);
379 template <
typename T>
383 std::size_t adjust = count;
384 if (count > (size_ - len_))
386 adjust = size_ - len_;
395 if (back_ >= (buf_ + size_))
405 template <
typename T>
421 template <
typename T>
425 assert (buf !=
nullptr);
435 if (
static_cast<std::size_t
> (front_ - buf_) >= size_)
437 front_ =
const_cast<value_type* volatile
> (buf_);
445 template <
typename T>
449 assert (buf !=
nullptr);
451 std::size_t len = siz;
457 std::size_t sizeToEnd = size_ -
static_cast<std::size_t
> (front_ - buf_);
458 if (len <= sizeToEnd)
460 std::memcpy (buf, front_, len);
462 if (
static_cast<std::size_t
> (front_ - buf_) >= size_)
464 front_ =
const_cast<value_type* volatile
> (buf_);
470 std::memcpy (buf, front_, sizeToEnd);
471 front_ =
const_cast<value_type* volatile
> (buf_);
472 std::memcpy (buf + sizeToEnd, front_, len - sizeToEnd);
473 front_ += (len - sizeToEnd);
479 template <
typename T>
488 std::size_t adjust = count;
495 if (front_ >= (buf_ + size_))
505 template <
typename T>
509 assert (ppbuf !=
nullptr);
513 std::size_t sizeToEnd = size_ -
static_cast<std::size_t
> (front_ - buf_);
514 std::size_t len = sizeToEnd;
523 template <
typename T>
527 assert (ppbuf !=
nullptr);
531 std::size_t sizeToEnd = size_ -
static_cast<std::size_t
> (back_ - buf_);
532 std::size_t len = sizeToEnd;
533 if (len > (size_ - len_))
541 template <
typename T>
546 __PRETTY_FUNCTION__, buf_, size_, len_,
547 high_water_mark_, low_water_mark_);
Circular buffer class template.<cmsis-plus/posix-driver/circular-buffer.h>
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.