Initial commit.

This commit is contained in:
jmsgrogan 2020-05-02 08:31:03 +01:00
commit 59c6161fdb
134 changed files with 4751 additions and 0 deletions

13
src/core/CMakeLists.txt Normal file
View file

@ -0,0 +1,13 @@
list(APPEND core_LIB_INCLUDES
Event.cpp
Color.cpp
CommandLineArgs.cpp
loggers/FileLogger.cpp
StringUtils.cpp)
# add the executable
add_library(core SHARED ${core_LIB_INCLUDES})
target_include_directories(core PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}"
)

36
src/core/Color.cpp Normal file
View file

@ -0,0 +1,36 @@
#include "Color.h"
Color::Color(unsigned r, unsigned g, unsigned b, double a)
: mR(r),
mG(g),
mB(b),
mAlpha(a)
{
}
std::shared_ptr<Color> Color::Create(unsigned r, unsigned g, unsigned b,
double a )
{
return std::make_shared<Color>(r, g, b, a);
}
unsigned Color::GetR()
{
return mR;
}
unsigned Color::GetG()
{
return mG;
}
unsigned Color::GetB()
{
return mB;
}
double Color::GetAlpha()
{
return mAlpha;
}

23
src/core/Color.h Normal file
View file

@ -0,0 +1,23 @@
#pragma once
#include <memory>
class Color
{
unsigned mR;
unsigned mG;
unsigned mB;
double mAlpha;
public:
Color(unsigned r, unsigned g, unsigned b, double a = 1.0);
static std::shared_ptr<Color> Create(unsigned r, unsigned g, unsigned b, double a = 1.0);
unsigned GetR();
unsigned GetG();
unsigned GetB();
double GetAlpha();
};
using ColorPtr = std::shared_ptr<Color>;

View file

@ -0,0 +1,29 @@
#include "CommandLineArgs.h"
CommandLineArgs::CommandLineArgs()
: mArugments()
{
}
void CommandLineArgs::Process(int argc, char *argv[])
{
for(int idx=0; idx<argc; idx++)
{
mArugments.push_back(std::string(argv[idx]));
}
}
std::size_t CommandLineArgs::GetNumberOfArgs() const
{
return mArugments.size();
}
std::string CommandLineArgs::GetArg(std::size_t index) const
{
if(index<mArugments.size())
{
return mArugments[index];
}
return "";
}

View file

@ -0,0 +1,19 @@
#pragma once
#include <memory>
#include <vector>
#include <string>
class CommandLineArgs
{
std::vector<std::string> mArugments;
public:
CommandLineArgs();
void Process(int argc, char *argv[]);
std::size_t GetNumberOfArgs() const;
std::string GetArg(std::size_t index) const;
};

11
src/core/Event.cpp Normal file
View file

@ -0,0 +1,11 @@
#include "Event.h"
Event::Event()
{
}
Event::~Event()
{
}

8
src/core/Event.h Normal file
View file

@ -0,0 +1,8 @@
class Event
{
public:
Event();
~Event();
};

14
src/core/StringUtils.cpp Normal file
View file

@ -0,0 +1,14 @@
#include "StringUtils.h"
#include <locale>
bool StringUtils::IsAlphaNumeric(char c)
{
std::locale loc;
return std::isalnum(c, loc);
}
bool StringUtils::IsSpace(char c)
{
std::locale loc;
return std::isspace(c, loc);
}

19
src/core/StringUtils.h Normal file
View file

@ -0,0 +1,19 @@
#pragma once
#include <string>
class StringUtils
{
public:
static constexpr char LEFT_BRACKET = '<';
static constexpr char RIGHT_BRACKET = '>';
static constexpr char FORWARD_SLASH = '/';
static constexpr char BACK_SLASH = '\\';
static constexpr char QUESTION_MARK = '?';
static constexpr char EQUALS = '=';
static constexpr char DOUBLE_QUOTE = '"';
static constexpr char SINGLE_QUOTE = '\'';
static bool IsAlphaNumeric(char c);
static bool IsSpace(char c);
};

View file

@ -0,0 +1,38 @@
#include "HttpResponse.h"
HttpResponse::HttpResponse()
:mHttpVersion("1.1"),
mResponseCode("200 OK"),
mContentType("text/plain"),
mBody()
{
}
HttpResponse::~HttpResponse()
{
}
void HttpResponse::SetBody(const std::string& body)
{
mBody = body;
}
unsigned HttpResponse::GetBodyLength()
{
return mBody.length();
}
std::string HttpResponse::GetHeaderString()
{
std::string header = "HTTP/" + mHttpVersion + " " + mResponseCode + "\n";
header += "Content-Type: " + mContentType + "\n";
header += "Content-Length: " + std::to_string(GetBodyLength()) + "\n";
return header;
}
std::string HttpResponse::ToString()
{
return GetHeaderString() + "\n\n" + mBody;
}

View file

@ -0,0 +1,26 @@
#pragma once
#include <string>
class HttpResponse
{
std::string mHttpVersion;
std::string mResponseCode;
std::string mContentType;
std::string mBody;
public:
HttpResponse();
~HttpResponse();
void SetBody(const std::string& body);
unsigned GetBodyLength();
std::string GetHeaderString();
std::string ToString();
};

View file

@ -0,0 +1,44 @@
#include "FileLogger.h"
FileLogger::FileLogger()
:mWorkDirectory(),
mFileName("MT_Log.txt"),
mFileStream()
{
}
FileLogger::~FileLogger()
{
}
void FileLogger::SetWorkDirectory(const std::string& workDir)
{
mWorkDirectory = workDir;
}
void FileLogger::SetFileName(const std::string& fileName)
{
mFileName = fileName;
}
void FileLogger::Open()
{
mFileStream.open(mWorkDirectory + "/" + mFileName);
}
void FileLogger::Close()
{
mFileStream.close();
}
void FileLogger::LogLine(const std::string& line)
{
mFileStream << line << std::endl;
}
std::shared_ptr<FileLogger> FileLogger::Create()
{
return std::make_shared<FileLogger>();
}

View file

@ -0,0 +1,35 @@
#pragma once
#include <memory>
#include <string>
#include <fstream>
class FileLogger
{
std::string mWorkDirectory;
std::string mFileName;
std::ofstream mFileStream;
public:
FileLogger();
~FileLogger();
void SetWorkDirectory(const std::string& workDir);
void SetFileName(const std::string& fileName);
void Open();
void Close();
void LogLine(const std::string& line);
static std::shared_ptr<FileLogger> Create();
};
using FileLoggerPtr = std::shared_ptr<FileLogger>;