COSA
An Object-Oriented Platform for Arduino Programming
IOStream Class Reference

#include <IOStream.hh>

Inheritance diagram for IOStream:
Inheritance graph
Collaboration diagram for IOStream:
Collaboration graph

Classes

class  Device
 

Public Types

enum  Base {
  bcd = 0, bin = 2, oct = 8, dec = 10,
  hex = 16
}
 
enum  Mode { CR_MODE = 0, LF_MODE = 1, CRLF_MODE = 2 }
 
typedef IOStream &(* Manipulator) (IOStream &)
 

Public Member Functions

 IOStream (Device *dev)
 
 IOStream ()
 
Devicedevice () const
 
Devicedevice (Device *dev)
 
str_P eol () const
 
str_P EOL () const
 
void eol (str_P s)
 
int8_t width (int8_t value)
 
uint8_t precision (uint8_t value)
 
void print (int value, Base base=dec)
 
void print (long int value, Base base=dec)
 
void print (unsigned int value, Base base=dec)
 
void print (unsigned long int value, Base base=dec)
 
void print (unsigned int value, uint8_t digits, Base base)
 
void print (unsigned long int value, uint8_t digits, Base base)
 
void print (double value, int8_t width, uint8_t prec)
 
void print (uint32_t src, const void *ptr, size_t size, Base base=dec, uint8_t max=16)
 
void print (const void *ptr, size_t size, Base base=dec, uint8_t max=16)
 
void print (void *ptr)
 
void print (const void *ptr)
 
void print (char c)
 
void print (const char *s)
 
void print (str_P s)
 
void println ()
 
void vprintf (str_P format, va_list args)
 
void printf (str_P format,...)
 
void print (IOStream::Device *buffer)
 
void flush ()
 
char * scan (char *s, size_t count)
 
char * readline (char *buf, size_t size, bool echo=true)
 
IOStreamoperator<< (Manipulator func)
 
IOStreamoperator<< (int n)
 
IOStreamoperator<< (long int n)
 
IOStreamoperator<< (double n)
 
IOStreamoperator<< (unsigned int n)
 
IOStreamoperator<< (unsigned long int n)
 
IOStreamoperator<< (void *ptr)
 
IOStreamoperator<< (const void *ptr)
 
IOStreamoperator<< (char c)
 
IOStreamoperator<< (char *s)
 
IOStreamoperator<< (const char *s)
 
IOStreamoperator<< (str_P s)
 
IOStreamoperator<< (IOStream &buffer)
 
IOStreamoperator<< (const iovec_t *vec)
 

Static Public Member Functions

static char * ultoa (unsigned long __val, char *__s, int base)
 
static char * ltoa (long __val, char *__s, int base)
 
static char * utoa (unsigned int __val, char *__s, int base)
 
static char * itoa (int __val, char *__s, int base)
 

Static Public Attributes

static const int EOF = -1
 
static const char CR []
 
static const char LF [] = "\r"
 
static const char CRLF [] = "\r\n"
 

Protected Member Functions

void print_prefix (Base base)
 

Protected Attributes

Devicem_dev
 Delegated device. More...
 
Base m_base
 Base for next output operator. More...
 
int8_t m_width
 Minimum width of output string. More...
 
uint8_t m_prec
 Number of digits after decimal sign. More...
 
str_P m_eols
 End of line string (program memory). More...
 

Static Protected Attributes

static const size_t BUF_MAX = sizeof(uint32_t) * CHARBITS + 1
 

Friends

IOStreambcd (IOStream &outs)
 
IOStreambin (IOStream &outs)
 
IOStreamoct (IOStream &outs)
 
IOStreamdec (IOStream &outs)
 
IOStreamhex (IOStream &outs)
 
IOStreamflush (IOStream &outs)
 

Detailed Description

Basic in-/output stream support class. Requires implementation of Stream::Device.

Definition at line 30 of file IOStream.hh.

Member Typedef Documentation

typedef IOStream&(* IOStream::Manipulator) (IOStream &)

Stream manipulator function prototype. To allow implementation of base change and end of line.

Parameters
[in]iostream.
Returns
iostream.

Definition at line 538 of file IOStream.hh.

Member Enumeration Documentation

Base conversion.

Enumerator
bcd 
bin 
oct 
dec 
hex 

Definition at line 43 of file IOStream.hh.

End of line modes.

Enumerator
CR_MODE 
LF_MODE 
CRLF_MODE 

Definition at line 54 of file IOStream.hh.

Constructor & Destructor Documentation

