Dokumentation
The class OutputStream corresponds, essentially, to the class ostream from the C++ IO-Stream library. More...
#include <object/outputstream.h>
Public Member Functions | |
OutputStream () | |
Default constructor. Initial number system is decimal. | |
virtual | ~OutputStream () |
Destructor. | |
virtual void | flush ()=0 |
Clears the buffer. More... | |
OutputStream & | operator<< (char c) |
Print a single character. More... | |
OutputStream & | operator<< (unsigned char c) |
Print a single character. More... | |
OutputStream & | operator<< (const char *string) |
Printing a null-terminated string. More... | |
OutputStream & | operator<< (bool b) |
Print a boolean value. More... | |
OutputStream & | operator<< (short ival) |
Print an integral number in radix base More... | |
OutputStream & | operator<< (unsigned short ival) |
Print an integral number in radix base More... | |
OutputStream & | operator<< (int ival) |
Print an integral number in radix base More... | |
OutputStream & | operator<< (unsigned int ival) |
Print an integral number in radix base More... | |
OutputStream & | operator<< (long ival) |
Print an integral number in radix base More... | |
OutputStream & | operator<< (unsigned long ival) |
Print an integral number in radix base More... | |
OutputStream & | operator<< (long long ival) |
Print an integral number in radix base More... | |
OutputStream & | operator<< (unsigned long long ival) |
Print an integral number in radix base More... | |
OutputStream & | operator<< (const void *ptr) |
Print a pointer as hexadecimal number. More... | |
OutputStream & | operator<< (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] |
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.
Member Function Documentation
|
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, and TextStream.
OutputStream & OutputStream::operator<< | ( | char | c | ) |
Print a single character.
- Parameters
-
c Character to be printed
- Returns
- Reference to OutputStream os; allows operator chaining.
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, achar
is asigned char
.
- Parameters
-
c Character to be printed
- Returns
- Reference to OutputStream os; allows operator chaining.
OutputStream & OutputStream::operator<< | ( | const char * | string | ) |
Printing a null-terminated string.
- Parameters
-
string String to be printed
- Returns
- Reference to OutputStream os; allows operator chaining.
OutputStream & OutputStream::operator<< | ( | bool | b | ) |
Print a boolean value.
- Parameters
-
b Boolean to be printed
- Returns
- Reference to OutputStream os; allows operator chaining.
OutputStream & OutputStream::operator<< | ( | short | ival | ) |
Print an integral number in radix base
- Parameters
-
ival Number to be printed
- Returns
- Reference to OutputStream os; allows operator chaining.
OutputStream & OutputStream::operator<< | ( | unsigned short | ival | ) |
Print an integral number in radix base
- Parameters
-
ival Number to be printed
- Returns
- Reference to OutputStream os; allows operator chaining.
OutputStream & OutputStream::operator<< | ( | int | ival | ) |
Print an integral number in radix base
- Parameters
-
ival Number to be printed
- Returns
- Reference to OutputStream os; allows operator chaining.
OutputStream & OutputStream::operator<< | ( | unsigned int | ival | ) |
Print an integral number in radix base
- Parameters
-
ival Number to be printed
- Returns
- Reference to OutputStream os; allows operator chaining.
OutputStream & OutputStream::operator<< | ( | long | ival | ) |
Print an integral number in radix base
- Parameters
-
ival Number to be printed
- Returns
- Reference to OutputStream os; allows operator chaining.
OutputStream & OutputStream::operator<< | ( | unsigned long | ival | ) |
Print an integral number in radix base
- Parameters
-
ival Number to be printed
- Returns
- Reference to OutputStream os; allows operator chaining.
OutputStream & OutputStream::operator<< | ( | long long | ival | ) |
Print an integral number in radix base
- Parameters
-
ival Number to be printed
- Returns
- Reference to OutputStream os; allows operator chaining.
OutputStream & OutputStream::operator<< | ( | unsigned long long | ival | ) |
Print an integral number in radix base
- Parameters
-
ival Number to be printed
- Returns
- Reference to OutputStream os; allows operator chaining.
OutputStream & OutputStream::operator<< | ( | const void * | ptr | ) |
Print a pointer as hexadecimal number.
- Parameters
-
ptr Pointer to be printed
- Returns
- Reference to OutputStream os; allows operator chaining.
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
-
f Manipulator function to be called
- Returns
- Reference to OutputStream os; allows operator chaining.
The documentation for this class was generated from the following files:
- object/outputstream.h
- object/outputstream.cc