Added Interface Logger
Added Class WindowsLogger which logs messages via the Windows MessageBox function ~G2k
This commit is contained in:
13
src/Logger.h
Normal file
13
src/Logger.h
Normal file
@@ -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;
|
||||||
|
};
|
||||||
|
};
|
||||||
47
src/WindowsLogger.cpp
Normal file
47
src/WindowsLogger.cpp
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#include <cstdlib>
|
||||||
|
#include "WindowsLogger.h"
|
||||||
|
#include <windows.h>
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
20
src/WindowsLogger.h
Normal file
20
src/WindowsLogger.h
Normal file
@@ -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();
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user