IOStream::IOStream ( Device dev)

Construct stream with given device.

Parameters
[in]devstream device.

Definition at line 29 of file IOStream.cpp.

IOStream::IOStream ( )

Definition at line 37 of file IOStream.cpp.

Member Function Documentation

Device* IOStream::device ( ) const
inline

Get current device.

Returns
device.

Definition at line 265 of file IOStream.hh.

Device* IOStream::device ( Device dev)
inline

Set io stream device.

Parameters
[in]devstream device.
Returns
previous device.

Definition at line 275 of file IOStream.hh.

str_P IOStream::eol ( ) const
inline

Get io stream end of line string.

Returns
string for end of line.

Definition at line 286 of file IOStream.hh.

str_P IOStream::EOL ( ) const
inline

Get io stream end of line string.

Returns
string for end of line.

Definition at line 295 of file IOStream.hh.

void IOStream::eol ( str_P  s)
inline

Set io stream end of line string.

Parameters
[in]sstring for end of line.

Definition at line 304 of file IOStream.hh.

void IOStream::flush ( )
inline

Flush contents of iostream to stream.

Definition at line 504 of file IOStream.hh.

char * IOStream::itoa ( int  __val,
char *  __s,
int  base 
)
static

Definition at line 144 of file IOStream_dtoa.cpp.

char * IOStream::ltoa ( long  __val,
char *  __s,
int  base 
)
static

Definition at line 129 of file IOStream_dtoa.cpp.

IOStream& IOStream::operator<< ( Manipulator  func)
inline

Output operator for stream manipulator. Apply function.

Parameters
[in]funciostream manipulator.
Returns
iostream.

Definition at line 545 of file IOStream.hh.

IOStream& IOStream::operator<< ( int  n)
inline

Print integer as string in the current base to stream. Reset base to decimal.

Parameters
[in]nvalue to print.
Returns
iostream.

Definition at line 556 of file IOStream.hh.

IOStream& IOStream::operator<< ( long int  n)
inline

Print long integer as string in the current base to stream. Reset base to decimal.

Parameters
[in]nvalue to print.
Returns
iostream.

Definition at line 569 of file IOStream.hh.

IOStream& IOStream::operator<< ( double  n)
inline

Print double as string with the current field min width and number of decimals. Reset base to decimal.

Parameters
[in]nvalue to print.
Returns
iostream.

Definition at line 583 of file IOStream.hh.

IOStream& IOStream::operator<< ( unsigned int  n)
inline

Print unsigned integer as string in the current base to stream. Reset base to decimal.

Parameters
[in]nvalue to print.
Returns
iostream.

Definition at line 596 of file IOStream.hh.

IOStream& IOStream::operator<< ( unsigned long int  n)
inline

Print unsigned long integer as string in the current base to stream. Reset base to decimal.

Parameters
[in]nvalue to print.
Returns
iostream.

Definition at line 609 of file IOStream.hh.

IOStream& IOStream::operator<< ( void *  ptr)
inline

Print pointer as a hexadecimal number string to stream.

Parameters
[in]ptrpointer to print.
Returns
iostream.

Definition at line 621 of file IOStream.hh.

IOStream& IOStream::operator<< ( const void *  ptr)
inline

Print program memory pointer as a hexadecimal number string to stream.

Parameters
[in]ptrprogram memory pointer to print.
Returns
iostream.

Definition at line 634 of file IOStream.hh.

IOStream& IOStream::operator<< ( char  c)
inline

Print character to stream.

Parameters
[in]ccharacter to print.
Returns
iostream.

Definition at line 646 of file IOStream.hh.

IOStream& IOStream::operator<< ( char *  s)
inline

Print null terminated string to stream.

Parameters
[in]sstring to print.
Returns
iostream.

Definition at line 657 of file IOStream.hh.

IOStream& IOStream::operator<< ( const char *  s)
inline

Print null terminated string in program memory to stream.

Parameters
[in]sstring in program memory to print.
Returns
iostream.

Definition at line 668 of file IOStream.hh.

IOStream& IOStream::operator<< ( str_P  s)
inline

Print null terminated string in program memory to stream.

Parameters
[in]sstring in program memory to print.
Returns
iostream.

Definition at line 679 of file IOStream.hh.

IOStream& IOStream::operator<< ( IOStream buffer)
inline

Print contents of iobuffer to stream.

Parameters
[in]bufferinput/output buffer.
Returns
iostream.

Definition at line 690 of file IOStream.hh.

