DUDS
Distributed Update of Data from Something
duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits > Class Template Reference

Writes output from a stream into an internal buffer, and writes that buffer to the display when sync() is called. More...

#include <TextDisplayStream.hpp>

Inheritance diagram for duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >:
Collaboration diagram for duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >:

Public Member Functions

 TextDisplayBasicBufferedStreambuf (const std::shared_ptr< TextDisplay > &d)
 Makes the stream buffer with a display for output. More...
 
virtual void clearDisplay ()
 Remove all text from the display and place the cursor in the upper left corner. More...
 
virtual void clearTo (unsigned int c, unsigned int r)
 Clear text from the current cursor position to the given position, inclusive. More...
 
virtual unsigned int column () const
 Returns the cursos's column position. More...
 
virtual void moveCursor (unsigned int c, unsigned int r)
 Moves the display's cursor to the given location. More...
 
virtual unsigned int row () const
 Returns the cursos's row position. More...
 
virtual void startLine ()
 Moves the cursor to the start of a line clearing text along the way. More...
 
- Public Member Functions inherited from duds::hardware::display::TextDisplayBasicStreambuf< Char, Traits >
 TextDisplayBasicStreambuf (const std::shared_ptr< TextDisplay > &d)
 Makes the stream buffer with a display for output. More...
 
const std::shared_ptr< TextDisplay > & display () const
 Returns the output display. More...
 

Protected Member Functions

virtual Traits::int_type overflow (typename Traits::int_type c=Traits::eof())
 Writes a character to the start of the display after wrapping around from the end. More...
 
virtual base::pos_type seekoff (typename base::off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which=std::ios_base::out)
 
virtual base::pos_type seekpos (typename base::pos_type pos, std::ios_base::openmode which=std::ios_base::out)
 
virtual int sync ()
 
virtual std::streamsize xsputn (const Char *s, std::streamsize count)
 

Private Types

using base = TextDisplayBasicStreambuf< Char, Traits >
 

Private Member Functions

void bufWrite (Char c)
 Handles writing a character into the buffer or moving the cursor for new lines and carriage returns. More...
 
void clearToImpl (unsigned int c, unsigned int r)
 Clears a portion of the buffer with spaces from the current cursor position to the indicated position. More...
 
void write (Char c)
 Internal function to write a printable character to the buffer. More...
 

Private Attributes

std::uint8_t columnsize
 Number of columns on the display. More...
 
std::uint8_t cpos
 Cursor column position. More...
 
std::uint8_t rowsize
 Number of rows on the display. More...
 
std::uint8_t rpos
 Cursor row position. More...
 
std::vector< Char > shown
 The buffer currently shown by the display. More...
 
std::vector< Char > update
 The buffer that is being written to the display. More...
 
duds::general::Spinlock wblock
 Write block. More...
 
std::vector< Char > working
 The buffer that accepts new data. More...
 

Detailed Description

template<class Char, class Traits = std::char_traits<Char>>
class duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >

Writes output from a stream into an internal buffer, and writes that buffer to the display when sync() is called.

Only changes are written to the display, and the display is only updated when sync() is called. Using std::endl with the output stream, or calling flush on the stream, will cause a call to sync().

Thread safety
Objects of this type are thread-safe for the case of exactly two threads: one writing new text, and another thread that flushes the stream (calls sync()). The thread that flushes will handle outputing text changes to the display. The other thread that writes new text will not be stalled by the display output. Using two threads is not a requirement.
Author
Jeff Jackowski

Definition at line 155 of file TextDisplayStream.hpp.

Member Typedef Documentation

◆ base

template<class Char, class Traits = std::char_traits<Char>>
using duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::base = TextDisplayBasicStreambuf<Char, Traits>
private

Definition at line 157 of file TextDisplayStream.hpp.

Constructor & Destructor Documentation

◆ TextDisplayBasicBufferedStreambuf()

template<class Char, class Traits = std::char_traits<Char>>
duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::TextDisplayBasicBufferedStreambuf ( const std::shared_ptr< TextDisplay > &  d)
inline

Makes the stream buffer with a display for output.

Parameters
dThe display that will take the output.
Precondition
The display is initialzied and ready to accept data.

Definition at line 356 of file TextDisplayStream.hpp.

Member Function Documentation

◆ bufWrite()

template<class Char, class Traits = std::char_traits<Char>>
void duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::bufWrite ( Char  c)
inlineprivate

Handles writing a character into the buffer or moving the cursor for new lines and carriage returns.

Definition at line 232 of file TextDisplayStream.hpp.

◆ clearDisplay()

template<class Char, class Traits = std::char_traits<Char>>
virtual void duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::clearDisplay ( )
inlinevirtual

Remove all text from the display and place the cursor in the upper left corner.

Reimplemented from duds::hardware::display::TextDisplayBasicStreambuf< Char, Traits >.

Definition at line 387 of file TextDisplayStream.hpp.

◆ clearTo()

template<class Char, class Traits = std::char_traits<Char>>
virtual void duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::clearTo ( unsigned int  c,
unsigned int  r 
)
inlinevirtual

Clear text from the current cursor position to the given position, inclusive.

The cursor will be moved to the spot immediately after the given position.

Parameters
cThe end column.
rThe end row.
Exceptions
TextDisplayRangeErrorThe requested position is beyond the display's boundries.

Reimplemented from duds::hardware::display::TextDisplayBasicStreambuf< Char, Traits >.

Definition at line 395 of file TextDisplayStream.hpp.

◆ clearToImpl()

template<class Char, class Traits = std::char_traits<Char>>
void duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::clearToImpl ( unsigned int  c,
unsigned int  r 
)
inlineprivate

