Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1312 was 1312, checked in by landauf, 16 years ago

changed InputBuffer, added OutputBuffer and made a first sketch of 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 <set>
33#include <sstream>
34
35#include "CorePrereqs.h"
36
37namespace orxonox
38{
39    class OutputBufferListener
40    {
41        friend class OutputBuffer;
42        virtual void outputChanged() = 0;
43    };
44
45    class _CoreExport OutputBuffer
46    {
47        public:
48            static OutputBuffer& getOutputBuffer();
49
50            template <class T>
51            inline OutputBuffer& operator<<(T object)
52            {
53                this->stream_ << object;
54                this->callListeners();
55                return &this;
56            }
57
58            template <class T>
59            inline void add(T object)
60            {
61                this->stream_ << object;
62                this->callListeners();
63            }
64
65            template <class T>
66            inline void addLine(T object)
67            {
68                this->stream_ << object << std::endl;
69                this->callListeners();
70            }
71
72            inline void newline()
73            {
74                this->stream_ << std::endl;
75                this->callListeners();
76            }
77
78            inline void flush()
79            {
80                this->stream_.flush();
81            }
82
83            bool getLine(std::string* output);
84
85            void registerListener(OutputBufferListener* listener);
86            void unregisterListener(OutputBufferListener* listener);
87
88        private:
89            OutputBuffer() {}
90            OutputBuffer(const OutputBuffer& other);
91            ~OutputBuffer() {}
92
93            void callListeners();
94
95            std::stringstream stream_;
96            std::set<OutputBufferListener*> listeners_;
97    };
98}
99
100#endif /* _OutputBuffer_H__ */
Note: See TracBrowser for help on using the repository browser.