From f7d846f18354e254353bc417ed1a666c59ef3ea2 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Mon, 9 Jul 2012 03:36:11 +1000 Subject: Better implementation: smarter strategy iteration Also add the beginnings of some log stuff, mayhaps. --- impl/Log.hpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 impl/Log.hpp (limited to 'impl/Log.hpp') diff --git a/impl/Log.hpp b/impl/Log.hpp new file mode 100644 index 0000000..a920906 --- /dev/null +++ b/impl/Log.hpp @@ -0,0 +1,49 @@ +#ifndef LOG_HPP +#define LOG_HPP + +#include +#include +#include + +namespace log { + + struct Logger { + Logger(std::ostream& stream, const std::string& name) + : _stream(stream), + _name(name), + _enabled(false) {} + + bool enabled() const { + return _enabled; + } + + bool enabled(bool v) { + bool ret = _enabled; + _enabled = v; + return ret; + } + + template + friend Logger& operator<<(Logger&, const T&); + + private: + std::ostream& _stream; + std::string _name; + bool _enabled; + }; + + template + Logger& operator<<(Logger& logger, const T& obj) { + if (logger._enabled) { + logger._stream << logger._name << " :- " << obj << std::endl; + } + return logger; + } + + Logger trace(std::cerr, "trace"); + Logger strategy(std::cerr, "strategy"); + Logger debug(std::cerr, "debug"); + +} + +#endif -- cgit v1.2.3