FastArduino  v1.7
C++ library to build fast but small Arduino/AVR projects
streams::ostreambuf Class Reference

Output API based on a ring buffer. More...

#include <fastarduino/streambuf.h>

Inheritance diagram for streams::ostreambuf:
Collaboration diagram for streams::ostreambuf:

Public Types

using CALLBACK = virtual_support::VirtualMethod::METHOD
 

Public Member Functions

 ostreambuf (const ostreambuf &)=delete
 
ostreambufoperator= (const ostreambuf &)=delete
 
template<uint8_t SIZE>
 ostreambuf (char(&buffer)[SIZE], CALLBACK callback=nullptr, void *arg=nullptr)
 
void pubsync ()
 Wait until all buffer content has been pulled by a consumer. More...
 
void sputc (char c)
 Append a character to the buffer. More...
 
void sputn (const char *content, size_t size)
 Append several characters to the buffer. More...
 
void sputn (const char *str)
 Append a string to the buffer. More...
 
void sputn (const flash::FlashStorage *str)
 Append a string, stored on flash memory, to the buffer. More...
 
bool overflow () const
 Indicate if a buffer overflow has occurred since last time pubsync() or reset_overflow() was called. More...
 
QUEUE & queue ()
 Return the underlying queue. More...
 

Protected Member Functions

void put_ (char c, bool call_on_put=true)
 Append a character to the buffer. More...
 
void reset_overflow ()
 Reset the overflow flag. More...
 

Friends

class ios_base
 
class ostream
 

Detailed Description

Output API based on a ring buffer.

Provides general methods to push characters or strings to the buffer; the buffer is supposed to be consumed by another class (e.g. serial::hard::UATX). The API provides protected "hooks" that get notified every time new content is successfully pushed to the buffer, or when the buffer is full while new content addition is attempted.

Parameters
bufferthe original ring buffer containing all pushed content; once passed to the constructor, it should never be used directly as it will be consumed by a containers::Queue.
callbacka pointer to function that is called back when data is pushed to this ostreambuf.
argany pointer value that will be passed to callback

Definition at line 45 of file streambuf.h.

Member Function Documentation

◆ pubsync()

void streams::ostreambuf::pubsync ( )
inline

Wait until all buffer content has been pulled by a consumer.

This method clear the count of overflows that have occurred until now.

Definition at line 64 of file streambuf.h.

◆ sputc()

void streams::ostreambuf::sputc ( char  c)
inline

Append a character to the buffer.

If the buffer is full, then overflow() flag will be set.

Parameters
cthe character to append
See also
overflow()

Definition at line 76 of file streambuf.h.

◆ sputn() [1/3]

void streams::ostreambuf::sputn ( const char *  content,
size_t  size 
)
inline

Append several characters to the buffer.

If the buffer is full, then overflow() flag will be set. Once all characters have been appended, on_put() will be called, even if an overflow has occurred.

Parameters
contentthe array of characters to be appended
sizethe number of characters in content to append
See also
on_put()
overflow()

Definition at line 92 of file streambuf.h.

◆ sputn() [2/3]

void streams::ostreambuf::sputn ( const char *  str)
inline

Append a string to the buffer.

The ‘’\0'end character of @p str is not transmitted. If the buffer is full, thenoverflow()flag will be set. Once all string content has been appended,on_put()` will be called, even if an overflow has occurred.

Parameters
strthe '\0' ended string (standard C-string) to append
See also
on_put()
overflow()

Definition at line 109 of file streambuf.h.

◆ sputn() [3/3]

void streams::ostreambuf::sputn ( const flash::FlashStorage *  str)
inline

Append a string, stored on flash memory, to the buffer.

The ‘’\0'end character of @p str is not transmitted. If the buffer is full, thenoverflow()flag will be set. Once all string content has been appended,on_put()` will be called, even if an overflow has occurred. Example:

output.sputn(F("Hello, World!\n"));
Parameters
strthe '\0' ended string (standard C-string), stored on flash, to append
See also
F()
on_put()
overflow()

Definition at line 132 of file streambuf.h.

◆ overflow()

bool streams::ostreambuf::overflow ( ) const
inline

Indicate if a buffer overflow has occurred since last time pubsync() or reset_overflow() was called.

See also
pubsync()
reset_overflow()

Definition at line 145 of file streambuf.h.

◆ queue()

QUEUE& streams::ostreambuf::queue ( )
inline

Return the underlying queue.

Normally you will not need this method.

Definition at line 154 of file streambuf.h.

◆ put_()

void streams::ostreambuf::put_ ( char  c,
bool  call_on_put = true 
)
inlineprotected

Append a character to the buffer.

If the buffer is full, then overflow() flag will be set.

Parameters
cthe character to append
call_on_puttrue if on_put() should be called after c has been appended, false otherwise; when directly calling this method, you should keep the default value.
See also
on_put()
overflow()

Definition at line 170 of file streambuf.h.

◆ reset_overflow()

void streams::ostreambuf::reset_overflow ( )
inlineprotected

Reset the overflow flag.

See also
overflow()

Definition at line 180 of file streambuf.h.


The documentation for this class was generated from the following file:
F
#define F(ptr)
Force string constant to be stored as flash storage.
Definition: flash.h:98