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
kazu b503fb9bdc pushing before transfering ownership
added new tests and new helper classes
speed improvements
minor fixes
2016-01-25 17:54:58 +01:00

54 lines
973 B
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;
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;}
}
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;}
}
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 << "] ";
}
};
#endif // DEBUG_H