StuBS
OutputStream Class Referenceabstract

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

#include <outputstream.h>

Inheritance diagram for OutputStream:
Collaboration diagram for OutputStream:

Public Member Functions

 OutputStream ()
 Default constructor. Initial number system is decimal. More...
 
virtual ~OutputStream ()
 Destructor.
 
virtual void flush ()=0
 Clears the buffer. More...
 
OutputStreamoperator<< (char c)
 Print a single character. More...
 
OutputStreamoperator<< (unsigned char c)
 Print a single character. More...
 
OutputStreamoperator<< (const char *string)
 Printing a null-terminated string. More...
 
OutputStreamoperator<< (bool b)
 Print a boolean value. More...
 
OutputStreamoperator<< (short ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (unsigned short ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (int ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (unsigned int ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (long ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (unsigned long ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (long long ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (unsigned long long ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (const void *ptr)
 Print a pointer as hexadecimal number. More...
 
OutputStreamoperator<< (OutputStream &(*f)(OutputStream &))
 Calls one of the manipulator functions. More...
 
- 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)
 

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. More...
 
virtual void flush ()=0
 Flush the buffer contents. More...
 
- Protected Attributes inherited from Stringbuffer
char buffer [80+1]
 
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 additionaloperator<<` allows using manipulators whose detailed description is given below.

Constructor & Destructor Documentation

◆ OutputStream()

OutputStream::OutputStream ( )
inline

Default constructor. Initial number system is decimal.

Member Function Documentation

◆ 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 CopyStream, SerialStream, and TextStream.

◆ operator<<() [1/14]

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

Print a boolean value.

Parameters
bBoolean to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [2/14]

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

Print a single character.

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.

Parameters
stringString to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [4/14]

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

Print a pointer as hexadecimal number.

Parameters
ptrPointer to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [5/14]

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

Print an integral number in radix base.

Parameters
ivalNumber to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [6/14]

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

Print an integral number in radix base.

Parameters
ivalNumber to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [7/14]

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

Print an integral number in radix base.

Parameters
ivalNumber to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [8/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.

Parameters
fManipulator function to be called
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [9/14]

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

Print an integral number in radix base.

Parameters
ivalNumber to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [10/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.
Parameters
cCharacter to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [11/14]

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

Print an integral number in radix base.

Parameters
ivalNumber to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [12/14]

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

Print an integral number in radix base.

Parameters
ivalNumber to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [13/14]

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

Print an integral number in radix base.

Parameters
ivalNumber to be printed
Returns
Reference to OutputStream os; allows operator chaining.

◆ operator<<() [14/14]

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

Print an integral number in radix base.

Parameters
ivalNumber to be printed
Returns
Reference to OutputStream os; allows operator chaining.

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