FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
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 Member Functions

 ostreambuf (const ostreambuf &)=delete
 
ostreambufoperator= (const ostreambuf &)=delete
 
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 a protected "hook" (virtual on_put()) 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.

Definition at line 95 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 113 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 125 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 141 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 158 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"));
#define F(ptr)
Force string constant to be stored as flash storage.
Definition: flash.h:150
Parameters
strthe '\0' ended string (standard C-string), stored on flash, to append
See also
F()
on_put()
overflow()

Definition at line 181 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 194 of file streambuf.h.

◆ queue()

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

Return the underlying queue.

Normally you will not need this method.

Definition at line 203 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 219 of file streambuf.h.

◆ reset_overflow()

void streams::ostreambuf::reset_overflow ( )
inlineprotected

Reset the overflow flag.

See also
overflow()

Definition at line 229 of file streambuf.h.

Friends And Related Function Documentation

◆ ios_base

friend class ios_base
friend

Definition at line 242 of file streambuf.h.

◆ ostream

friend class ostream
friend

Definition at line 243 of file streambuf.h.


The documentation for this class was generated from the following file: