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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -171,7 +171,7 @@ Angle Angle::arcTangent2(float y, float x) {
return a; 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) << ")"; dbg.nospace() << "Angle(" << a.getDegrees(-180) << ")";
return dbg.space(); return dbg.space();

View file

@ -26,7 +26,7 @@
#include "common/scummsys.h" #include "common/scummsys.h"
namespace Common { namespace Common {
class Debug; class StreamDebug;
} }
namespace Math { namespace Math {
@ -160,7 +160,7 @@ inline bool operator>(const Angle &a1, const Angle &a2) {
return a1.getDegrees() > a2.getDegrees(); 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; 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) { if (fabsf(line._a) < 0.0001f) {
dbg.nospace() << "Line2d: <y = " << (-line._a / line._b) << " * x + " << -line._c / line._b << ">"; dbg.nospace() << "Line2d: <y = " << (-line._a / line._b) << " * x + " << -line._c / line._b << ">";
} else { } else {

View file

@ -41,7 +41,7 @@ public:
float getYatX(float x) const; 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: private:
float _a, _b, _c; 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> 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 << ">("; dbg.nospace() << "Matrix<" << r << ", " << c << ">(";
for (int col = 0; col < c; ++col) { for (int col = 0; col < c; ++col) {
dbg << m(0, col) << ", "; dbg << m(0, col) << ", ";

View file

@ -126,7 +126,7 @@ void MatrixType<dim, 1>::readFromStream(Common::ReadStream *stream) {
template<int dim> 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); dbg.nospace() << "Vector<" << dim << ">(" << v.getValue(0);
for (int i = 1; i < dim; ++i) { for (int i = 1; i < dim; ++i) {
dbg << ", " << v.getValue(i); dbg << ", " << v.getValue(i);