StuBS
outputstream.h File Reference

This file contains the OutputStream. More...

#include "stringbuffer.h"
Include dependency graph for outputstream.h:
This graph shows which files directly or indirectly include this file:

Classes

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

Functions

OutputStreamflush (OutputStream &os)
 Enforces a buffer flush.
 
OutputStreamendl (OutputStream &os)
 Prints a newline character to the stream and issues a buffer flush.
 
OutputStreambin (OutputStream &os)
 Print subsequent numbers in binary form.
 
OutputStreamoct (OutputStream &os)
 Print subsequent numbers in octal form.
 
OutputStreamdec (OutputStream &os)
 Print subsequent numbers in decimal form.
 
OutputStreamhex (OutputStream &os)
 Print subsequent numbers in hex form.
 

Detailed Description

This file contains the OutputStream.

Along with the class OutputStream itself, this file contains definitions for the manipulators hex, dec, oct, and bin, which are used for changing the radix, and endl for signaling the end of the current line.

Manipulators
To simplify formatting text and numbers using the class OutputStream, we define so-called manipulators. For example, the expression kout << "a = " << dec << a << " is hexadecimal " << hex << a << endl; should, at first, print the value stored in decimal and then in hexadecimal form, followed by a line break. The intended properties can be realized by implementing hex, dec, oct, bin, and endl as functions (i.e., they are, in particular, not methods of OutputStream) that take (as first parameter) and return a reference to an OutputStream object. When compiling the expression show above, the method OutputStream& OutputStream::operator<< ((f) (OutputStream&)) is chosen when one of the functions hex, dec, oct, bin, or endl is streamed an OutputStream, which finally will execute the passed function.
Note
The term manipulator originates from the book The C++ Programming Language by Bjarne Stroustrup. Refer to this book for further explanations.

Function Documentation

◆ bin()

OutputStream & bin ( OutputStream os)

Print subsequent numbers in binary form.

Parameters
osReference to stream to be modified.
Returns
Reference to OutputStream os; allows operator chaining.

◆ dec()

OutputStream & dec ( OutputStream os)

Print subsequent numbers in decimal form.

Parameters
osReference to stream to be modified.
Returns
Reference to OutputStream os; allows operator chaining.

◆ endl()

OutputStream & endl ( OutputStream os)

Prints a newline character to the stream and issues a buffer flush.

Parameters
osReference to stream to be modified.
Returns
Reference to OutputStream os; allows operator chaining.

◆ flush()

OutputStream & flush ( OutputStream os)

Enforces a buffer flush.

Parameters
osReference to stream to be flushed.
Returns
Reference to OutputStream os; allows operator chaining.

◆ hex()

OutputStream & hex ( OutputStream os)

Print subsequent numbers in hex form.

Parameters
osReference to stream to be modified.
Returns
Reference to OutputStream os; allows operator chaining.

◆ oct()

OutputStream & oct ( OutputStream os)

Print subsequent numbers in octal form.

Parameters
osReference to stream to be modified.
Returns
Reference to OutputStream os; allows operator chaining.