BWAPI
|
00001 #pragma once 00002 00003 #include "Singleton.h" 00004 00005 #include "Interface.h" 00006 #include <string> 00007 #include <sstream> 00008 #include <fstream> 00009 00010 class String_Builder 00011 { 00012 public: 00013 template<typename T> 00014 String_Builder &operator <<(const T &value) 00015 { 00016 builder << value; 00017 00018 return (*this); 00019 } 00020 00021 operator std::string() 00022 { 00023 return (builder.str()); 00024 } 00025 00026 std::string getString() 00027 { 00028 return (builder.str()); 00029 } 00030 00031 private: 00032 std::ostringstream builder; 00033 }; 00034 00035 class LoggerClass 00036 { 00037 public: 00038 LoggerClass() 00039 { 00040 #if _DEBUG 00041 std::ofstream output("bwapi-data\\Skynet\\SkynetLog.txt", std::ios::trunc); 00042 output.close(); 00043 #endif 00044 } 00045 00046 inline void log(const std::string &message, int level = 0) 00047 { 00048 if(level > 1) 00049 BWAPI::Broodwar->sendText(message.c_str()); 00050 else if(level > 0) 00051 BWAPI::Broodwar->printf(message.c_str()); 00052 00053 #if _DEBUG 00054 std::ofstream output("bwapi-data\\Skynet\\SkynetLog.txt", std::ios::ate | std::ios::app); 00055 output << BWAPI::Broodwar->getFrameCount() << " : " << message << std::endl; 00056 output.close(); 00057 #endif 00058 } 00059 00060 private: 00061 }; 00062 typedef Singleton<LoggerClass> Logger; 00063 00064 #if _DEBUG 00065 #define LOGMESSAGE(message) Logger::Instance().log(message) 00066 #define LOGMESSAGEWARNING(message) Logger::Instance().log(message, 1) 00067 #else 00068 #define LOGMESSAGE(ignore) ((void) 0) 00069 #define LOGMESSAGEWARNING(ignore) ((void) 0) 00070 #endif 00071 00072 #define LOGMESSAGEERROR(message) Logger::Instance().log(message, 2)