This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/misc/Debug.h
FrankE d0801606b7 fixed dijkstra memleak
new dijkstra interfaces and abort options
refactored all files accordingly
enable logging via compile-time defines
2016-03-18 10:18:17 +01:00

66 lines
1.4 KiB
C++

#ifndef DEBUG_H
#define DEBUG_H
#include <string>
#include <iostream>
#include <iomanip>
#include "Time.h"
/** quick and dirty workaround */
static decltype(Time::tick()) LogLastTick;
#ifdef WITH_DEBUG_LOG
class Log {
public:
static void add(const char* comp, const std::string what, const bool nl = true) {
addComp(comp);
std::cout << what;
if (nl) {std::cout << std::endl;} else {std::cout << std::flush;}
}
static void add(const std::string& component, const std::string what, const bool nl = true) {
addComp(component.c_str());
std::cout << what;
if (nl) {std::cout << std::endl;} else {std::cout << std::flush;}
}
static void tick() {
LogLastTick = Time::tick();
}
static void tock() {
const auto cur = Time::tick();
const int diff_ms = Time::diffMS(LogLastTick, cur);
LogLastTick = cur;
std::cout << " (took: " << diff_ms << "ms)" << std::endl;
}
private:
static void addComp(const char* component) {
std::cout << "[" << std::setw(12) << std::setfill(' ') << component << "] ";
}
};
#else
class Log {
public:
static void add(const char* comp, const std::string what, const bool nl = true) { (void)comp; (void) what; (void) nl; }
static void add(const std::string& component, const std::string what, const bool nl = true) { (void)component; (void) what; (void) nl; }
static void tick() {;}
static void tock() {;}
};
#endif
#endif // DEBUG_H