2012-12-19 22:15:43 +00:00
|
|
|
/* ResidualVM - A 3D game interpreter
|
2011-08-31 13:37:42 +00:00
|
|
|
*
|
2012-12-19 22:15:43 +00:00
|
|
|
* ResidualVM is the legal property of its developers, whose names
|
2011-08-31 13:37:42 +00:00
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
2012-12-19 22:15:43 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
2011-08-31 13:37:42 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-12-19 22:15:43 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2011-08-31 13:37:42 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/streamdebug.h"
|
|
|
|
#include "common/debug.h"
|
|
|
|
#include "common/str.h"
|
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
|
|
|
|
class MessageStream {
|
|
|
|
public:
|
|
|
|
MessageStream() :
|
|
|
|
ref(1), space(true) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String msg;
|
|
|
|
int ref;
|
|
|
|
bool space;
|
|
|
|
int level;
|
|
|
|
};
|
|
|
|
|
2020-10-16 19:47:16 +00:00
|
|
|
StreamDebug::StreamDebug(int level) :
|
2011-08-31 13:37:42 +00:00
|
|
|
_stream(new MessageStream()) {
|
|
|
|
_stream->level = level;
|
|
|
|
}
|
|
|
|
|
2020-10-16 19:47:16 +00:00
|
|
|
StreamDebug::StreamDebug(const StreamDebug &other) {
|
2011-08-31 13:37:42 +00:00
|
|
|
*this = other;
|
|
|
|
}
|
|
|
|
|
2020-10-16 19:47:16 +00:00
|
|
|
StreamDebug::~StreamDebug() {
|
2011-08-31 13:37:42 +00:00
|
|
|
if (--_stream->ref == 0) {
|
2012-01-27 11:02:03 +00:00
|
|
|
debug(_stream->level, "%s", _stream->msg.c_str());
|
2011-08-31 13:37:42 +00:00
|
|
|
delete _stream;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-16 19:47:16 +00:00
|
|
|
StreamDebug &StreamDebug::space() {
|
2011-08-31 13:37:42 +00:00
|
|
|
if (!_stream->space) {
|
|
|
|
_stream->msg += String(" ");
|
|
|
|
_stream->space = true;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-10-16 19:47:16 +00:00
|
|
|
StreamDebug &StreamDebug::nospace() {
|
2011-08-31 13:37:42 +00:00
|
|
|
_stream->space = false;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-10-16 19:47:16 +00:00
|
|
|
StreamDebug &StreamDebug::maybeSpace() {
|
2011-08-31 13:37:42 +00:00
|
|
|
if (_stream->space) {
|
|
|
|
_stream->msg += " ";
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-10-16 19:47:16 +00:00
|
|
|
StreamDebug &StreamDebug::operator<<(const String &str) {
|
2011-08-31 13:37:42 +00:00
|
|
|
_stream->msg += str;
|
|
|
|
return maybeSpace();
|
|
|
|
}
|
|
|
|
|
2020-10-16 19:47:16 +00:00
|
|
|
StreamDebug &StreamDebug::operator<<(const char *str) {
|
2011-08-31 13:37:42 +00:00
|
|
|
_stream->msg += str;
|
|
|
|
return maybeSpace();
|
|
|
|
}
|
|
|
|
|
2020-10-16 19:47:16 +00:00
|
|
|
StreamDebug &StreamDebug::operator<<(char str) {
|
2011-09-14 20:50:18 +00:00
|
|
|
_stream->msg += str;
|
|
|
|
return maybeSpace();
|
|
|
|
}
|
|
|
|
|
2020-10-16 19:47:16 +00:00
|
|
|
StreamDebug &StreamDebug::operator<<(int num) {
|
2011-08-31 13:37:42 +00:00
|
|
|
_stream->msg += String::format("%d", num);
|
|
|
|
return maybeSpace();
|
|
|
|
}
|
|
|
|
|
2020-10-16 19:47:16 +00:00
|
|
|
StreamDebug &StreamDebug::operator<<(unsigned int num) {
|
2011-10-18 15:46:29 +00:00
|
|
|
_stream->msg += String::format("%d", num);
|
|
|
|
return maybeSpace();
|
|
|
|
}
|
|
|
|
|
2020-10-11 08:22:23 +00:00
|
|
|
#if !defined(__DC__) && !defined(__DS__)
|
2020-10-16 19:47:16 +00:00
|
|
|
StreamDebug &StreamDebug::operator<<(double num) {
|
2011-10-18 15:46:29 +00:00
|
|
|
_stream->msg += String::format("%g", num);
|
|
|
|
return maybeSpace();
|
|
|
|
}
|
2020-10-10 08:28:05 +00:00
|
|
|
#endif
|
2011-10-18 15:46:29 +00:00
|
|
|
|
2020-10-16 19:47:16 +00:00
|
|
|
StreamDebug &StreamDebug::operator<<(float num) {
|
2011-08-31 13:37:42 +00:00
|
|
|
_stream->msg += String::format("%g", num);
|
|
|
|
return maybeSpace();
|
|
|
|
}
|
|
|
|
|
2020-10-16 19:47:16 +00:00
|
|
|
StreamDebug &StreamDebug::operator<<(bool value) {
|
2011-08-31 13:37:42 +00:00
|
|
|
_stream->msg += (value ? "true" : "false");
|
|
|
|
return maybeSpace();
|
|
|
|
}
|
|
|
|
|
2020-10-16 19:47:16 +00:00
|
|
|
StreamDebug &StreamDebug::operator<<(void *p) {
|
2011-09-14 20:50:18 +00:00
|
|
|
_stream->msg += String::format("%p", p);
|
|
|
|
return maybeSpace();
|
|
|
|
}
|
|
|
|
|
2020-10-16 19:47:16 +00:00
|
|
|
StreamDebug &StreamDebug::operator=(const StreamDebug &other) {
|
2011-08-31 13:37:42 +00:00
|
|
|
_stream = other._stream;
|
|
|
|
++_stream->ref;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-10-16 19:47:16 +00:00
|
|
|
Common::StreamDebug streamDbg(int level) {
|
|
|
|
return Common::StreamDebug(level);
|
2011-08-31 13:37:42 +00:00
|
|
|
}
|