Clears a portion of the buffer with spaces from the current cursor position to the indicated position.

The cursor will be moved to the spot immediately after the given position.

Precondition
The given position is within the bounds of the display.
Parameters
cThe end column.
rThe end row.

Definition at line 222 of file TextDisplayStream.hpp.

◆ column()

template<class Char, class Traits = std::char_traits<Char>>
virtual unsigned int duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::column ( ) const
inlinevirtual

Returns the cursos's column position.

Reimplemented from duds::hardware::display::TextDisplayBasicStreambuf< Char, Traits >.

Definition at line 367 of file TextDisplayStream.hpp.

◆ moveCursor()

template<class Char, class Traits = std::char_traits<Char>>
virtual void duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::moveCursor ( unsigned int  c,
unsigned int  r 
)
inlinevirtual

Moves the display's cursor to the given location.

Parameters
cThe destination column.
rThe destination row.
Exceptions
TextDisplayRangeErrorThe requested position is beyond the display's boundries.

Reimplemented from duds::hardware::display::TextDisplayBasicStreambuf< Char, Traits >.

Definition at line 373 of file TextDisplayStream.hpp.

◆ overflow()

template<class Char, class Traits = std::char_traits<Char>>
virtual Traits::int_type duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::overflow ( typename Traits::int_type  c = Traits::eof())
inlineprotectedvirtual

Writes a character to the start of the display after wrapping around from the end.

Reimplemented from duds::hardware::display::TextDisplayBasicStreambuf< Char, Traits >.

Definition at line 255 of file TextDisplayStream.hpp.

◆ row()

template<class Char, class Traits = std::char_traits<Char>>
virtual unsigned int duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::row ( ) const
inlinevirtual

Returns the cursos's row position.

Reimplemented from duds::hardware::display::TextDisplayBasicStreambuf< Char, Traits >.

Definition at line 370 of file TextDisplayStream.hpp.

◆ seekoff()

template<class Char, class Traits = std::char_traits<Char>>
virtual base::pos_type duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::seekoff ( typename base::off_type  off,
std::ios_base::seekdir  dir,
std::ios_base::openmode  which = std::ios_base::out 
)
inlineprotectedvirtual

Definition at line 306 of file TextDisplayStream.hpp.

◆ seekpos()

template<class Char, class Traits = std::char_traits<Char>>
virtual base::pos_type duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::seekpos ( typename base::pos_type  pos,
std::ios_base::openmode  which = std::ios_base::out 
)
inlineprotectedvirtual

Definition at line 344 of file TextDisplayStream.hpp.

◆ startLine()

template<class Char, class Traits = std::char_traits<Char>>
virtual void duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::startLine ( )
inlinevirtual

Moves the cursor to the start of a line clearing text along the way.

If the cursor is already at the start of a line, it will not move and no text will be cleared.

Reimplemented from duds::hardware::display::TextDisplayBasicStreambuf< Char, Traits >.

Definition at line 406 of file TextDisplayStream.hpp.

◆ sync()

template<class Char, class Traits = std::char_traits<Char>>
virtual int duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::sync ( )
inlineprotectedvirtual

Definition at line 272 of file TextDisplayStream.hpp.

◆ write()

template<class Char, class Traits = std::char_traits<Char>>
void duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::write ( Char  c)
inlineprivate

Internal function to write a printable character to the buffer.

Definition at line 199 of file TextDisplayStream.hpp.

◆ xsputn()

template<class Char, class Traits = std::char_traits<Char>>
virtual std::streamsize duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::xsputn ( const Char *  s,
std::streamsize  count 
)
inlineprotectedvirtual

Definition at line 265 of file TextDisplayStream.hpp.

Member Data Documentation

◆ columnsize

template<class Char, class Traits = std::char_traits<Char>>
std::uint8_t duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::columnsize
private

Number of columns on the display.

Sizes included here because they reduce calls to the display through a shared pointer, and 4 byte memory alignment prevents their inclusion from needing more memory.

Definition at line 180 of file TextDisplayStream.hpp.

◆ cpos

template<class Char, class Traits = std::char_traits<Char>>
std::uint8_t duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::cpos
private

Cursor column position.

Definition at line 191 of file TextDisplayStream.hpp.

◆ rowsize

template<class Char, class Traits = std::char_traits<Char>>
std::uint8_t duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::rowsize
private

Number of rows on the display.

Sizes included here because they reduce calls to the display through a shared pointer, and 4 byte memory alignment prevents their inclusion from needing more memory.

Definition at line 187 of file TextDisplayStream.hpp.

◆ rpos

template<class Char, class Traits = std::char_traits<Char>>
std::uint8_t duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::rpos
private

Cursor row position.

Definition at line 195 of file TextDisplayStream.hpp.

◆ shown

template<class Char, class Traits = std::char_traits<Char>>
std::vector<Char> duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::shown
private

The buffer currently shown by the display.

Definition at line 161 of file TextDisplayStream.hpp.

◆ update

template<class Char, class Traits = std::char_traits<Char>>
std::vector<Char> duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::update
private

The buffer that is being written to the display.

Definition at line 165 of file TextDisplayStream.hpp.

◆ wblock

template<class Char, class Traits = std::char_traits<Char>>
duds::general::Spinlock duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::wblock
private

Write block.

Definition at line 173 of file TextDisplayStream.hpp.

◆ working

template<class Char, class Traits = std::char_traits<Char>>
std::vector<Char> duds::hardware::display::TextDisplayBasicBufferedStreambuf< Char, Traits >::working
private

The buffer that accepts new data.

Definition at line 169 of file TextDisplayStream.hpp.


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