[ox] Move buildinfo and trace packages into std
This commit is contained in:
10
deps/ox/src/ox/std/CMakeLists.txt
vendored
10
deps/ox/src/ox/std/CMakeLists.txt
vendored
@@ -1,13 +1,13 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
add_library(
|
||||
OxStd
|
||||
assert.cpp
|
||||
buildinfo.cpp
|
||||
byteswap.cpp
|
||||
memops.cpp
|
||||
random.cpp
|
||||
stacktrace.cpp
|
||||
strops.cpp
|
||||
trace.cpp
|
||||
)
|
||||
|
||||
set_property(
|
||||
@@ -17,14 +17,15 @@ set_property(
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
)
|
||||
|
||||
target_link_libraries(OxStd PUBLIC OxTrace)
|
||||
|
||||
install(
|
||||
FILES
|
||||
assert.hpp
|
||||
bitops.hpp
|
||||
buildinfo.hpp
|
||||
byteswap.hpp
|
||||
defines.hpp
|
||||
error.hpp
|
||||
hashmap.hpp
|
||||
math.hpp
|
||||
memops.hpp
|
||||
new.hpp
|
||||
@@ -34,6 +35,7 @@ install(
|
||||
strops.hpp
|
||||
std.hpp
|
||||
stddef.hpp
|
||||
trace.hpp
|
||||
types.hpp
|
||||
typetraits.hpp
|
||||
vector.hpp
|
||||
|
3
deps/ox/src/ox/std/assert.cpp
vendored
3
deps/ox/src/ox/std/assert.cpp
vendored
@@ -11,8 +11,7 @@
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
#include <ox/__buildinfo/defines.hpp>
|
||||
|
||||
#include "defines.hpp"
|
||||
#include "stacktrace.hpp"
|
||||
#include "assert.hpp"
|
||||
|
||||
|
3
deps/ox/src/ox/std/assert.hpp
vendored
3
deps/ox/src/ox/std/assert.hpp
vendored
@@ -8,8 +8,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/__buildinfo/defines.hpp>
|
||||
|
||||
#include "defines.hpp"
|
||||
#include "error.hpp"
|
||||
|
||||
namespace ox {
|
||||
|
42
deps/ox/src/ox/std/buildinfo.cpp
vendored
Normal file
42
deps/ox/src/ox/std/buildinfo.cpp
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2015 - 2018 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/.
|
||||
*/
|
||||
|
||||
namespace ox::buildinfo {
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunused-const-variable"
|
||||
|
||||
#if defined(OX_USE_STDLIB)
|
||||
const bool UseStdLib = true;
|
||||
#else
|
||||
const bool UseStdLib = false;
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG)
|
||||
const bool Debug = true;
|
||||
#else
|
||||
const bool Debug = false;
|
||||
#endif
|
||||
|
||||
#if defined(NDEBUG)
|
||||
const bool NDebug = true;
|
||||
#else
|
||||
const bool NDebug = false;
|
||||
#endif
|
||||
|
||||
#if defined(__BIG_ENDIAN__)
|
||||
const bool BigEndian = true;
|
||||
const bool LittleEndian = false;
|
||||
#else
|
||||
const bool BigEndian = false;
|
||||
const bool LittleEndian = true;
|
||||
#endif
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
}
|
17
deps/ox/src/ox/std/buildinfo.hpp
vendored
Normal file
17
deps/ox/src/ox/std/buildinfo.hpp
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2015 - 2018 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/.
|
||||
*/
|
||||
|
||||
namespace ox::buildinfo {
|
||||
|
||||
extern const bool UseStdLib;
|
||||
extern const bool Debug;
|
||||
extern const bool NDebug;
|
||||
extern const bool BigEndian;
|
||||
extern const bool LittleEndian;
|
||||
|
||||
}
|
3
deps/ox/src/ox/std/byteswap.hpp
vendored
3
deps/ox/src/ox/std/byteswap.hpp
vendored
@@ -8,8 +8,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/__buildinfo/defines.hpp>
|
||||
|
||||
#include "defines.hpp"
|
||||
#include "types.hpp"
|
||||
#include "typetraits.hpp"
|
||||
|
||||
|
39
deps/ox/src/ox/std/defines.hpp
vendored
Normal file
39
deps/ox/src/ox/std/defines.hpp
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2015 - 2018 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::defines {
|
||||
|
||||
#if defined(OX_USE_STDLIB)
|
||||
constexpr auto UseStdLib = true;
|
||||
#else
|
||||
constexpr auto UseStdLib = false;
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG)
|
||||
constexpr auto Debug = true;
|
||||
#else
|
||||
constexpr auto Debug = false;
|
||||
#endif
|
||||
|
||||
#if defined(NDEBUG)
|
||||
constexpr auto NDebug = true;
|
||||
#else
|
||||
constexpr auto NDebug = false;
|
||||
#endif
|
||||
|
||||
#if defined(__BIG_ENDIAN__)
|
||||
constexpr auto BigEndian = true;
|
||||
constexpr auto LittleEndian = false;
|
||||
#else
|
||||
constexpr auto BigEndian = false;
|
||||
constexpr auto LittleEndian = true;
|
||||
#endif
|
||||
|
||||
}
|
3
deps/ox/src/ox/std/new.hpp
vendored
3
deps/ox/src/ox/std/new.hpp
vendored
@@ -8,8 +8,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/__buildinfo/defines.hpp>
|
||||
|
||||
#include "defines.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
|
2
deps/ox/src/ox/std/test/CMakeLists.txt
vendored
2
deps/ox/src/ox/std/test/CMakeLists.txt
vendored
@@ -5,7 +5,7 @@ add_executable(
|
||||
tests.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(StdTest OxTrace OxStd)
|
||||
target_link_libraries(StdTest OxStd)
|
||||
|
||||
add_test("Test\\ ox_memcmp\\ ABCDEFG\\ !=\\ HIJKLMN" StdTest "ABCDEFG != HIJKLMN")
|
||||
add_test("Test\\ ox_memcmp\\ HIJKLMN\\ !=\\ ABCDEFG" StdTest "HIJKLMN != ABCDEFG")
|
||||
|
96
deps/ox/src/ox/std/trace.cpp
vendored
Normal file
96
deps/ox/src/ox/std/trace.cpp
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright 2015 - 2018 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/.
|
||||
*/
|
||||
|
||||
#if defined(OX_USE_STDLIB)
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <ox/mc/write.hpp>
|
||||
|
||||
#include "trace.hpp"
|
||||
|
||||
namespace ox::trace {
|
||||
|
||||
#if defined(OX_USE_STDLIB)
|
||||
static const auto OxPrintTrace = std::getenv("OXTRACE");
|
||||
#else
|
||||
static const auto OxPrintTrace = false;
|
||||
#endif
|
||||
|
||||
namespace gdblogger {
|
||||
|
||||
void captureLogFunc([[maybe_unused]] const char *file, [[maybe_unused]] int line,
|
||||
[[maybe_unused]] const char *ch, [[maybe_unused]] const char *msg) {
|
||||
}
|
||||
|
||||
void logFunc(const char *file, int line, const char *ch, const char *msg) {
|
||||
captureLogFunc(file, line, ch, msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
OutStream::OutStream(const char *file, int line, const char *ch, const char *msg) {
|
||||
m_msg.file = file;
|
||||
m_msg.line = line;
|
||||
m_msg.ch = ch;
|
||||
m_msg.msg = msg;
|
||||
}
|
||||
|
||||
OutStream::~OutStream() {
|
||||
gdblogger::logFunc(m_msg.file.c_str(), m_msg.line, m_msg.ch.c_str(), m_msg.msg.c_str());
|
||||
#if defined(OX_USE_STDLIB)
|
||||
if (OxPrintTrace) {
|
||||
auto pipe = fopen(OxPrintTrace, "a");
|
||||
if (pipe) {
|
||||
constexpr std::size_t buffLen = 1024;
|
||||
std::size_t size = 0;
|
||||
uint8_t buff[buffLen];
|
||||
writeMC(buff, buffLen, &m_msg, &size);
|
||||
|
||||
//write(pipe, buff, size);
|
||||
fclose(pipe);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
StdOutStream::StdOutStream(const char *file, int line, const char *ch, const char *msg) {
|
||||
m_msg.file = file;
|
||||
m_msg.line = line;
|
||||
m_msg.ch = ch;
|
||||
m_msg.msg = msg;
|
||||
}
|
||||
|
||||
StdOutStream::~StdOutStream() {
|
||||
gdblogger::logFunc(m_msg.file.c_str(), m_msg.line, m_msg.ch.c_str(), m_msg.msg.c_str());
|
||||
#if defined(OX_USE_STDLIB)
|
||||
if (OxPrintTrace) {
|
||||
std::cout << std::setw(53) << std::left << m_msg.ch.c_str() << '|';
|
||||
std::cout << std::setw(65) << std::left << m_msg.msg.c_str() << '|';
|
||||
std::cout << " " << m_msg.file.c_str() << ':' << m_msg.line << "\n";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void logError(const char *file, int line, Error err) {
|
||||
if (err) {
|
||||
ErrorInfo ei(err);
|
||||
TraceStream trc(file, line, "ox::error");
|
||||
trc << "Error:" << ei.errCode;
|
||||
if (ei.file != nullptr) {
|
||||
trc << "(" << reinterpret_cast<const char*>(ei.file) << ":" << ei.line << ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
129
deps/ox/src/ox/std/trace.hpp
vendored
Normal file
129
deps/ox/src/ox/std/trace.hpp
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright 2015 - 2018 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
|
||||
|
||||
#include <ox/std/std.hpp>
|
||||
|
||||
namespace ox::trace {
|
||||
|
||||
struct TraceMsg {
|
||||
ox::BString<255> file = "";
|
||||
int line = 0;
|
||||
uint64_t time = 0;
|
||||
ox::BString<75> ch = "";
|
||||
ox::BString<100> msg;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
int ioOp(T *io, ox::trace::TraceMsg *obj) {
|
||||
int32_t err = 0;
|
||||
io->setTypeInfo("ox::trace::TraceMsg", 5);
|
||||
err |= io->op("file", &obj->file);
|
||||
err |= io->op("line", &obj->line);
|
||||
err |= io->op("time", &obj->time);
|
||||
err |= io->op("msg", &obj->msg);
|
||||
return err;
|
||||
}
|
||||
|
||||
class OutStream {
|
||||
|
||||
private:
|
||||
const char *m_delimiter = " ";
|
||||
TraceMsg m_msg;
|
||||
|
||||
public:
|
||||
OutStream() = default;
|
||||
|
||||
OutStream(const char *file, int line, const char *ch, const char *msg = "");
|
||||
|
||||
~OutStream();
|
||||
|
||||
template<typename T>
|
||||
inline OutStream &operator<<(const T &v) {
|
||||
m_msg.msg += m_delimiter;
|
||||
m_msg.msg += v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* del sets the delimiter between log segments.
|
||||
*/
|
||||
inline OutStream &del(const char *delimiter) {
|
||||
m_delimiter = delimiter;
|
||||
return *this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class StdOutStream {
|
||||
|
||||
private:
|
||||
const char *m_delimiter = " ";
|
||||
TraceMsg m_msg;
|
||||
|
||||
public:
|
||||
StdOutStream() = default;
|
||||
|
||||
StdOutStream(const char *file, int line, const char *ch, const char *msg = "");
|
||||
|
||||
~StdOutStream();
|
||||
|
||||
template<typename T>
|
||||
constexpr inline StdOutStream &operator<<(const T &v) {
|
||||
m_msg.msg += m_delimiter;
|
||||
m_msg.msg += v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* del sets the delimiter between log segments.
|
||||
*/
|
||||
inline StdOutStream &del(const char *delimiter) {
|
||||
m_delimiter = delimiter;
|
||||
return *this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class NullStream {
|
||||
|
||||
public:
|
||||
constexpr NullStream() = default;
|
||||
|
||||
constexpr NullStream(const char*, int, const char*, const char* = "") {
|
||||
}
|
||||
|
||||
~NullStream() = default;
|
||||
|
||||
template<typename T>
|
||||
constexpr inline NullStream &operator<<(const T&) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline NullStream &del(const char*) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#ifdef DEBUG
|
||||
using TraceStream = OutStream;
|
||||
#else
|
||||
using TraceStream = NullStream;
|
||||
#endif
|
||||
|
||||
void logError(const char *file, int line, Error err);
|
||||
|
||||
}
|
||||
|
||||
#define oxLogError(err) ox::trace::logError(__FILE__, __LINE__, err)
|
||||
|
||||
#define oxTrace(ch) ox::trace::TraceStream(__FILE__, __LINE__, ch)
|
Reference in New Issue
Block a user