IOStream& IOStream::operator<< ( const iovec_t vec)
inline

Print contents of iovector to stream.

Parameters
[in]veciovector.
Returns
iostream.

Definition at line 701 of file IOStream.hh.

uint8_t IOStream::precision ( uint8_t  value)
inline

Set number of digits after decimal point for double numbers.

Parameters
[in]valueprecision.
Returns
previous precision.

Definition at line 327 of file IOStream.hh.

void IOStream::print ( int  value,
Base  base = dec 
)

Print integer as string with given base to stream.

Parameters
[in]valueto print.
[in]baseto represent value in (default 10).

Definition at line 46 of file IOStream.cpp.

void IOStream::print ( long int  value,
Base  base = dec 
)

Print long integer 32-bit value in given base torace stream.

Parameters
[in]valueto print.
[in]baseto represent value in (default 10).

Definition at line 65 of file IOStream.cpp.

void IOStream::print ( unsigned int  value,
Base  base = dec 
)

Print unsigned integer as string with given base to stream.

Parameters
[in]valueto print.
[in]baseto represent value in (default 10).

Definition at line 73 of file IOStream.cpp.

void IOStream::print ( unsigned long int  value,
Base  base = dec 
)

Print unsigned long integer 32-bit value in given base to stream.

Parameters
[in]valueto print.
[in]baseto represent value in (default 10).

Definition at line 81 of file IOStream.cpp.

void IOStream::print ( unsigned int  value,
uint8_t  digits,
Base  base 
)

Print unsigned integer as string with given base to stream.

Parameters
[in]valueto print.
[in]digitsto print.
[in]baseto represent value in.

Definition at line 89 of file IOStream.cpp.

void IOStream::print ( unsigned long int  value,
uint8_t  digits,
Base  base 
)

Print unsigned long integer 32-bit value in given base to stream.

Parameters
[in]valueto print.
[in]digitsto print.
[in]baseto represent value in.

Definition at line 99 of file IOStream.cpp.

void IOStream::print ( double  value,
int8_t  width,
uint8_t  prec 
)

Print double with the minimum field width of the output string (including the '.' and the possible sign for negative values) is given in width, and prec determines the number of digits after the decimal sign. width is signed value, negative for left adjustment.

Parameters
[in]valueto print.
[in]widthminimum field width.
[in]precnumber of digits.

Definition at line 109 of file IOStream.cpp.

void IOStream::print ( uint32_t  src,
const void *  ptr,
size_t  size,
Base  base = dec,
uint8_t  max = 16 
)

Print buffer contents in given base to stream.

Parameters
[in]srcaddress prefix.
[in]ptrpointer to data memory.
[in]sizenumber of bytes.
[in]baseto represent value in (default 10).
[in]maxnumber of numbers per line (default 16).

Definition at line 136 of file IOStream.cpp.

void IOStream::print ( const void *  ptr,
size_t  size,
Base  base = dec,
uint8_t  max = 16 
)
inline

Print buffer contents in given base to stream.

Parameters
[in]ptrpointer to data memory.
[in]sizenumber of bytes.
[in]baseto represent value in (default 10).
[in]maxnumber of numbers per line (default 16).

Definition at line 408 of file IOStream.hh.

void IOStream::print ( void *  ptr)
inline

Print pointer as a hexadecimal number to stream.

Parameters
[in]ptrpointer to data memory.

Definition at line 418 of file IOStream.hh.

void IOStream::print ( const void *  ptr)
inline

Print pointer to program memory as a hexadecimal number to stream.

Parameters
[in]ptrpointer to program memory.

Definition at line 428 of file IOStream.hh.

void IOStream::print ( char  c)
inline

Print character to stream.

Parameters
[in]ccharacter to print.

Definition at line 437 of file IOStream.hh.

void IOStream::print ( const char *  s)
inline

Print string in data memory to stream.

Parameters
[in]spointer to data memory string.

Definition at line 447 of file IOStream.hh.

void IOStream::print ( str_P  s)
inline

Print string in program memory to stream. Use macro PSTR() to generate a string constants in program memory.

Parameters
[in]spointer to program memory string.

Definition at line 458 of file IOStream.hh.

void IOStream::print ( IOStream::Device buffer)

Print contents of iostream to stream.

Parameters
[in]bufferinput/output buffer.

Definition at line 117 of file IOStream.cpp.

void IOStream::print_prefix ( Base  base)
protected

Print number prefix for non decimal base.

Parameters
[in]baserepresentation.

Definition at line 125 of file IOStream.cpp.

