Orxonox  0.0.5 Codename: Arcturus
OutputStream.h
Go to the documentation of this file.
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 
35 #ifndef _OutputStream_H__
36 #define _OutputStream_H__
37 
38 #include "util/UtilPrereqs.h"
39 
40 #include <sstream>
41 
42 #include "OutputDefinitions.h"
43 
44 namespace orxonox
45 {
73  class OutputStream : public std::ostringstream
74  {
75  typedef std::ostream& (*EndlType)(std::ostream&);
76 
77  public:
81 
83 
85  template <class T>
86  inline OutputStream& operator<<(const T& val) { return this->output(val); }
88  inline OutputStream& operator<<(std::ios_base& (*manipulator)(std::ios_base&)) { return this->output(manipulator); }
90  inline OutputStream& operator<<(std::ios& (*manipulator)(std::ios&)) { return this->output(manipulator); }
92  inline OutputStream& operator<<(std::ostream& (*manipulator)(std::ostream&))
93  {
94  if (this->bAcceptsOutput_)
95  {
96  if (manipulator == static_cast<EndlType>(std::endl))
97  this->sendMessage(); // send the message to OutputManager
98  else
99  return this->output(manipulator); // apply the manipulator
100  }
101  return *this;
102  }
103 
104  inline const OutputLevel getOutputLevel() const { return this->level_; }
105  inline const OutputContextContainer* getOutputContext() const { return this->context_; }
106  inline bool acceptsOutput() const { return this->bAcceptsOutput_; }
107 
108  private:
110  template <class T>
111  inline OutputStream& output(const T& val)
112  {
113  if (this->bAcceptsOutput_)
114  static_cast<std::ostringstream&>(*this) << val;
115  return *this;
116  }
117 
118  void _UtilExport sendMessage();
119 
123  };
124 }
125 
126 #endif /* _OutputStream_H__ */
bool bAcceptsOutput_
After defining level and context of the following message, this flag is set according to the masks de...
Definition: OutputStream.h:122
OutputStream & operator<<(std::ostream &(*manipulator)(std::ostream &))
Sends a manipulator to the output stream and flushes the message if the manipulator is std::endl...
Definition: OutputStream.h:92
#define _UtilExport
Definition: UtilPrereqs.h:60
OutputStream & operator<<(std::ios &(*manipulator)(std::ios &))
Sends a manipulator to the output stream.
Definition: OutputStream.h:90
Stores all information about a context.
Definition: OutputDefinitions.h:112
OutputLevel level_
The output level of the current message.
Definition: OutputStream.h:120
const OutputContextContainer * context_
The output context of the current message.
Definition: OutputStream.h:121
_UtilExport OutputStream()
Default constructor, initializes level and context with default values.
Definition: OutputStream.cc:43
_UtilExport ~OutputStream()
Destructor, sends remaining output to OutputManager (if any).
Definition: OutputStream.cc:58
OutputStream & output(const T &val)
Generic function to add values to the output stream, using the inherited << operator from std::ostrin...
Definition: OutputStream.h:111
void _UtilExport setOutputAttributes(OutputLevel level, const OutputContextContainer &context)
Defines level and context of the following output.
Definition: OutputStream.cc:78
OutputLevel
Output levels define type and importance of an output message.
Definition: OutputDefinitions.h:84
Defines output levels and output contexts.
bool acceptsOutput() const
Definition: OutputStream.h:106
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
Shared library macros, enums, constants and forward declarations for the util library ...
Definition: InputPrereqs.h:78
const OutputContextContainer * getOutputContext() const
Definition: OutputStream.h:105
OutputStream & operator<<(std::ios_base &(*manipulator)(std::ios_base &))
Sends a manipulator to the output stream.
Definition: OutputStream.h:88
void _UtilExport sendMessage()
Sends the buffered message to OutputManager together with the stored level and context.
Definition: OutputStream.cc:68
const OutputLevel getOutputLevel() const
Definition: OutputStream.h:104
OutputStream & operator<<(const T &val)
Generic << operator which adds output to the stream.
Definition: OutputStream.h:86
This class is used to buffer output and send it to OutputManager whenever std::endl is passed to it...
Definition: OutputStream.h:73