COMMON: Rename Common::Debug to Common::StreamDebug

This commit is contained in:
Paweł Kołodziejski 2020-10-16 21:47:16 +02:00
parent 985335154e
commit e2cd2e6ed7
12 changed files with 47 additions and 47 deletions

View file

@ -39,23 +39,23 @@ public:
int level;
};
Debug::Debug(int level) :
StreamDebug::StreamDebug(int level) :
_stream(new MessageStream()) {
_stream->level = level;
}
Debug::Debug(const Debug &other) {
StreamDebug::StreamDebug(const StreamDebug &other) {
*this = other;
}
Debug::~Debug() {
StreamDebug::~StreamDebug() {
if (--_stream->ref == 0) {
debug(_stream->level, "%s", _stream->msg.c_str());
delete _stream;
}
}
Debug &Debug::space() {
StreamDebug &StreamDebug::space() {
if (!_stream->space) {
_stream->msg += String(" ");
_stream->space = true;
@ -63,66 +63,66 @@ Debug &Debug::space() {
return *this;
}
Debug &Debug::nospace() {
StreamDebug &StreamDebug::nospace() {
_stream->space = false;
return *this;
}
Debug &Debug::maybeSpace() {
StreamDebug &StreamDebug::maybeSpace() {
if (_stream->space) {
_stream->msg += " ";
}
return *this;
}
Debug &Debug::operator<<(const String &str) {
StreamDebug &StreamDebug::operator<<(const String &str) {
_stream->msg += str;
return maybeSpace();
}
Debug &Debug::operator<<(const char *str) {
StreamDebug &StreamDebug::operator<<(const char *str) {
_stream->msg += str;
return maybeSpace();
}
Debug &Debug::operator<<(char str) {
StreamDebug &StreamDebug::operator<<(char str) {
_stream->msg += str;
return maybeSpace();
}
Debug &Debug::operator<<(int num) {
StreamDebug &StreamDebug::operator<<(int num) {
_stream->msg += String::format("%d", num);
return maybeSpace();
}
Debug &Debug::operator<<(unsigned int num) {
StreamDebug &StreamDebug::operator<<(unsigned int num) {
_stream->msg += String::format("%d", num);
return maybeSpace();
}
#if !defined(__DC__) && !defined(__DS__)
Debug &Debug::operator<<(double num) {
StreamDebug &StreamDebug::operator<<(double num) {
_stream->msg += String::format("%g", num);
return maybeSpace();
}
#endif
Debug &Debug::operator<<(float num) {
StreamDebug &StreamDebug::operator<<(float num) {
_stream->msg += String::format("%g", num);
return maybeSpace();
}
Debug &Debug::operator<<(bool value) {
StreamDebug &StreamDebug::operator<<(bool value) {
_stream->msg += (value ? "true" : "false");
return maybeSpace();
}
Debug &Debug::operator<<(void *p) {
StreamDebug &StreamDebug::operator<<(void *p) {
_stream->msg += String::format("%p", p);
return maybeSpace();
}
Debug &Debug::operator=(const Debug &other) {
StreamDebug &StreamDebug::operator=(const StreamDebug &other) {
_stream = other._stream;
++_stream->ref;
@ -131,6 +131,6 @@ Debug &Debug::operator=(const Debug &other) {
}
Common::Debug streamDbg(int level) {
return Common::Debug(level);
Common::StreamDebug streamDbg(int level) {
return Common::StreamDebug(level);
}

View file

@ -28,39 +28,39 @@ namespace Common {
class String;
class MessageStream;
class Debug {
class StreamDebug {
public:
Debug(int level);
Debug(const Debug &other);
~Debug();
StreamDebug(int level);
StreamDebug(const StreamDebug &other);
~StreamDebug();
Debug &space();
Debug &nospace();
StreamDebug &space();
StreamDebug &nospace();
Debug &operator<<(const String &str);
Debug &operator<<(const char *str);
Debug &operator<<(char str);
Debug &operator<<(int number);
Debug &operator<<(unsigned int number);
StreamDebug &operator<<(const String &str);
StreamDebug &operator<<(const char *str);
StreamDebug &operator<<(char str);
StreamDebug &operator<<(int number);
StreamDebug &operator<<(unsigned int number);
// DC and DS has float and double equal
#if !defined(__DC__) && !defined(__DS__)
Debug &operator<<(double number);
StreamDebug &operator<<(double number);
#endif
Debug &operator<<(float number);
Debug &operator<<(bool value);
Debug &operator<<(void *p);
StreamDebug &operator<<(float number);
StreamDebug &operator<<(bool value);
StreamDebug &operator<<(void *p);
Debug &operator=(const Debug &other);
StreamDebug &operator=(const StreamDebug &other);
private:
Debug &maybeSpace();
StreamDebug &maybeSpace();
MessageStream *_stream;
};
}
Common::Debug streamDbg(int level = -1);
Common::StreamDebug streamDbg(int level = -1);
#endif

View file

@ -58,7 +58,7 @@ void Bookmark::readData(Formats::XRCReadStream *stream) {
}
void Bookmark::printData() {
Common::Debug debug = streamDbg();
Common::StreamDebug debug = streamDbg();
debug << "position: " << _position << "\n";
}

View file

@ -91,7 +91,7 @@ Math::Angle Camera::getHorizontalAngle() const {
}
void Camera::printData() {
Common::Debug debug = streamDbg();
Common::StreamDebug debug = streamDbg();
debug << "position: " << _position << "\n";
debug << "lookDirection: " << _lookDirection << "\n";
debug << "f1: " << _f1 << "\n";

View file

@ -217,7 +217,7 @@ void Floor::enableFloorField(FloorField *floorfield, bool enable) {
void Floor::printData() {
debug("face count: %d", _facesCount);
Common::Debug debug = streamDbg();
Common::StreamDebug debug = streamDbg();
for (uint i = 0; i < _vertices.size(); i++) {
debug << i << ": " << _vertices[i] << "\n";
}

View file

@ -97,7 +97,7 @@ Gfx::LightEntry *Light::getLightEntry() {
}
void Light::printData() {
Common::Debug debug = streamDbg();
Common::StreamDebug debug = streamDbg();
debug << "color: " << _color << "\n";
debug << "position: " << _position << "\n";
debug << "direction: " << _direction << "\n";

View file

@ -171,7 +171,7 @@ Angle Angle::arcTangent2(float y, float x) {
return a;
}
Common::Debug &operator<<(Common::Debug &dbg, const Math::Angle &a) {
Common::StreamDebug &operator<<(Common::StreamDebug &dbg, const Math::Angle &a) {
dbg.nospace() << "Angle(" << a.getDegrees(-180) << ")";
return dbg.space();

View file

@ -26,7 +26,7 @@
#include "common/scummsys.h"
namespace Common {
class Debug;
class StreamDebug;
}
namespace Math {
@ -160,7 +160,7 @@ inline bool operator>(const Angle &a1, const Angle &a2) {
return a1.getDegrees() > a2.getDegrees();
}
Common::Debug &operator<<(Common::Debug &dbg, const Math::Angle &a);
Common::StreamDebug &operator<<(Common::StreamDebug &dbg, const Math::Angle &a);
}

View file

@ -105,7 +105,7 @@ float Line2d::getYatX(float x) const {
return -(_a * x + _c) / _b;
}
Common::Debug &operator<<(Common::Debug &dbg, const Math::Line2d &line) {
Common::StreamDebug &operator<<(Common::StreamDebug &dbg, const Math::Line2d &line) {
if (fabsf(line._a) < 0.0001f) {
dbg.nospace() << "Line2d: <y = " << (-line._a / line._b) << " * x + " << -line._c / line._b << ">";
} else {

View file

@ -41,7 +41,7 @@ public:
float getYatX(float x) const;
friend Common::Debug &operator<<(Common::Debug &dbg, const Line2d &line);
friend Common::StreamDebug &operator<<(Common::StreamDebug &dbg, const Line2d &line);
private:
float _a, _b, _c;

View file

@ -469,7 +469,7 @@ bool operator!=(const Matrix<r, c> &m1, const Matrix<r, c> &m2) {
}
template<int r, int c>
Common::Debug &operator<<(Common::Debug dbg, const Math::Matrix<r, c> &m) {
Common::StreamDebug &operator<<(Common::StreamDebug dbg, const Math::Matrix<r, c> &m) {
dbg.nospace() << "Matrix<" << r << ", " << c << ">(";
for (int col = 0; col < c; ++col) {
dbg << m(0, col) << ", ";

View file

@ -126,7 +126,7 @@ void MatrixType<dim, 1>::readFromStream(Common::ReadStream *stream) {
template<int dim>
Common::Debug &operator<<(Common::Debug dbg, const Math::Matrix<dim, 1> &v) {
Common::StreamDebug &operator<<(Common::StreamDebug dbg, const Math::Matrix<dim, 1> &v) {
dbg.nospace() << "Vector<" << dim << ">(" << v.getValue(0);
for (int i = 1; i < dim; ++i) {
dbg << ", " << v.getValue(i);