Noiasca Buffer Print
Print to an internal buffer
Public Member Functions | Protected Attributes | List of all members
NoiascaBufferPrint Class Referenceabstract

#include <NoiascaBufferPrint.h>

Public Member Functions

virtual size_t write (uint8_t)=0
 similar functionality like in the default Print.h library. More...
 
size_t add (uint8_t value)
 puf a single value (one character) in to the internal buffer More...
 
size_t print (int, int=DEC, bool=true)
 print an integer to the buffer More...
 
virtual void flush ()=0
 final method to flush data to the interface More...
 
size_t getBufferLength ()
 how many bytes are currently in the buffer More...
 
int setBufferLength (size_t)
 set actual index More...
 
int resetBuffer ()
 reset the internal buffer to zero More...
 
int setFlushAfter (size_t)
 set value when to flush More...
 

Protected Attributes

char internal [buffersize]
 the internal buffered stream More...
 

Detailed Description

class to print into a buffer

Member Function Documentation

◆ write()

virtual size_t NoiascaBufferPrint::write ( uint8_t  )
pure virtual

similar functionality like in the default Print.h library.

write() is used for the bytewise output to your class. write() doesn't use the internal buffer - but you could implement that in your class.

Note
You must implement this function in your derived class (compareable with using Print.h).

◆ add()

size_t NoiascaBufferPrint::add ( uint8_t  value)
inline

puf a single value (one character) in to the internal buffer

Adds the value to the internal buffer. By default add() doesn't generate output.

Parameters
valuethe value to be added to the buffer

◆ print()

size_t NoiascaBufferPrint::print ( int  n,
int  base = DEC,
bool  finalFlush = true 
)

print an integer to the buffer

All print() and println() variants from the Print.h are available. All functions can take an additional parameter finalFlush which can be set to false to avoid flush after the print.

  • Call the println() without parameter and use its implizit finalFlush (true) instead of println(false) and a separate.
  • Call println(false) and use an explizit flush() to flush the buffer content.

This enables one to add several println into the buffer. You only have to set the finalflush to false and can continue to fill the buffer. If the size of the buffer or the set limit is reached, print will flush the stream to your interface.

Parameters
nthe integer
baseformat DEC, BIN, OCT or HEX
finalFlushautoflush after last digit

◆ flush()

virtual void NoiascaBufferPrint::flush ( )
pure virtual

final method to flush data to the interface

Note
You must implement this function in your class.

◆ getBufferLength()

size_t NoiascaBufferPrint::getBufferLength ( )

how many bytes are currently in the buffer

Returns the actual bytes in the internal buffer. Use this function in your implementation of flush() to determine, how many bytes should be streamed to your interface.

Returns
actual bytes in buffer

◆ setBufferLength()

int NoiascaBufferPrint::setBufferLength ( size_t  newValue)

set actual index

sets the actual position in the buffer

Returns
0 on success
Parameters
newValuethe new actual position in the buffer

◆ resetBuffer()

int NoiascaBufferPrint::resetBuffer ( )

reset the internal buffer to zero

Call this function at the end of your implementation of add() to reset the internal buffer to 0.

Returns
0 on success

◆ setFlushAfter()

int NoiascaBufferPrint::setFlushAfter ( size_t  newValue)

set value when to flush

By default the internal buffer is 64 bytes and therefore the buffer will be flushed after 64 bytes latest. If you have an interface which can't handle a stream of 64 bytes, you can reduce the limit to your need.

Returns
0 on success
Parameters
newValuethe new limit to excecute a auto flush

Member Data Documentation

◆ internal

char NoiascaBufferPrint::internal[buffersize]
protected

the internal buffered stream

This array contains the buffered bytes - the stream to be outputed on next flush(). Use this internal buffer together with getBufferLength() to evaluate the correct length of valid bytes.