StuBS
|
The class OutputStream corresponds, essentially, to the class ostream from the C++ IO-Stream library. More...
#include <outputstream.h>
Public Member Functions | |
OutputStream () | |
Default constructor. Initial number system is decimal. | |
virtual | ~OutputStream () |
Destructor. | |
virtual void | flush ()=0 |
Clears the buffer. | |
OutputStream & | operator<< (char c) |
Print a single character. | |
OutputStream & | operator<< (unsigned char c) |
Print a single character. | |
OutputStream & | operator<< (const char *string) |
Printing a null-terminated string. | |
OutputStream & | operator<< (bool b) |
Print a boolean value. | |
OutputStream & | operator<< (short ival) |
Print an integral number in radix base. | |
OutputStream & | operator<< (unsigned short ival) |
Print an integral number in radix base. | |
OutputStream & | operator<< (int ival) |
Print an integral number in radix base. | |
OutputStream & | operator<< (unsigned int ival) |
Print an integral number in radix base. | |
OutputStream & | operator<< (long ival) |
Print an integral number in radix base. | |
OutputStream & | operator<< (unsigned long ival) |
Print an integral number in radix base. | |
OutputStream & | operator<< (long long ival) |
Print an integral number in radix base. | |
OutputStream & | operator<< (unsigned long long ival) |
Print an integral number in radix base. | |
OutputStream & | operator<< (const void *ptr) |
Print a pointer as hexadecimal number. | |
OutputStream & | operator<< (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) | |
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+1] |
long unsigned | pos |
current position in the buffer | |
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.
|
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.
OutputStream & OutputStream::operator<< | ( | bool | b | ) |
Print a boolean value.
b | Boolean to be printed |
OutputStream & OutputStream::operator<< | ( | char | c | ) |
Print a single character.
c | Character to be printed |
OutputStream & OutputStream::operator<< | ( | const char * | string | ) |
Printing a null-terminated string.
string | String to be printed |
OutputStream & OutputStream::operator<< | ( | const void * | ptr | ) |
Print a pointer as hexadecimal number.
ptr | Pointer to be printed |
OutputStream & OutputStream::operator<< | ( | int | ival | ) |
Print an integral number in radix base.
ival | Number to be printed |
OutputStream & OutputStream::operator<< | ( | long | ival | ) |
Print an integral number in radix base.
ival | Number to be printed |
OutputStream & OutputStream::operator<< | ( | long long | ival | ) |
Print an integral number in radix base.
ival | Number to be printed |
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.
f | Manipulator function to be called |
OutputStream & OutputStream::operator<< | ( | short | ival | ) |
Print an integral number in radix base.
ival | Number to be printed |
OutputStream & OutputStream::operator<< | ( | unsigned char | c | ) |
Print a single character.
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
.c | Character to be printed |
OutputStream & OutputStream::operator<< | ( | unsigned int | ival | ) |
Print an integral number in radix base.
ival | Number to be printed |
OutputStream & OutputStream::operator<< | ( | unsigned long | ival | ) |
Print an integral number in radix base.
ival | Number to be printed |
OutputStream & OutputStream::operator<< | ( | unsigned long long | ival | ) |
Print an integral number in radix base.
ival | Number to be printed |
OutputStream & OutputStream::operator<< | ( | unsigned short | ival | ) |
Print an integral number in radix base.
ival | Number to be printed |