Merge commit '8559ab53ccc74e63924b4a9a31bc91ee1dafefa9' as 'deps/ox'

This commit is contained in:
2017-10-11 19:20:46 -05:00
63 changed files with 5684 additions and 0 deletions

25
deps/ox/src/ox/log/CMakeLists.txt vendored Normal file
View File

@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 2.8)
add_library(
OxLog
log.cpp
)
set_property(
TARGET
OxLog
PROPERTY
POSITION_INDEPENDENT_CODE ON
)
install(
FILES
log.hpp
DESTINATION
include/ox/mc
)
install(TARGETS OxLog
LIBRARY DESTINATION lib/ox
ARCHIVE DESTINATION lib/ox
)

105
deps/ox/src/ox/log/log.cpp vendored Normal file
View File

@@ -0,0 +1,105 @@
/*
* Copyright 2015 - 2017 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <stdarg.h>
#include <stdio.h>
#include "log.hpp"
namespace ox {
class Logger {
private:
// void* stand-in for FILE*
const char *m_path = nullptr;
public:
Logger(const char *path = nullptr);
~Logger();
void log(LogLevel_t level, const char *msg, va_list args);
void info(const char *msg, ...);
void debug(const char *msg, ...);
void error(const char *msg, ...);
};
Logger::Logger(const char *path) {
m_path = path;
}
Logger::~Logger() {
}
void Logger::log(LogLevel_t level, const char *msg, va_list args) {
if (m_path) {
auto file = fopen(m_path, "a");
vfprintf(file, msg, args);
fprintf(file, "\n");
fclose(file);
}
}
void Logger::info(const char *msg, ...) {
va_list args;
va_start(args, msg);
log(LogLevel_t::Info, msg, args);
va_end(args);
}
void Logger::debug(const char *msg, ...) {
va_list args;
va_start(args, msg);
log(LogLevel_t::Debug, msg, args);
va_end(args);
}
void Logger::error(const char *msg, ...) {
va_list args;
va_start(args, msg);
log(LogLevel_t::Error, msg, args);
va_end(args);
}
static Logger logger;
void logFile(const char *path) {
logger = Logger(path);
}
void log(LogLevel_t level, const char *msg, va_list args) {
logger.log(level, msg, args);
}
void info(const char *msg, ...) {
va_list args;
va_start(args, msg);
log(LogLevel_t::Info, msg, args);
va_end(args);
}
void debug(const char *msg, ...) {
va_list args;
va_start(args, msg);
log(LogLevel_t::Debug, msg, args);
va_end(args);
}
void error(const char *msg, ...) {
va_list args;
va_start(args, msg);
log(LogLevel_t::Error, msg, args);
va_end(args);
}
}

27
deps/ox/src/ox/log/log.hpp vendored Normal file
View File

@@ -0,0 +1,27 @@
/*
* Copyright 2015 - 2017 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
namespace ox {
enum class LogLevel_t: int {
Info,
Debug,
Error,
};
void logFile(const char *path);
void info(const char *msg, ...);
void debug(const char *msg, ...);
void error(const char *msg, ...);
}