| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include <iostream> |
| | #include <iomanip> |
| | #include "drw_dbg.h" |
| |
|
| | DRW_dbg *DRW_dbg::instance{nullptr}; |
| |
|
| | |
| |
|
| | class print_debug : public DRW::DebugPrinter { |
| | public: |
| | 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; |
| | private: |
| | std::ios_base::fmtflags flags{std::cerr.flags()}; |
| | }; |
| |
|
| | |
| | DRW_dbg *DRW_dbg::getInstance(){ |
| | if (!instance){ |
| | instance = new DRW_dbg; |
| | } |
| | return instance; |
| | } |
| |
|
| | DRW_dbg::DRW_dbg(){ |
| | debugPrinter.reset(new 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(); |
| | } |
| | } |
| |
|
| | void DRW_dbg::setLevel(Level lvl){ |
| | level = lvl; |
| | switch (level){ |
| | case Level::Debug: |
| | currentPrinter = debugPrinter.get(); |
| | break; |
| | case Level::None: |
| | currentPrinter = &silentDebug; |
| | break; |
| | } |
| | } |
| |
|
| | DRW_dbg::Level DRW_dbg::getLevel(){ |
| | return level; |
| | } |
| |
|
| | void DRW_dbg::print(const std::string &s){ |
| | currentPrinter->printS(s); |
| | } |
| |
|
| | void DRW_dbg::print(signed char i){ |
| | currentPrinter->printI(i); |
| | } |
| |
|
| | void DRW_dbg::print(unsigned char i){ |
| | currentPrinter->printUI(i); |
| | } |
| |
|
| | void DRW_dbg::print(int i){ |
| | currentPrinter->printI(i); |
| | } |
| |
|
| | void DRW_dbg::print(unsigned int i){ |
| | currentPrinter->printUI(i); |
| | } |
| |
|
| | void DRW_dbg::print(long long int i){ |
| | currentPrinter->printI(i); |
| | } |
| |
|
| | void DRW_dbg::print(long unsigned int i){ |
| | currentPrinter->printUI(i); |
| | } |
| |
|
| | void DRW_dbg::print(long long unsigned int i){ |
| | currentPrinter->printUI(i); |
| | } |
| |
|
| | void DRW_dbg::print(double d){ |
| | currentPrinter->printD(d); |
| | } |
| |
|
| | void DRW_dbg::printH(long long int i){ |
| | currentPrinter->printH(i); |
| | } |
| |
|
| | void DRW_dbg::printB(int i){ |
| | currentPrinter->printB(i); |
| | } |
| | void DRW_dbg::printHL(int c, int s, int h){ |
| | currentPrinter->printHL(c, s, h); |
| | } |
| |
|
| | void DRW_dbg::printPT(double x, double y, double z){ |
| | currentPrinter->printPT(x, y, z); |
| | } |
| |
|
| | void print_debug::printS(const std::string &s){ |
| | 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; |
| | } |
| |
|