Add window support for Windows.
This commit is contained in:
parent
5d32592126
commit
c05b7b6315
27 changed files with 783 additions and 95 deletions
26
src/core/AbstractApp.h
Normal file
26
src/core/AbstractApp.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
class IApplicationContext
|
||||
{
|
||||
public:
|
||||
IApplicationContext() = default;
|
||||
virtual ~IApplicationContext() = default;
|
||||
};
|
||||
|
||||
class AbstractApp
|
||||
{
|
||||
public:
|
||||
AbstractApp() = default;
|
||||
|
||||
virtual ~AbstractApp() = default;
|
||||
IApplicationContext* GetApplicationContext() const
|
||||
{
|
||||
return mApplicationContext.get();
|
||||
}
|
||||
protected:
|
||||
std::unique_ptr<IApplicationContext> mApplicationContext{ nullptr };
|
||||
};
|
||||
|
||||
using AbstractAppPtr = std::unique_ptr<AbstractApp>;
|
|
@ -1,4 +1,5 @@
|
|||
list(APPEND core_HEADERS
|
||||
AbstractApp.h
|
||||
Event.h
|
||||
Color.h
|
||||
CommandLineArgs.h
|
||||
|
|
|
@ -30,6 +30,11 @@ void CommandLineArgs::Process(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
void CommandLineArgs::Process(const std::vector<std::string>& args)
|
||||
{
|
||||
mArugments = args;
|
||||
}
|
||||
|
||||
std::size_t CommandLineArgs::GetNumberOfArgs() const
|
||||
{
|
||||
return mArugments.size();
|
||||
|
|
|
@ -21,6 +21,8 @@ public:
|
|||
|
||||
void Process(int argc, char *argv[]);
|
||||
|
||||
void Process(const std::vector<std::string>& args);
|
||||
|
||||
std::size_t GetNumberOfArgs() const;
|
||||
|
||||
std::string GetArg(std::size_t index) const;
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
#include <locale>
|
||||
#include <algorithm>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Windows.h"
|
||||
#endif
|
||||
|
||||
bool StringUtils::IsAlphaNumeric(char c)
|
||||
{
|
||||
std::locale loc;
|
||||
|
@ -21,3 +25,23 @@ std::string StringUtils::ToLower(const std::string& s)
|
|||
[](unsigned char c){ return std::tolower(c); });
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string StringUtils::convert(const std::wstring& input)
|
||||
{
|
||||
if (input.empty())
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
const auto size = ::WideCharToMultiByte(CP_UTF8, 0, &input[0],
|
||||
(int)input.size(), nullptr, 0, nullptr, nullptr);
|
||||
|
||||
std::string result(size, 0);
|
||||
::WideCharToMultiByte(CP_UTF8, 0, &input[0], (int)input.size(),
|
||||
&result[0], size, nullptr, nullptr);
|
||||
return result;
|
||||
#else
|
||||
throw std::logic_error("Not implemented");
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -17,4 +17,5 @@ public:
|
|||
static bool IsAlphaNumeric(char c);
|
||||
static bool IsSpace(char c);
|
||||
static std::string ToLower(const std::string& s);
|
||||
static std::string convert(const std::wstring& input);
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "FileLogger.h"
|
||||
#include <time.h>
|
||||
#include <iomanip>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
FileLogger::~FileLogger()
|
||||
{
|
||||
|
@ -28,12 +28,12 @@ void FileLogger::Close()
|
|||
mFileStream.close();
|
||||
}
|
||||
|
||||
void FileLogger::LogLine(const std::string& line)
|
||||
void FileLogger::LogLine(const std::ostringstream& line)
|
||||
{
|
||||
mFileStream << line << std::endl;
|
||||
mFileStream << line.str() << std::endl;
|
||||
}
|
||||
|
||||
void FileLogger::LogLine(const std::string& logType, const std::string& line, const std::string& fileName, const std::string& functionName, int lineNumber)
|
||||
void FileLogger::LogLine(const std::string& logType, const std::ostringstream& line, const std::string& fileName, const std::string& functionName, int lineNumber)
|
||||
{
|
||||
std::time_t t = std::time(nullptr);
|
||||
const std::string cleanedFileName = fileName.substr(fileName.find_last_of("/\\") + 1);
|
||||
|
@ -43,5 +43,6 @@ void FileLogger::LogLine(const std::string& logType, const std::string& line, co
|
|||
#else
|
||||
gmtime_r(&t, &time_buf);
|
||||
#endif
|
||||
mFileStream << logType << "|" << std::put_time(&time_buf, "%T") << "|" << cleanedFileName << "::" << functionName << "::" << lineNumber << "|" << line << std::endl;
|
||||
std::cout << logType << "|" << std::put_time(&time_buf, "%T") << "|" << cleanedFileName << "::" << functionName << "::" << lineNumber << "|" << line.str() << std::endl;
|
||||
mFileStream << logType << "|" << std::put_time(&time_buf, "%T") << "|" << cleanedFileName << "::" << functionName << "::" << lineNumber << "|" << line.str() << std::endl;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
#pragma once
|
||||
#define MLOG_INFO(msg) FileLogger::GetInstance().LogLine("Info", msg, __FILE__, __FUNCTION__, __LINE__);
|
||||
#define MLOG_ERROR(msg) FileLogger::GetInstance().LogLine("Error", msg, __FILE__, __FUNCTION__, __LINE__);
|
||||
|
||||
#define MLOG_ALL(msg, level) {std::ostringstream mt_logstream;\
|
||||
mt_logstream << msg; \
|
||||
FileLogger::GetInstance().LogLine(level, mt_logstream, __FILE__, __FUNCTION__, __LINE__);};
|
||||
|
||||
#define MLOG_INFO(msg) MLOG_ALL(msg, "Info");
|
||||
#define MLOG_ERROR(msg) MLOG_ALL(msg, "Error");
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
class FileLogger
|
||||
{
|
||||
|
@ -41,9 +47,9 @@ public:
|
|||
|
||||
void Close();
|
||||
|
||||
void LogLine(const std::string& line);
|
||||
void LogLine(const std::ostringstream& line);
|
||||
|
||||
void LogLine(const std::string& logType, const std::string& line, const std::string& fileName = "", const std::string& functionName = "", int lineNumber=-1);
|
||||
void LogLine(const std::string& logType, const std::ostringstream& line, const std::string& fileName = "", const std::string& functionName = "", int lineNumber=-1);
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue