FastArduino
v1.8
C++ library to build fast but small Arduino/AVR projects
|
Go to the documentation of this file.
48 using QUEUE = Queue<char, char>;
56 template<u
int8_t SIZE>
57 explicit ostreambuf(
char (&buffer)[SIZE], CALLBACK callback =
nullptr,
void* arg =
nullptr)
58 : QUEUE{buffer,
true}, on_put_callback_{callback, arg} {}
94 while (
size--)
put_(*content++,
false);
111 while (*str)
put_(*str++,
false);
132 void sputn(
const flash::FlashStorage* str)
134 uint16_t address = (uint16_t) str;
135 while (
char value = pgm_read_byte(address++))
put_(value,
false);
170 void put_(
char c,
bool call_on_put =
true)
172 if (!
push(c)) overflow_ =
true;
173 if (call_on_put) on_put();
191 bool overflow_ =
false;
194 friend class ios_base;
195 friend class ostream;
211 using QUEUE = Queue<char, char>;
220 static const int EOF = -1;
222 template<u
int8_t SIZE>
explicit istreambuf(
char (&buffer)[SIZE]) : QUEUE{buffer,
false} {}
239 if (
pull(value))
return value;
250 if (
peek(value))
return value;
void put_(char c, bool call_on_put=true)
Append a character to the buffer.
uint8_t size() const
Get the maximum size of this queue.
Input API based on a ring buffer.
bool pull(T &item)
Pull an item from the beginning of this queue, if not empty, and copy it into item.
void sputn(const char *str)
Append a string to the buffer.
void(*)(void *) METHOD
The type of function that will get the call.
Output API based on a ring buffer.
void yield()
Utility method used by many FastArduino API in order to "yield" some processor time; concretely it ju...
void reset_overflow()
Reset the overflow flag.
void sputn(const char *content, size_t size)
Append several characters to the buffer.
bool push(TREF item)
Push item to the end of this queue, provided there is still available space in its ring buffer.
uint8_t items() const
Tell the current number of items currently present in this queue.
QUEUE & queue()
Return the underlying queue.
Utility API to handle ring-buffer queue containers.
Holder of a "virtual method".
Defines C++-like streams API, based on circular buffers for input or output.
void sputn(const flash::FlashStorage *str)
Append a string, stored on flash memory, to the buffer.
Small utilities to emulate virtual methods without extra vtabl.
void pubsync()
Wait until all buffer content has been pulled by a consumer.
static const int EOF
Special value returned by sbumpc() when buffer is empty.
void sputc(char c)
Append a character to the buffer.
bool empty() const
Tell if this queue is currently empty.
bool peek(T &item) const
Peek an item from the beginning of this queue, if not empty, and copy it into item.
QUEUE & queue()
Return the underlying queue.
bool overflow() const
Indicate if a buffer overflow has occurred since last time pubsync() or reset_overflow() was called.