From 1dd65057a8add544058de1edc46fe48dc7c09049 Mon Sep 17 00:00:00 2001 From: Tom Hicks Date: Sat, 1 Jul 2006 23:08:51 -0400 Subject: [PATCH] Added Interface Logger Added Class WindowsLogger which logs messages via the Windows MessageBox function ~G2k --- src/Logger.h | 13 ++++++++++++ src/WindowsLogger.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++ src/WindowsLogger.h | 20 ++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 src/Logger.h create mode 100644 src/WindowsLogger.cpp create mode 100644 src/WindowsLogger.h diff --git a/src/Logger.h b/src/Logger.h new file mode 100644 index 0000000..0d23b4c --- /dev/null +++ b/src/Logger.h @@ -0,0 +1,13 @@ +#pragma once + +namespace OpenArena +{ + class Logger + { + public: + enum MessageType{MESSAGETYPE_ALL, MESSAGETYPE_NONE, MESSAGETYPE_INFORMATION, MESSAGETYPE_ERROR, MESSAGETYPE_DEBUG}; + virtual ~Logger(void){} + virtual void Log(const char* message, MessageType type=MESSAGETYPE_INFORMATION) = 0; + virtual void Log(const char* message, const char* classification, MessageType type=MESSAGETYPE_INFORMATION) = 0; + }; +}; diff --git a/src/WindowsLogger.cpp b/src/WindowsLogger.cpp new file mode 100644 index 0000000..edbbfac --- /dev/null +++ b/src/WindowsLogger.cpp @@ -0,0 +1,47 @@ +#include +#include "WindowsLogger.h" +#include +namespace OpenArena +{ + WindowsLogger::WindowsLogger() + { + _type = MESSAGETYPE_ALL; + } + + WindowsLogger::~WindowsLogger(void) + { + } + + WindowsLogger::WindowsLogger(Logger::MessageType type) + { + _type = type; + } + + void WindowsLogger::Log(const char* message, MessageType type) + { + Log(message, "unspecified", type); + } + + void WindowsLogger::Log(const char* message, const char* classification, MessageType type) + { + if(_type != MESSAGETYPE_NONE || _type == type || _type == MESSAGETYPE_ALL) + { + MessageBox(NULL, message, classification, MB_OK | GetIconFromMessageType(type)); + } + } + + uint32 WindowsLogger::GetIconFromMessageType(MessageType type) + { + switch (type) + { + case MESSAGETYPE_ERROR: + return MB_ICONERROR; + case MESSAGETYPE_INFORMATION: + return MB_ICONINFORMATION; + case MESSAGETYPE_DEBUG: + return MB_ICONWARNING; + default: + return MB_ICONASTERISK; + }; + } +}; \ No newline at end of file diff --git a/src/WindowsLogger.h b/src/WindowsLogger.h new file mode 100644 index 0000000..ada6439 --- /dev/null +++ b/src/WindowsLogger.h @@ -0,0 +1,20 @@ +#pragma once +#include "logger.h" +#include "datatypes.h" + +namespace OpenArena +{ + class WindowsLogger : + public OpenArena::Logger + { + private: + uint32 GetIconFromMessageType(MessageType type); + MessageType _type; + public: + WindowsLogger(); + WindowsLogger(Logger::MessageType type); + virtual void Log(const char* message, MessageType type=MESSAGETYPE_INFORMATION); + virtual void Log(const char* message, const char* classification, MessageType type=MESSAGETYPE_INFORMATION); + virtual ~WindowsLogger(); + }; +}; \ No newline at end of file