Orxonox: orxonox::OutputBuffer Class Reference

# orxonox::OutputBuffer Class Reference

The OutputBuffer acts almost like std::ostream and stores the assigned text. More...

`#include <src/util/OutputBuffer.h>`

List of all members.

## Public Member Functions

template<class T>
void | add (T object)
| Does the same like operator<<: Assigns the object to the stream and calls the listeners.
template<class T>
void | addLine (T object)
| Assigns an object/value and adds std::endl.
void | flush ()
| Flushes the stored text (~empties the OutputBuffer).
bool | getLine (std::string *output)
| Removes the first line from the stream and assigns it to a given string object.
std::stringstream & | getStream ()
| Returns the internal stringstream object.
void | newline ()
| Puts std::endl to the stream and calls the listeners.
OutputBuffer & | operator<< (std::ios_base &(*manipulator)(std::ios_base &))
| Puts a stream manipulator to the stream.
OutputBuffer & | operator<< (std::ios &(*manipulator)(std::ios &))
| Puts a stream manipulator to the stream.
OutputBuffer & | operator<< (std::ostream &(*manipulator)(std::ostream &))
| Puts a stream manipulator to the stream.
template<const OutputBuffer & >
OutputBuffer & | operator<< (const OutputBuffer &object)
| Reads the stored text of the other OutputBuffer and calls the listeners.
template<class T>
OutputBuffer & | operator<< (T object)
| Puts some object/value to the OutputBuffer. The text gets assigned and the OutputBuffer calls it's listeners.
| OutputBuffer ()
void | registerListener (OutputBufferListener *listener)
| Adds a new listener to the list.
void | unregisterListener (OutputBufferListener *listener)
| Removes a listener from the list.
| ~OutputBuffer ()

## Private Member Functions

void | callListeners ()
| Calls the outputChanged() function of all registered listeners.

## Private Attributes

std::vector < OutputBufferListener * > | listeners_
| A list of all listeners.
std::stringstream | stream_
| The stringstream that stores the assigned text.

## Detailed Description

The OutputBuffer acts almost like std::ostream and stores the assigned text.

If text gets assigned by using the << operator or another function, the OutputBuffer calls it's listeners, allowing them to retrieve the text line by line.

It's important to know that getLine actually removes the line from the OutputBuffer, so it's better to only have one "active" listener.

## Constructor & Destructor Documentation

orxonox::OutputBuffer::OutputBuffer | ( |  | ) | `[inline]`

orxonox::OutputBuffer::~OutputBuffer | ( |  | ) | `[inline]`

## Member Function Documentation

template<class T>

void orxonox::OutputBuffer::add | ( | T | object | ) | `[inline]`

Does the same like operator<<: Assigns the object to the stream and calls the listeners.

Parameters:

  | object | The object/value

template<class T>

void orxonox::OutputBuffer::addLine | ( | T | object | ) | `[inline]`

Assigns an object/value and adds std::endl.

Parameters:

  | object | The object/value

void orxonox::OutputBuffer::callListeners | ( |  | ) | `[private]`

Calls the outputChanged() function of all registered listeners.

References listeners_.

Referenced by operator<<().

void orxonox::OutputBuffer::flush | ( |  | ) | `[inline]`

Flushes the stored text (~empties the OutputBuffer).

bool orxonox::OutputBuffer::getLine | ( | std::string * | output | ) |

Removes the first line from the stream and assigns it to a given string object.

Parameters:

  | output | The string object to assign the first line

Returns:
  True if there was at least one line in the stream and this line was successfully assigned

It's important to know the returned line will be removed from the stream. If there are more than one listener, they have to cooperate to avoid conflicts.

References stream_.

Referenced by orxonox::Shell::outputChanged().

std::stringstream& orxonox::OutputBuffer::getStream | ( |  | ) | `[inline]`

Returns the internal stringstream object.

Referenced by orxonox::OutputHandler::setOutputBuffer().

void orxonox::OutputBuffer::newline | ( |  | ) | `[inline]`

Puts std::endl to the stream and calls the listeners.

OutputBuffer & orxonox::OutputBuffer::operator<< | ( | std::ios_base &(*)(std::ios_base &) | manipulator | ) |

Puts a stream manipulator to the stream.

Parameters:

  | manipulator | The manipulator

References callListeners(), and stream_.

OutputBuffer & orxonox::OutputBuffer::operator<< | ( | std::ios &(*)(std::ios &) | manipulator | ) |

Puts a stream manipulator to the stream.

Parameters:

  | manipulator | The manipulator

References callListeners(), and stream_.

OutputBuffer & orxonox::OutputBuffer::operator<< | ( | std::ostream &(*)(std::ostream &) | manipulator | ) |

Puts a stream manipulator to the stream.

Parameters:

  | manipulator | The manipulator

References callListeners(), and stream_.

template<const OutputBuffer & >

OutputBuffer& orxonox::OutputBuffer::operator<< | ( | const OutputBuffer & | object | ) | `[inline]`

Reads the stored text of the other OutputBuffer and calls the listeners.

Parameters:

  | object | The other OutputBuffer

template<class T>

OutputBuffer& orxonox::OutputBuffer::operator<< | ( | T | object | ) | `[inline]`

Puts some object/value to the OutputBuffer. The text gets assigned and the OutputBuffer calls it's listeners.

Parameters:

  | object | The object/value to assign

void orxonox::OutputBuffer::registerListener | ( | OutputBufferListener * | listener | ) |

Adds a new listener to the list.

Parameters:

  | listener | The new listener

References listeners_.

Referenced by orxonox::Shell::Shell().

void orxonox::OutputBuffer::unregisterListener | ( | OutputBufferListener * | listener | ) |

Removes a listener from the list.

Parameters:

  | listener | The listener

References listeners_.

## Member Data Documentation

std::vector<OutputBufferListener*> orxonox::OutputBuffer::listeners_`[private]`

A list of all listeners.

Referenced by callListeners(), registerListener(), and unregisterListener().

std::stringstream orxonox::OutputBuffer::stream_`[private]`

The stringstream that stores the assigned text.

Referenced by getLine(), and operator<<().

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

- src/util/OutputBuffer.h
- src/util/OutputBuffer.cc