#pragma once ///////////////////////////////////////////////////////////////////// // Utilities.h - defines Log class and several template functions // // // // Jim Fawcett, CSE776 - Design Patterns, Fall 2017 // ///////////////////////////////////////////////////////////////////// #include #include #include #include namespace Utilities { class Log { public: static bool logging; void set(std::ostream*); void doLog(const std::string& logStr); private: static std::vector pipes; }; bool Log::logging = false; std::vector Log::pipes; inline void Log::set(std::ostream* pStrm) { pipes.push_back(pStrm); } inline void Log::doLog(const std::string& logMsg) { if (!logging) return; for (std::ostream* pStrm : pipes) *pStrm << logMsg; } template std::string toString(T t) { std::ostringstream out; out << t; return out.str(); } inline void putLine(size_t n = 1) { for (size_t i = 0; i < n; ++i) std::cout << "\n"; } template void title(const std::string& msg, std::ostream& out = std::cout) { out << "\n " << msg; std::string underline(msg.size() + 2, ch); out << "\n " << underline; } }