ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

streamdebug.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011 
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/streamdebug.h"
00024 #include "common/debug.h"
00025 #include "common/str.h"
00026 
00027 namespace Common {
00028 
00029 class MessageStream {
00030 public:
00031     MessageStream() :
00032         ref(1), space(true) {
00033 
00034     }
00035 
00036     String msg;
00037     int ref;
00038     bool space;
00039     int level;
00040 };
00041 
00042 Debug::Debug(int level) :
00043     _stream(new MessageStream()) {
00044     _stream->level = level;
00045 }
00046 
00047 Debug::Debug(const Debug &other) {
00048     *this = other;
00049 }
00050 
00051 Debug::~Debug() {
00052     if (--_stream->ref == 0) {
00053         debug(_stream->level, "%s", _stream->msg.c_str());
00054         delete _stream;
00055     }
00056 }
00057 
00058 Debug &Debug::space() {
00059     if (!_stream->space) {
00060         _stream->msg += String(" ");
00061         _stream->space = true;
00062     }
00063     return *this;
00064 }
00065 
00066 Debug &Debug::nospace() {
00067     _stream->space = false;
00068     return *this;
00069 }
00070 
00071 Debug &Debug::maybeSpace() {
00072     if (_stream->space) {
00073         _stream->msg += " ";
00074     }
00075     return *this;
00076 }
00077 
00078 Debug &Debug::operator<<(const String &str) {
00079     _stream->msg += str;
00080     return maybeSpace();
00081 }
00082 
00083 Debug &Debug::operator<<(const char *str) {
00084     _stream->msg += str;
00085     return maybeSpace();
00086 }
00087 
00088 Debug &Debug::operator<<(char str) {
00089     _stream->msg += str;
00090     return maybeSpace();
00091 }
00092 
00093 Debug &Debug::operator<<(int num) {
00094     _stream->msg += String::format("%d", num);
00095     return maybeSpace();
00096 }
00097 
00098 Debug &Debug::operator<<(unsigned int num) {
00099     _stream->msg += String::format("%d", num);
00100     return maybeSpace();
00101 }
00102 
00103 Debug &Debug::operator<<(double num) {
00104     _stream->msg += String::format("%g", num);
00105     return maybeSpace();
00106 }
00107 
00108 Debug &Debug::operator<<(float num) {
00109     _stream->msg += String::format("%g", num);
00110     return maybeSpace();
00111 }
00112 
00113 Debug &Debug::operator<<(bool value) {
00114     _stream->msg += (value ? "true" : "false");
00115     return maybeSpace();
00116 }
00117 
00118 Debug &Debug::operator<<(void *p) {
00119     _stream->msg += String::format("%p", p);
00120     return maybeSpace();
00121 }
00122 
00123 Debug &Debug::operator=(const Debug &other) {
00124     _stream = other._stream;
00125     ++_stream->ref;
00126 
00127     return *this;
00128 }
00129 
00130 }
00131 
00132 Common::Debug streamDbg(int level) {
00133     return Common::Debug(level);
00134 }
00135 


Generated on Sat Jul 13 2019 05:01:00 for ResidualVM by doxygen 1.7.1
curved edge   curved edge