Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1784 was 1784, checked in by rgrieder, 16 years ago
  • removed obsolete Convert.h includes (possibly from old XML loading)
  • replaced tabs in audio library, plus minor code cleanup because removing the tabs screwed layout
  • replaced all "#define name number" with "const Type name = number" if possible
  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
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
29#include "OutputBuffer.h"
30
31
32namespace orxonox
33{
34    const int OUTPUTBUFFER_MAX_LINE_LENGTH = 16384;
35
36    void OutputBuffer::registerListener(OutputBufferListener* listener)
37    {
38        this->listeners_.insert(this->listeners_.end(), listener);
39    }
40
41    void OutputBuffer::unregisterListener(OutputBufferListener* listener)
42    {
43        for (std::list<OutputBufferListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); )
44        {
45            if ((*it) == listener)
46                this->listeners_.erase(it++);
47            else
48                ++it;
49        }
50    }
51
52    OutputBuffer& OutputBuffer::operator<<(std::ostream& (*manipulator)(std::ostream&))
53    {
54                this->stream_ << manipulator;
55                this->callListeners();
56                return *this;
57    }
58
59    OutputBuffer& OutputBuffer::operator<<(std::ios& (*manipulator)(std::ios&))
60    {
61                this->stream_ << manipulator;
62                this->callListeners();
63                return *this;
64    }
65
66    OutputBuffer& OutputBuffer::operator<<(std::ios_base& (*manipulator)(std::ios_base&))
67    {
68                this->stream_ << manipulator;
69                this->callListeners();
70                return *this;
71    }
72
73    bool OutputBuffer::getLine(std::string* output)
74    {
75        char line[OUTPUTBUFFER_MAX_LINE_LENGTH];
76
77        this->stream_.getline(line, OUTPUTBUFFER_MAX_LINE_LENGTH);
78        (*output) = std::string(line);
79
80        bool eof = this->stream_.eof();
81        bool fail = this->stream_.fail();
82
83        if (eof)
84            this->stream_.flush();
85
86        if (eof || fail)
87            this->stream_.clear();
88
89        return (!eof && !fail);
90    }
91
92    void OutputBuffer::callListeners()
93    {
94        for (std::list<OutputBufferListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
95            (*it)->outputChanged();
96    }
97}
Note: See TracBrowser for help on using the repository browser.