2017-06-20 10:40:39 +02:00
|
|
|
/******************************************************************************
|
|
|
|
** libDXFrw - Library to read/write DXF files (ascii & binary) **
|
|
|
|
** **
|
|
|
|
** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com **
|
|
|
|
** **
|
|
|
|
** This library is free software, licensed 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. **
|
|
|
|
** You should have received a copy of the GNU General Public License **
|
|
|
|
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
2021-11-22 18:28:51 +01:00
|
|
|
#include <memory>
|
2017-06-20 10:40:39 +02:00
|
|
|
#include "drw_dbg.h"
|
|
|
|
|
2021-11-22 18:28:51 +01:00
|
|
|
DRW_dbg *DRW_dbg::instance{nullptr};
|
2017-06-20 10:40:39 +02:00
|
|
|
|
|
|
|
/*********private clases*************/
|
|
|
|
|
2021-11-23 12:11:56 +01:00
|
|
|
class print_debug : public DRW::DebugPrinter {
|
2017-06-20 10:40:39 +02:00
|
|
|
public:
|
2021-11-22 18:28:51 +01:00
|
|
|
void printS(const std::string &s) override;
|
|
|
|
void printI(long long int i) override;
|
|
|
|
void printUI(long long unsigned int i) override;
|
|
|
|
void printD(double d) override;
|
|
|
|
void printH(long long int i) override;
|
|
|
|
void printB(int i) override;
|
|
|
|
void printHL(int c, int s, int h) override;
|
|
|
|
void printPT(double x, double y, double z) override;
|
|
|
|
print_debug()=default;
|
2017-06-20 10:40:39 +02:00
|
|
|
private:
|
2021-11-22 18:28:51 +01:00
|
|
|
std::ios_base::fmtflags flags{std::cerr.flags()};
|
2017-06-20 10:40:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/********* debug class *************/
|
|
|
|
DRW_dbg *DRW_dbg::getInstance(){
|
2021-11-22 18:28:51 +01:00
|
|
|
if (instance == nullptr){
|
2017-06-20 10:40:39 +02:00
|
|
|
instance = new DRW_dbg;
|
|
|
|
}
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2021-11-22 18:28:51 +01:00
|
|
|
DRW_dbg::DRW_dbg() :
|
2021-11-23 12:11:56 +01:00
|
|
|
debugPrinter(std::make_unique<print_debug>())
|
|
|
|
{
|
|
|
|
currentPrinter = &silentDebug;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DRW_dbg::setCustomDebugPrinter(std::unique_ptr<DRW::DebugPrinter> printer)
|
|
|
|
{
|
|
|
|
debugPrinter = std::move( printer );
|
|
|
|
if (level == Level::Debug){
|
|
|
|
currentPrinter = debugPrinter.get();
|
|
|
|
}
|
|
|
|
}
|
2017-06-20 10:40:39 +02:00
|
|
|
|
2021-11-23 10:28:54 +01:00
|
|
|
void DRW_dbg::setLevel(Level lvl){
|
2017-06-20 10:40:39 +02:00
|
|
|
level = lvl;
|
|
|
|
switch (level){
|
2021-11-23 10:28:54 +01:00
|
|
|
case Level::Debug:
|
2021-11-23 12:11:56 +01:00
|
|
|
currentPrinter = debugPrinter.get();
|
2017-06-20 10:40:39 +02:00
|
|
|
break;
|
|
|
|
default:
|
2021-11-23 12:11:56 +01:00
|
|
|
currentPrinter = &silentDebug;
|
|
|
|
break;
|
2017-06-20 10:40:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-23 10:28:54 +01:00
|
|
|
DRW_dbg::Level DRW_dbg::getLevel() const{
|
2017-06-20 10:40:39 +02:00
|
|
|
return level;
|
|
|
|
}
|
|
|
|
|
2018-06-26 14:53:48 +02:00
|
|
|
void DRW_dbg::print(const std::string &s){
|
2021-11-23 12:11:56 +01:00
|
|
|
currentPrinter->printS(s);
|
2017-06-20 10:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DRW_dbg::print(int i){
|
2021-11-23 12:11:56 +01:00
|
|
|
currentPrinter->printI(i);
|
2017-06-20 10:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DRW_dbg::print(unsigned int i){
|
2021-11-23 12:11:56 +01:00
|
|
|
currentPrinter->printUI(i);
|
2017-06-20 10:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DRW_dbg::print(long long int i){
|
2021-11-23 12:11:56 +01:00
|
|
|
currentPrinter->printI(i);
|
2017-06-20 10:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DRW_dbg::print(long unsigned int i){
|
2021-11-23 12:11:56 +01:00
|
|
|
currentPrinter->printUI(i);
|
2017-06-20 10:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DRW_dbg::print(long long unsigned int i){
|
2021-11-23 12:11:56 +01:00
|
|
|
currentPrinter->printUI(i);
|
2017-06-20 10:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DRW_dbg::print(double d){
|
2021-11-23 12:11:56 +01:00
|
|
|
currentPrinter->printD(d);
|
2017-06-20 10:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DRW_dbg::printH(long long int i){
|
2021-11-23 12:11:56 +01:00
|
|
|
currentPrinter->printH(i);
|
2017-06-20 10:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DRW_dbg::printB(int i){
|
2021-11-23 12:11:56 +01:00
|
|
|
currentPrinter->printB(i);
|
2017-06-20 10:40:39 +02:00
|
|
|
}
|
|
|
|
void DRW_dbg::printHL(int c, int s, int h){
|
2021-11-23 12:11:56 +01:00
|
|
|
currentPrinter->printHL(c, s, h);
|
2017-06-20 10:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DRW_dbg::printPT(double x, double y, double z){
|
2021-11-23 12:11:56 +01:00
|
|
|
currentPrinter->printPT(x, y, z);
|
2017-06-20 10:40:39 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 14:53:48 +02:00
|
|
|
void print_debug::printS(const std::string &s){
|
2017-06-20 10:40:39 +02:00
|
|
|
std::cerr << s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_debug::printI(long long int i){
|
|
|
|
std::cerr << i;
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_debug::printUI(long long unsigned int i){
|
|
|
|
std::cerr << i;
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_debug::printD(double d){
|
|
|
|
std::cerr << std::fixed << d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_debug::printH(long long i){
|
|
|
|
std::cerr << "0x" << std::setw(2) << std::setfill('0');
|
|
|
|
std::cerr << std::hex << i;
|
|
|
|
std::cerr.flags(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_debug::printB(int i){
|
|
|
|
std::cerr << std::setw(8) << std::setfill('0');
|
|
|
|
std::cerr << std::setbase(2) << i;
|
|
|
|
std::cerr.flags(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_debug::printHL(int c, int s, int h){
|
|
|
|
std::cerr << c << '.' << s << '.';
|
|
|
|
std::cerr << "0x" << std::setw(2) << std::setfill('0');
|
|
|
|
std::cerr << std::hex << h;
|
|
|
|
std::cerr.flags(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_debug::printPT(double x, double y, double z){
|
|
|
|
std::cerr << std::fixed << "x: " << x << ", y: " << y << ", z: "<< z;
|
|
|
|
}
|