StuBS
OutputStream Class Referenceabstract

The class OutputStream corresponds, essentially, to the class ostream from the C++ IO-Stream library. More...

#include <object/outputstream.h>

Inheritance diagram for OutputStream:
[legend]
Collaboration diagram for OutputStream:
[legend]

Public Member Functions

 OutputStream ()
 Default constructor. Initial number system is decimal.
 
virtual ~OutputStream ()
 Destructor.
 
virtual void flush ()=0
 Clears the buffer.
 
OutputStreamoperator<< (char c)
 Print a single character.
 
OutputStreamoperator<< (unsigned char c)
 Print a single character.
 
OutputStreamoperator<< (const char *string)
 Printing a null-terminated string.
 
OutputStreamoperator<< (bool b)
 Print a boolean value.
 
OutputStreamoperator<< (short ival)
 Print an integral number in radix base
 
OutputStreamoperator<< (unsigned short ival)
 Print an integral number in radix base
 
OutputStreamoperator<< (int ival)
 Print an integral number in radix base
 
OutputStreamoperator<< (unsigned int ival)
 Print an integral number in radix base
 
OutputStreamoperator<< (long ival)
 Print an integral number in radix base
 
OutputStreamoperator<< (unsigned long ival)
 Print an integral number in radix base
 
OutputStreamoperator<< (long long ival)
 Print an integral number in radix base
 
OutputStreamoperator<< (unsigned long long ival)
 Print an integral number in radix base
 
OutputStreamoperator<< (const void *ptr)
 Print a pointer as hexadecimal number.
 
OutputStreamoperator<< (OutputStream &(*f)(OutputStream &))
 Calls one of the manipulator functions.
 
- Public Member Functions inherited from Stringbuffer
virtual ~Stringbuffer ()
 Destructor (nothing to do here)
 

Public Attributes

int base
 Number system used for printing integral numbers (one of 2, 8, 10, or 16)
 

Private Member Functions

 OutputStream (const OutputStream &)=delete
 
OutputStreamoperator= (const OutputStream &)=delete
 

Additional Inherited Members

- Protected Member Functions inherited from Stringbuffer
 Stringbuffer ()
 Constructor; Marks the buffer as empty.
 
void put (char c)
 Inserts a character into the buffer.
 
- Protected Attributes inherited from Stringbuffer
char buffer [80]
 buffer containing characters that will be printed upon flush()
 
long unsigned pos
 current position in the buffer
 

Detailed Description

The class OutputStream corresponds, essentially, to the class ostream from the C++ IO-Stream library.

As relying on the method Stringbuffer::put() is quite cumbersome when not only printing single characters, but numbers and whole strings, the class OutputStream provides a convenient way of composing output of variables of varying data types. Therefore, OutputStream implements shift operators operator<<` for various data types (similar to those known from the C++ IO-Stream library)

For further convenience, OutputStream also allows printing integral numbers in decimal, binary, octal, and hexadecimal format. Remember that, for negative numbers, the sign is only printed when using the decimal number system; for binary, octal, and hex, the number is printed as stored in the machine word without interpreting the sign. For Intel CPUs, two's complement is used for storing negative values, -1, for example, will print hex FFFFFFFF and octal 37777777777.

OutputStream's public methods/operators all return a reference to the object they are called on (i.e. *this). Returning *this allows chaining those stream operators in a single expression, such as kout << "a = " << a;

At this point in time, OutputStream implements operator<< for chars, strings and whole numbers. An additional operator<< allows using manipulators whose detailed description is given below.

Constructor & Destructor Documentation

◆ OutputStream() [1/2]

OutputStream::OutputStream ( const OutputStream )
privatedelete

◆ OutputStream() [2/2]

OutputStream::OutputStream ( )
inline

Default constructor. Initial number system is decimal.

Todo:
Implement Constructor

◆ ~OutputStream()

virtual OutputStream::~OutputStream ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ operator=()

OutputStream & OutputStream::operator= ( const OutputStream )
privatedelete

◆ flush()

virtual void OutputStream::flush ( )
pure virtual

Clears the buffer.

Pure virtual method that must be implemented by derived (non-abstract) classes. Formatting of the buffer contents can be implemented differently by different derived classes

Implements Stringbuffer.

Implemented in SerialStream, TextStream, ConsoleOut, and FileOut.

◆ operator<<() [1/14]

OutputStream & OutputStream::operator<< ( char  c)

Print a single character.

Todo:
Implement Operator
Parameters
cCharacter to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [2/14]

OutputStream & OutputStream::operator<< ( unsigned char  c)

Print a single character.

Note
In C, there are no "characters" in that sense, but only integers. A char, therefore, is a 8 bit number with the most significant bit (optionally) representing a sign. Depending on whether signed or not, the value ranges are [-128, 127] or [0; 255]. For GCC, a char is a signed char.
Todo:
Implement Operator
Parameters
cCharacter to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [3/14]

OutputStream & OutputStream::operator<< ( const char *  string)

Printing a null-terminated string.

Todo:
Implement Operator
Parameters
stringString to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [4/14]

OutputStream & OutputStream::operator<< ( bool  b)

Print a boolean value.

Todo:
Implement Operator
Parameters
bBoolean to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [5/14]

OutputStream & OutputStream::operator<< ( short  ival)

Print an integral number in radix base

Todo:
Implement Operator
Parameters
ivalNumber to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [6/14]

OutputStream & OutputStream::operator<< ( unsigned short  ival)

Print an integral number in radix base

Todo:
Implement Operator
Parameters
ivalNumber to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [7/14]

OutputStream & OutputStream::operator<< ( int  ival)

Print an integral number in radix base

Todo:
Implement Operator
Parameters
ivalNumber to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [8/14]

OutputStream & OutputStream::operator<< ( unsigned int  ival)

Print an integral number in radix base

Todo:
Implement Operator
Parameters
ivalNumber to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [9/14]

OutputStream & OutputStream::operator<< ( long  ival)

Print an integral number in radix base

Todo:
Implement Operator
Parameters
ivalNumber to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [10/14]

OutputStream & OutputStream::operator<< ( unsigned long  ival)

Print an integral number in radix base

Todo:
Implement Operator
Parameters
ivalNumber to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [11/14]

OutputStream & OutputStream::operator<< ( long long  ival)

Print an integral number in radix base

Todo:
Implement Operator
Parameters
ivalNumber to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [12/14]

OutputStream & OutputStream::operator<< ( unsigned long long  ival)

Print an integral number in radix base

Todo:
Implement Operator
Parameters
ivalNumber to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [13/14]

OutputStream & OutputStream::operator<< ( const void *  ptr)

Print a pointer as hexadecimal number.

Todo:
Implement Operator
Parameters
ptrPointer to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [14/14]

OutputStream & OutputStream::operator<< ( OutputStream &(*)(OutputStream &)  f)

Calls one of the manipulator functions.

Method that calls the manipulator functions defined below, which allow modifying the stream's behavior by, for instance, changing the number system.

Todo:
Implement Operator
Parameters
fManipulator function to be called
Returns
Reference to OutputStream os; allows operator chaining.

Member Data Documentation

◆ base

int OutputStream::base

Number system used for printing integral numbers (one of 2, 8, 10, or 16)


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