Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/util/OutputBuffer.cc @ 5723

Last change on this file since 5723 was 3198, checked in by scheusso, 16 years ago

merged netp4 back to trunk

  • Property svn:eol-style set to native
File size: 3.7 KB
RevLine 
[1505]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
[1791]29/**
[2171]30    @file
[1791]31    @brief Implementation of the OutputBuffer.
32*/
33
[1505]34#include "OutputBuffer.h"
35
36namespace orxonox
37{
[1791]38    /**
39        @brief Adds a new listener to the list.
40        @param listener The new listener
41    */
[1505]42    void OutputBuffer::registerListener(OutputBufferListener* listener)
43    {
[3196]44        this->listeners_.push_back(listener);
[1505]45    }
46
[1791]47    /**
48        @brief Removes a listener from the list.
49        @param listener The listener
50    */
[1505]51    void OutputBuffer::unregisterListener(OutputBufferListener* listener)
52    {
[3196]53        for (std::vector<OutputBufferListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); )
[1505]54        {
55            if ((*it) == listener)
[3196]56                it = this->listeners_.erase(it);
[1505]57            else
58                ++it;
59        }
60    }
61
[1791]62    /**
63        @brief Puts a stream manipulator to the stream.
64        @param manipulator The manipulator
65    */
[1505]66    OutputBuffer& OutputBuffer::operator<<(std::ostream& (*manipulator)(std::ostream&))
67    {
[2710]68        this->stream_ << manipulator;
69        this->callListeners();
70        return *this;
[1505]71    }
72
[1791]73    /**
74        @brief Puts a stream manipulator to the stream.
75        @param manipulator The manipulator
76    */
[1505]77    OutputBuffer& OutputBuffer::operator<<(std::ios& (*manipulator)(std::ios&))
78    {
[2710]79        this->stream_ << manipulator;
80        this->callListeners();
81        return *this;
[1505]82    }
83
[1791]84    /**
85        @brief Puts a stream manipulator to the stream.
86        @param manipulator The manipulator
87    */
[1505]88    OutputBuffer& OutputBuffer::operator<<(std::ios_base& (*manipulator)(std::ios_base&))
89    {
[2710]90        this->stream_ << manipulator;
91        this->callListeners();
92        return *this;
[1505]93    }
94
[1791]95    /**
96        @brief Removes the first line from the stream and assigns it to a given string object.
97        @param output The string object to assign the first line
98        @return True if there was at least one line in the stream and this line was successfully assigned
99
100        It's important to know the returned line will be removed from the stream. If there are more than one
101        listener, they have to cooperate to avoid conflicts.
102    */
[1505]103    bool OutputBuffer::getLine(std::string* output)
104    {
[3198]105        std::getline(this->stream_, *output);
[1505]106
107        bool eof = this->stream_.eof();
108        bool fail = this->stream_.fail();
109
110        if (eof)
111            this->stream_.flush();
112
113        if (eof || fail)
114            this->stream_.clear();
115
116        return (!eof && !fail);
117    }
118
[1791]119    /**
120        @brief Calls the outputChanged() function of all registered listeners.
121    */
[1505]122    void OutputBuffer::callListeners()
123    {
[3196]124        for (std::vector<OutputBufferListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
[1505]125            (*it)->outputChanged();
126    }
127}
Note: See TracBrowser for help on using the repository browser.