Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/console/src/core/OutputBuffer.h @ 1313

Last change on this file since 1313 was 1313, checked in by landauf, 16 years ago
  • implemented Shell, but not yet linked with the graphical console
  • added new features (cursor, OIS::KeyCode listener) to InputBuffer
  • changed some includes to avoid circular header-dependencies in OrxonoxClass and Shell
File size: 2.7 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#ifndef _OutputBuffer_H__
30#define _OutputBuffer_H__
31
32#include <list>
33#include <sstream>
34
35#include "CorePrereqs.h"
36
37namespace orxonox
38{
39    class _CoreExport OutputBufferListener
40    {
41        friend class OutputBuffer;
42
43        virtual void outputChanged() = 0;
44    };
45
46    class _CoreExport OutputBuffer
47    {
48        public:
49            OutputBuffer() {}
50            ~OutputBuffer() {}
51
52            template <class T>
53            inline OutputBuffer& operator<<(T object)
54            {
55                this->stream_ << object;
56                this->callListeners();
57                return *this;
58            }
59
60            template <class T>
61            inline void add(T object)
62            {
63                this->stream_ << object;
64                this->callListeners();
65            }
66
67            template <class T>
68            inline void addLine(T object)
69            {
70                this->stream_ << object << std::endl;
71                this->callListeners();
72            }
73
74            inline void newline()
75            {
76                this->stream_ << std::endl;
77                this->callListeners();
78            }
79
80            inline void flush()
81            {
82                this->stream_.flush();
83            }
84
85            bool getLine(std::string* output);
86
87            void registerListener(OutputBufferListener* listener);
88            void unregisterListener(OutputBufferListener* listener);
89
90            inline operator std::stringstream&()
91            {
92                return this->stream_;
93            }
94
95        private:
96            void callListeners();
97
98            std::stringstream stream_;
99            std::list<OutputBufferListener*> listeners_;
100    };
101}
102
103#endif /* _OutputBuffer_H__ */
Note: See TracBrowser for help on using the repository browser.