[1312] | 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 | |
---|
| 33 | namespace orxonox |
---|
| 34 | { |
---|
| 35 | void OutputBuffer::registerListener(OutputBufferListener* listener) |
---|
| 36 | { |
---|
[1313] | 37 | this->listeners_.insert(this->listeners_.end(), listener); |
---|
[1312] | 38 | } |
---|
| 39 | |
---|
| 40 | void OutputBuffer::unregisterListener(OutputBufferListener* listener) |
---|
| 41 | { |
---|
[1313] | 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 | } |
---|
[1312] | 49 | } |
---|
| 50 | |
---|
[1322] | 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 | |
---|
[1312] | 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(); |
---|
[1334] | 80 | bool fail = this->stream_.fail(); |
---|
[1312] | 81 | |
---|
| 82 | if (eof) |
---|
[1322] | 83 | { |
---|
[1312] | 84 | this->stream_.flush(); |
---|
[1322] | 85 | this->stream_.clear(); |
---|
| 86 | } |
---|
[1312] | 87 | |
---|
[1334] | 88 | return (!eof && !fail); |
---|
[1312] | 89 | } |
---|
| 90 | |
---|
| 91 | void OutputBuffer::callListeners() |
---|
| 92 | { |
---|
[1313] | 93 | for (std::list<OutputBufferListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) |
---|
| 94 | (*it)->outputChanged(); |
---|
[1312] | 95 | } |
---|
| 96 | } |
---|