Add ioOp for TraceMsg and cleanup MetalClaw

This commit is contained in:
Gary Talent 2018-02-15 22:22:55 -06:00
parent 2b5c34279c
commit 7f3cda0ab3
5 changed files with 35 additions and 11 deletions

View File

@ -159,7 +159,7 @@ int MetalClawReader::op(const char*, T *val, size_t valLen) {
};
template<typename T>
int read(uint8_t *buff, size_t buffLen, T *val) {
int readMC(uint8_t *buff, size_t buffLen, T *val) {
MetalClawReader reader(buff, buffLen);
return ioOp(&reader, val);
}

View File

@ -83,7 +83,7 @@ map<string, int(*)(string)> tests = {
int err = 0;
TestStruct ts;
err |= write(buff, buffLen, &ts);
err |= writeMC(buff, buffLen, &ts);
delete []buff;
@ -109,8 +109,8 @@ map<string, int(*)(string)> tests = {
testIn.Struct.Int = 300;
testIn.Struct.String = "Test String 2";
err |= write(buff, buffLen, &testIn);
err |= read(buff, buffLen, &testOut);
err |= writeMC(buff, buffLen, &testIn);
err |= readMC(buff, buffLen, &testOut);
err |= !(testIn.Bool == testOut.Bool);
err |= !(testIn.Int == testOut.Int);

View File

@ -8,6 +8,7 @@
#pragma once
#include <ox/std/byteswap.hpp>
#include <ox/std/string.hpp>
#include <ox/std/types.hpp>
#include "err.hpp"
@ -44,6 +45,9 @@ class MetalClawWriter {
template<typename T>
int op(const char*, T *val, size_t len);
template<size_t L>
int op(const char*, const char *val);
template<size_t L>
int op(const char*, ox::BString<L> *val);
@ -153,7 +157,7 @@ int MetalClawWriter::op(const char*, T *val, size_t len) {
};
template<typename T>
int write(uint8_t *buff, size_t buffLen, T *val, size_t *sizeOut = nullptr) {
int writeMC(uint8_t *buff, size_t buffLen, T *val, size_t *sizeOut = nullptr) {
MetalClawWriter writer(buff, buffLen);
auto err = ioOp(&writer, val);
if (sizeOut) {

View File

@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <ox/std/std.hpp>
#include <ox/mc/write.hpp>
#include "trace.hpp"
@ -19,4 +19,11 @@ OutStream::OutStream(const char *file, int line, const char *ch, const char *msg
m_msg.msg = msg;
}
OutStream::~OutStream() {
constexpr size_t buffLen = 1024;
size_t size = 0;
uint8_t buff[buffLen];
writeMC(buff, buffLen, &m_msg, &size);
}
}

View File

@ -13,13 +13,24 @@
namespace ox {
struct TraceMsg {
const char *file;
int line;
uint64_t time;
const char *ch;
ox::BString<150> file = "";
int line = 0;
uint64_t time = 0;
ox::BString<50> ch = "";
ox::BString<100> msg;
};
template<typename T>
int ioOp(T *io, ox::TraceMsg *obj) {
int32_t err = 0;
io->setFields(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:
@ -30,6 +41,8 @@ class OutStream {
OutStream(const char *file, int line, const char *ch, const char *msg = "");
~OutStream();
template<typename T>
OutStream &operator<<(T v) {
m_msg.msg += " ";
@ -41,4 +54,4 @@ class OutStream {
}
#define oxTrace(ch, msg) ox::OutStream(__FILE__, __LINE__, ch, msg)
#define oxTrace(ch) ox::OutStream(__FILE__, __LINE__, ch)