49#define REGISTER_OSTREAMBUF_LISTENERS(HANDLER1, ...) \
50 void streams::ostreambuf_on_put_dispatch(ostreambuf& obuf) \
52 streams::dispatch_handler::ostreambuf_on_put<HANDLER1, ##__VA_ARGS__>(obuf);\
64#define REGISTER_OSTREAMBUF_NO_LISTENERS() \
65 void streams::ostreambuf_on_put_dispatch(ostreambuf&) {}
73#define DECL_OSTREAMBUF_LISTENERS_FRIEND \
74 friend struct streams::dispatch_handler;
80 extern void ostreambuf_on_put_dispatch(ostreambuf&);
98 using QUEUE = Queue<char, char>;
105 template<u
int8_t SIZE>
106 explicit ostreambuf(
char (&buffer)[SIZE]) : QUEUE{buffer,
true} {}
143 while (
size--)
put_(*content++,
false);
160 while (*str)
put_(*str++,
false);
181 void sputn(
const flash::FlashStorage* str)
183 uint16_t address = (uint16_t) str;
184 while (
char value = pgm_read_byte(address++))
put_(value,
false);
219 void put_(
char c,
bool call_on_put =
true)
221 if (!
push(c)) overflow_ =
true;
222 if (call_on_put) on_put();
237 ostreambuf_on_put_dispatch(*
this);
240 bool overflow_ =
false;
242 friend class ios_base;
243 friend class ostream;
259 using QUEUE = Queue<char, char>;
268 static const int EOF = -1;
271 template<u
int8_t SIZE>
explicit istreambuf(
char (&buffer)[SIZE]) : QUEUE{buffer, false} {}
289 if (
pull(value))
return value;
300 if (
peek(value))
return value;
315 struct dispatch_handler
317 template<
bool DUMMY_>
static bool ostreambuf_on_put_helper(ostreambuf& obuf
UNUSED)
322 template<
bool DUMMY_,
typename HANDLER1_,
typename... HANDLERS_>
323 static bool ostreambuf_on_put_helper(ostreambuf& obuf)
325 bool result = interrupt::HandlerHolder<HANDLER1_>::handler()->on_put(obuf);
327 return result || ostreambuf_on_put_helper<DUMMY_, HANDLERS_...>(obuf);
330 template<
typename... HANDLERS_>
static void ostreambuf_on_put(ostreambuf& obuf)
333 ostreambuf_on_put_helper<
false, HANDLERS_...>(obuf);
bool pull(T &item)
Pull an item from the beginning of this queue, if not empty, and copy it into item.
bool push(TREF item)
Push item to the end of this queue, provided there is still available space in its ring buffer.
bool empty() const
Tell if this queue is currently empty.
uint8_t size() const
Get the maximum size of this queue.
bool peek(T &item) const
Peek an item from the beginning of this queue, if not empty, and copy it into item.
uint8_t items() const
Tell the current number of items currently present in this queue.
Input API based on a ring buffer.
static const int EOF
Special value returned by sbumpc() when buffer is empty.
QUEUE & queue()
Return the underlying queue.
Output API based on a ring buffer.
void pubsync()
Wait until all buffer content has been pulled by a consumer.
bool overflow() const
Indicate if a buffer overflow has occurred since last time pubsync() or reset_overflow() was called.
void sputn(const char *str)
Append a string to the buffer.
void reset_overflow()
Reset the overflow flag.
void sputn(const flash::FlashStorage *str)
Append a string, stored on flash memory, to the buffer.
void put_(char c, bool call_on_put=true)
Append a character to the buffer.
QUEUE & queue()
Return the underlying queue.
void sputc(char c)
Append a character to the buffer.
void sputn(const char *content, size_t size)
Append several characters to the buffer.
#define UNUSED
Specific GCC attribute to declare an argument or variable unused, so that the compiler does not emit ...
General API for handling AVR interrupt vectors.
Defines C++-like streams API, based on circular buffers for input or output.
void yield()
Utility method used by many FastArduino API in order to "yield" some processor time; concretely it ju...
Utility API to handle ring-buffer queue containers.