Make this a default implementation of Logger rather than a special case in Log
This commit is contained in:
@@ -24,6 +24,8 @@
|
||||
#include "faster/R2Stretcher.h"
|
||||
#include "finer/R3Stretcher.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace RubberBand {
|
||||
|
||||
class RubberBandStretcher::Impl
|
||||
@@ -31,6 +33,26 @@ class RubberBandStretcher::Impl
|
||||
R2Stretcher *m_r2;
|
||||
R3Stretcher *m_r3;
|
||||
|
||||
class CerrLogger : public RubberBandStretcher::Logger {
|
||||
public:
|
||||
void log(const char *message) override {
|
||||
std::cerr << "RubberBand: " << message << "\n";
|
||||
}
|
||||
void log(const char *message, double arg0) override {
|
||||
auto prec = std::cerr.precision();
|
||||
std::cerr.precision(10);
|
||||
std::cerr << "RubberBand: " << message << ": " << arg0 << "\n";
|
||||
std::cerr.precision(prec);
|
||||
}
|
||||
void log(const char *message, double arg0, double arg1) override {
|
||||
auto prec = std::cerr.precision();
|
||||
std::cerr.precision(10);
|
||||
std::cerr << "RubberBand: " << message
|
||||
<< ": (" << arg0 << ", " << arg1 << ")" << "\n";
|
||||
std::cerr.precision(prec);
|
||||
}
|
||||
};
|
||||
|
||||
Log makeRBLog(std::shared_ptr<RubberBandStretcher::Logger> logger) {
|
||||
if (logger) {
|
||||
return Log(
|
||||
@@ -45,7 +67,8 @@ class RubberBandStretcher::Impl
|
||||
}
|
||||
);
|
||||
} else {
|
||||
return Log::makeCoutLog();
|
||||
return makeRBLog(std::shared_ptr<RubberBandStretcher::Logger>
|
||||
(new CerrLogger()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,27 +28,4 @@ namespace RubberBand
|
||||
|
||||
int Log::m_defaultDebugLevel = 0;
|
||||
|
||||
Log
|
||||
Log::makeCoutLog()
|
||||
{
|
||||
return Log(
|
||||
[](const char *message) {
|
||||
std::cout << "RubberBand: " << message << "\n";
|
||||
},
|
||||
[](const char *message, double arg0) {
|
||||
auto prec = std::cout.precision();
|
||||
std::cout.precision(10);
|
||||
std::cout << "RubberBand: " << message << ": " << arg0 << "\n";
|
||||
std::cout.precision(prec);
|
||||
},
|
||||
[](const char *message, double arg0, double arg1) {
|
||||
auto prec = std::cout.precision();
|
||||
std::cout.precision(10);
|
||||
std::cout << "RubberBand: " << message
|
||||
<< ": (" << arg0 << ", " << arg1 << ")" << "\n";
|
||||
std::cout.precision(prec);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,19 +39,10 @@ public:
|
||||
m_log2(_log2),
|
||||
m_debugLevel(m_defaultDebugLevel) { }
|
||||
|
||||
Log(const Log &other) :
|
||||
m_log0(other.m_log0),
|
||||
m_log1(other.m_log1),
|
||||
m_log2(other.m_log2),
|
||||
m_debugLevel(other.m_debugLevel) { }
|
||||
|
||||
Log &operator=(const Log &other) {
|
||||
m_log0 = other.m_log0;
|
||||
m_log1 = other.m_log1;
|
||||
m_log2 = other.m_log2;
|
||||
m_debugLevel = other.m_debugLevel;
|
||||
return *this;
|
||||
}
|
||||
Log(const Log &other) =default;
|
||||
Log(Log &&other) =default;
|
||||
Log &operator=(const Log &other) =default;
|
||||
Log &operator=(Log &&other) =default;
|
||||
|
||||
void setDebugLevel(int level) { m_debugLevel = level; }
|
||||
int getDebugLevel() const { return m_debugLevel; }
|
||||
@@ -68,8 +59,6 @@ public:
|
||||
if (level <= m_debugLevel) m_log2(message, arg0, arg1);
|
||||
}
|
||||
|
||||
static Log makeCoutLog();
|
||||
|
||||
private:
|
||||
std::function<void(const char *)> m_log0;
|
||||
std::function<void(const char *, double)> m_log1;
|
||||
|
||||
Reference in New Issue
Block a user