[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 | #ifndef _OutputBuffer_H__ |
---|
| 30 | #define _OutputBuffer_H__ |
---|
| 31 | |
---|
[1313] | 32 | #include <list> |
---|
[1312] | 33 | #include <sstream> |
---|
[1322] | 34 | #include <iostream> |
---|
[1312] | 35 | |
---|
| 36 | #include "CorePrereqs.h" |
---|
| 37 | |
---|
| 38 | namespace orxonox |
---|
| 39 | { |
---|
[1313] | 40 | class _CoreExport OutputBufferListener |
---|
[1312] | 41 | { |
---|
| 42 | friend class OutputBuffer; |
---|
[1313] | 43 | |
---|
[1312] | 44 | virtual void outputChanged() = 0; |
---|
| 45 | }; |
---|
| 46 | |
---|
| 47 | class _CoreExport OutputBuffer |
---|
| 48 | { |
---|
| 49 | public: |
---|
[1313] | 50 | OutputBuffer() {} |
---|
| 51 | ~OutputBuffer() {} |
---|
[1312] | 52 | |
---|
| 53 | template <class T> |
---|
| 54 | inline OutputBuffer& operator<<(T object) |
---|
| 55 | { |
---|
| 56 | this->stream_ << object; |
---|
| 57 | this->callListeners(); |
---|
[1313] | 58 | return *this; |
---|
[1312] | 59 | } |
---|
| 60 | |
---|
[1322] | 61 | OutputBuffer& operator<<(std::ostream& (*manipulator)(std::ostream&)); |
---|
| 62 | OutputBuffer& operator<<(std::ios& (*manipulator)(std::ios&)); |
---|
| 63 | OutputBuffer& operator<<(std::ios_base& (*manipulator)(std::ios_base&)); |
---|
| 64 | |
---|
[1312] | 65 | template <class T> |
---|
| 66 | inline void add(T object) |
---|
| 67 | { |
---|
| 68 | this->stream_ << object; |
---|
| 69 | this->callListeners(); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | template <class T> |
---|
| 73 | inline void addLine(T object) |
---|
| 74 | { |
---|
| 75 | this->stream_ << object << std::endl; |
---|
| 76 | this->callListeners(); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | inline void newline() |
---|
| 80 | { |
---|
| 81 | this->stream_ << std::endl; |
---|
| 82 | this->callListeners(); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | inline void flush() |
---|
| 86 | { |
---|
| 87 | this->stream_.flush(); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | bool getLine(std::string* output); |
---|
| 91 | |
---|
| 92 | void registerListener(OutputBufferListener* listener); |
---|
| 93 | void unregisterListener(OutputBufferListener* listener); |
---|
| 94 | |
---|
| 95 | private: |
---|
| 96 | void callListeners(); |
---|
| 97 | |
---|
| 98 | std::stringstream stream_; |
---|
[1313] | 99 | std::list<OutputBufferListener*> listeners_; |
---|
[1312] | 100 | }; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | #endif /* _OutputBuffer_H__ */ |
---|