Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/shader/src/core/OutputBuffer.cc @ 3029

Last change on this file since 3029 was 1505, checked in by rgrieder, 17 years ago

f* svn: It doesn't even inform you if you attempt to set a non existing property. It is svn:eol-style and not eol-style when using the command by the way…

  • 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#define OUTPUTBUFFER_MAX_LINE_LENGTH 16384
32
33namespace orxonox
34{
35    void OutputBuffer::registerListener(OutputBufferListener* listener)
36    {
37        this->listeners_.insert(this->listeners_.end(), listener);
38    }
39
40    void OutputBuffer::unregisterListener(OutputBufferListener* listener)
41    {
42        for (std::list<OutputBufferListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); )
43        {
44            if ((*it) == listener)
45                this->listeners_.erase(it++);
46            else
47                ++it;
48        }
49    }
50
51    OutputBuffer& OutputBuffer::operator<<(std::ostream& (*manipulator)(std::ostream&))
52    {
53                this->stream_ << manipulator;
54                this->callListeners();
55                return *this;
56    }
57
58    OutputBuffer& OutputBuffer::operator<<(std::ios& (*manipulator)(std::ios&))
59    {
60                this->stream_ << manipulator;
61                this->callListeners();
62                return *this;
63    }
64
65    OutputBuffer& OutputBuffer::operator<<(std::ios_base& (*manipulator)(std::ios_base&))
66    {
67                this->stream_ << manipulator;
68                this->callListeners();
69                return *this;
70    }
71
72    bool OutputBuffer::getLine(std::string* output)
73    {
74        char line[OUTPUTBUFFER_MAX_LINE_LENGTH];
75
76        this->stream_.getline(line, OUTPUTBUFFER_MAX_LINE_LENGTH);
77        (*output) = std::string(line);
78
79        bool eof = this->stream_.eof();
80        bool fail = this->stream_.fail();
81
82        if (eof)
83            this->stream_.flush();
84
85        if (eof || fail)
86            this->stream_.clear();
87
88        return (!eof && !fail);
89    }
90
91    void OutputBuffer::callListeners()
92    {
93        for (std::list<OutputBufferListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
94            (*it)->outputChanged();
95    }
96}
Note: See TracBrowser for help on using the repository browser.