void IOStream::printf ( str_P  format,
  ... 
)
inline

Formated print with variable argument list. The format string should be in program memory. Use the macro PSTR().

Parameters
[in]formatstring in program memory.
[in]...variable argument list.

Definition at line 487 of file IOStream.hh.

void IOStream::println ( )
inline

Print end of line to stream.

Definition at line 467 of file IOStream.hh.

char * IOStream::readline ( char *  buf,
size_t  size,
bool  echo = true 
)

Read line into the given buffer. Characters received from the device is appended to the end of the string until end of line is received. The buffer pointer is returned with a complete line has been received otherwise NULL. The function will append until the given size of reached.

Parameters
[in]bufbuffer for received line.
[in]sizeof buffer.
[in]echocharacter mode (Default true).
Returns
NULL or pointer to buffer when line received.

Definition at line 262 of file IOStream.cpp.

char * IOStream::scan ( char *  s,
size_t  count 
)

Scan next token from the input stream. Returns pointer to string or NULL if not stream is empty.

Parameters
[in]sstring buffer to read into.
[in]countmax number of bytes to read.
Returns
string pointer or NULL.

Definition at line 224 of file IOStream.cpp.

char * IOStream::ultoa ( unsigned long  __val,
char *  __s,
int  base 
)
static

Definition at line 51 of file IOStream_dtoa.cpp.

char * IOStream::utoa ( unsigned int  __val,
char *  __s,
int  base 
)
static

Definition at line 138 of file IOStream_dtoa.cpp.

void IOStream::vprintf ( str_P  format,
va_list  args 
)

Format print with variable argument list. The format string should be in program memory. Use the macro PSTR().

Parameters
[in]formatstring in program memory.
[in]argsvariable argument list.

Definition at line 163 of file IOStream.cpp.

int8_t IOStream::width ( int8_t  value)
inline

Set minimum width for double numbers. The width is signed value, negative for left adjustment.

Parameters
[in]valuewidth.
Returns
previous width.

Definition at line 315 of file IOStream.hh.

Friends And Related Function Documentation

IOStream& bcd ( IOStream outs)
friend

Set current base to bcd for next operator print.

Parameters
[in]outsstream.
Returns
iostream.

Definition at line 745 of file IOStream.hh.

IOStream& bin ( IOStream outs)
friend

Set current base to binary(2) for next operator print.

Parameters
[in]outsstream.
Returns
iostream.

Definition at line 757 of file IOStream.hh.

IOStream& dec ( IOStream outs)
friend

Set current base to deciaml(10) for next operator print.

Parameters
[in]outsstream.
Returns
iostream.

Definition at line 781 of file IOStream.hh.

IOStream& flush ( IOStream outs)
friend

Flush buffer to device.

Parameters
[in]outsstream.
Returns
iostream.

Definition at line 853 of file IOStream.hh.

IOStream& hex ( IOStream outs)
friend

Set current base to hexadecimal(16) for next operator print.

Parameters
[in]outsstream to set base.
Returns
iostream.

Definition at line 793 of file IOStream.hh.

IOStream& oct ( IOStream outs)
friend

Set current base to octal(8) for next operator print.

Parameters
[in]outsstream.
Returns
iostream.

Definition at line 769 of file IOStream.hh.

Member Data Documentation

const size_t IOStream::BUF_MAX = sizeof(uint32_t) * CHARBITS + 1
staticprotected

Maximum size of required buffer for string conversion.

Definition at line 730 of file IOStream.hh.

const char IOStream::CR[]
static

End Of Line character sequences

Definition at line 36 of file IOStream.hh.

const char IOStream::CRLF = "\r\n"
static

Definition at line 38 of file IOStream.hh.

const int IOStream::EOF = -1
static

End Of File, returned when device operations fails (empty or full).

Definition at line 33 of file IOStream.hh.

const char IOStream::LF = "\r"
static

Definition at line 37 of file IOStream.hh.

Base IOStream::m_base
protected

Base for next output operator.

Definition at line 724 of file IOStream.hh.

Device* IOStream::m_dev
protected

Delegated device.

Definition at line 723 of file IOStream.hh.

str_P IOStream::m_eols
protected

End of line string (program memory).

Definition at line 727 of file IOStream.hh.

uint8_t IOStream::m_prec
protected

Number of digits after decimal sign.

Definition at line 726 of file IOStream.hh.

int8_t IOStream::m_width
protected

Minimum width of output string.

Definition at line 725 of file IOStream.hh.


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