1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * |
---|
4 | * |
---|
5 | * License notice: |
---|
6 | * |
---|
7 | * This program is free software; you can redistribute it and/or |
---|
8 | * modify it under the terms of the GNU General Public License |
---|
9 | * as published by the Free Software Foundation; either version 2 |
---|
10 | * of the License, or (at your option) any later version. |
---|
11 | * |
---|
12 | * This program is distributed in the hope that it will be useful, |
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | * GNU General Public License for more details. |
---|
16 | * |
---|
17 | * You should have received a copy of the GNU General Public License |
---|
18 | * along with this program; if not, write to the Free Software |
---|
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
20 | * |
---|
21 | * Author: |
---|
22 | * Fabian 'x3n' Landau |
---|
23 | * Co-authors: |
---|
24 | * ... |
---|
25 | * |
---|
26 | */ |
---|
27 | |
---|
28 | #include "OutputHandler.h" |
---|
29 | |
---|
30 | namespace orxonox |
---|
31 | { |
---|
32 | /** |
---|
33 | @brief Constructor: Opens the logfile and writes the first line. |
---|
34 | @param logfilename The name of the logfile |
---|
35 | */ |
---|
36 | OutputHandler::OutputHandler(const std::string& logfilename) |
---|
37 | { |
---|
38 | this->logfilename_ = logfilename; |
---|
39 | this->logfile_.open(this->logfilename_.c_str(), std::fstream::out); |
---|
40 | this->logfile_ << "Started log" << std::endl; |
---|
41 | this->logfile_.flush(); |
---|
42 | } |
---|
43 | |
---|
44 | /** |
---|
45 | @brief Destructor: Writes the last line to the logfile and closes it. |
---|
46 | */ |
---|
47 | OutputHandler::~OutputHandler() |
---|
48 | { |
---|
49 | this->logfile_ << "Closed log" << std::endl; |
---|
50 | this->logfile_.close(); |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | @returns a reference to the only existing instance of the OutputHandler class. |
---|
55 | */ |
---|
56 | OutputHandler& OutputHandler::getOutStream() |
---|
57 | { |
---|
58 | static OutputHandler orxout("orxonox.log"); |
---|
59 | return orxout; |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | @brief Overloaded << operator, redirects the output to the console and the logfile. |
---|
64 | @param sb The streambuffer that should be shown in the console |
---|
65 | @return A reference to the OutputHandler itself |
---|
66 | */ |
---|
67 | OutputHandler& OutputHandler::operator<<(std::streambuf* sb) |
---|
68 | { |
---|
69 | std::cout << sb; |
---|
70 | this->logfile_ << sb; |
---|
71 | this->logfile_.flush(); |
---|
72 | return *this; |
---|
73 | } |
---|
74 | |
---|
75 | /** |
---|
76 | @brief Overloaded << operator, redirects the output to the console and the logfile. |
---|
77 | @param manipulator A function, manipulating the outstream. |
---|
78 | @return A reference to the OutputHandler itself |
---|
79 | */ |
---|
80 | OutputHandler& OutputHandler::operator<<(std::ostream& (*manipulator)(std::ostream&)) |
---|
81 | { |
---|
82 | manipulator(std::cout); |
---|
83 | manipulator(this->logfile_); |
---|
84 | this->logfile_.flush(); |
---|
85 | return *this; |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | @brief Overloaded << operator, redirects the output to the console and the logfile. |
---|
90 | @param manipulator A function, manipulating the outstream. |
---|
91 | @return A reference to the OutputHandler itself |
---|
92 | */ |
---|
93 | OutputHandler& OutputHandler::operator<<(std::ios& (*manipulator)(std::ios&)) |
---|
94 | { |
---|
95 | manipulator(std::cout); |
---|
96 | manipulator(this->logfile_); |
---|
97 | this->logfile_.flush(); |
---|
98 | return *this; |
---|
99 | } |
---|
100 | |
---|
101 | /** |
---|
102 | @brief Overloaded << operator, redirects the output to the console and the logfile. |
---|
103 | @param manipulator A function, manipulating the outstream. |
---|
104 | @return A reference to the OutputHandler itself |
---|
105 | */ |
---|
106 | OutputHandler& OutputHandler::operator<<(std::ios_base& (*manipulator)(std::ios_base&)) |
---|
107 | { |
---|
108 | manipulator(std::cout); |
---|
109 | manipulator(this->logfile_); |
---|
110 | this->logfile_.flush(); |
---|
111 | return *this; |
---|
112 | } |
---|
113 | |
---|
114 | /** |
---|
115 | @brief Overloaded non-member << operator, redirects the output to the console and the logfile. |
---|
116 | @param output The value that should be shown in the console |
---|
117 | @return A reference to the OutputHandler itself |
---|
118 | *//* |
---|
119 | OutputHandler& operator<<(OutputHandler& out, char c) |
---|
120 | { |
---|
121 | std::cout << c; |
---|
122 | out.getLogfile() << c; |
---|
123 | out.getLogfile().flush(); |
---|
124 | return out; |
---|
125 | }*/ |
---|
126 | |
---|
127 | /** |
---|
128 | @brief Overloaded non-member << operator, redirects the output to the console and the logfile. |
---|
129 | @param output The value that should be shown in the console |
---|
130 | @return A reference to the OutputHandler itself |
---|
131 | *//* |
---|
132 | OutputHandler& operator<<(OutputHandler& out, signed char c) |
---|
133 | { |
---|
134 | std::cout << c; |
---|
135 | out.getLogfile() << c; |
---|
136 | out.getLogfile().flush(); |
---|
137 | return out; |
---|
138 | }*/ |
---|
139 | |
---|
140 | /** |
---|
141 | @brief Overloaded non-member << operator, redirects the output to the console and the logfile. |
---|
142 | @param output The value that should be shown in the console |
---|
143 | @return A reference to the OutputHandler itself |
---|
144 | *//* |
---|
145 | OutputHandler& operator<<(OutputHandler& out, unsigned char c) |
---|
146 | { |
---|
147 | std::cout << c; |
---|
148 | out.getLogfile() << c; |
---|
149 | out.getLogfile().flush(); |
---|
150 | return out; |
---|
151 | }*/ |
---|
152 | |
---|
153 | /** |
---|
154 | @brief Overloaded non-member << operator, redirects the output to the console and the logfile. |
---|
155 | @param output The value that should be shown in the console |
---|
156 | @return A reference to the OutputHandler itself |
---|
157 | *//* |
---|
158 | OutputHandler& operator<<(OutputHandler& out, const char* s) |
---|
159 | { |
---|
160 | std::cout << s; |
---|
161 | out.getLogfile() << s; |
---|
162 | out.getLogfile().flush(); |
---|
163 | return out; |
---|
164 | }*/ |
---|
165 | |
---|
166 | /** |
---|
167 | @brief Overloaded non-member << operator, redirects the output to the console and the logfile. |
---|
168 | @param output The value that should be shown in the console |
---|
169 | @return A reference to the OutputHandler itself |
---|
170 | *//* |
---|
171 | OutputHandler& operator<<(OutputHandler& out, const signed char* s) |
---|
172 | { |
---|
173 | std::cout << s; |
---|
174 | out.getLogfile() << s; |
---|
175 | out.getLogfile().flush(); |
---|
176 | return out; |
---|
177 | }*/ |
---|
178 | |
---|
179 | /** |
---|
180 | @brief Overloaded non-member << operator, redirects the output to the console and the logfile. |
---|
181 | @param output The value that should be shown in the console |
---|
182 | @return A reference to the OutputHandler itself |
---|
183 | *//* |
---|
184 | OutputHandler& operator<<(OutputHandler& out, const unsigned char* s) |
---|
185 | { |
---|
186 | std::cout << s; |
---|
187 | out.getLogfile() << s; |
---|
188 | out.getLogfile().flush(); |
---|
189 | return out; |
---|
190 | }*/ |
---|
191 | } |
---|