changed things to include plog
This commit is contained in:
parent
b018a44f10
commit
68a1618743
34 changed files with 2702 additions and 27 deletions
40
include/plog/Helpers/AscDump.h
Normal file
40
include/plog/Helpers/AscDump.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
#pragma once
|
||||
#include <plog/Util.h>
|
||||
#include <cctype>
|
||||
|
||||
namespace plog
|
||||
{
|
||||
class AscDump
|
||||
{
|
||||
public:
|
||||
AscDump(const void* ptr, size_t size)
|
||||
: m_ptr(static_cast<const char*>(ptr))
|
||||
, m_size(size)
|
||||
{
|
||||
}
|
||||
|
||||
friend util::nostringstream& operator<<(util::nostringstream& stream, const AscDump& ascDump);
|
||||
|
||||
private:
|
||||
const char* m_ptr;
|
||||
size_t m_size;
|
||||
};
|
||||
|
||||
inline util::nostringstream& operator<<(util::nostringstream& stream, const AscDump& ascDump)
|
||||
{
|
||||
for (size_t i = 0; i < ascDump.m_size; ++i)
|
||||
{
|
||||
stream << (std::isprint(ascDump.m_ptr[i]) ? ascDump.m_ptr[i] : '.');
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline AscDump ascdump(const void* ptr, size_t size) { return AscDump(ptr, size); }
|
||||
|
||||
template<class Container>
|
||||
inline AscDump ascdump(const Container& container) { return AscDump(container.data(), container.size() * sizeof(*container.data())); }
|
||||
|
||||
template<class T, size_t N>
|
||||
inline AscDump ascdump(const T (&arr)[N]) { return AscDump(arr, N * sizeof(*arr)); }
|
||||
}
|
79
include/plog/Helpers/HexDump.h
Normal file
79
include/plog/Helpers/HexDump.h
Normal file
|
@ -0,0 +1,79 @@
|
|||
#pragma once
|
||||
#include <plog/Util.h>
|
||||
#include <iomanip>
|
||||
|
||||
namespace plog
|
||||
{
|
||||
class HexDump
|
||||
{
|
||||
public:
|
||||
HexDump(const void* ptr, size_t size)
|
||||
: m_ptr(static_cast<const unsigned char*>(ptr))
|
||||
, m_size(size)
|
||||
, m_group(8)
|
||||
, m_digitSeparator(" ")
|
||||
, m_groupSeparator(" ")
|
||||
{
|
||||
}
|
||||
|
||||
HexDump& group(size_t group)
|
||||
{
|
||||
m_group = group;
|
||||
return *this;
|
||||
}
|
||||
|
||||
HexDump& separator(const char* digitSeparator)
|
||||
{
|
||||
m_digitSeparator = digitSeparator;
|
||||
return *this;
|
||||
}
|
||||
|
||||
HexDump& separator(const char* digitSeparator, const char* groupSeparator)
|
||||
{
|
||||
m_digitSeparator = digitSeparator;
|
||||
m_groupSeparator = groupSeparator;
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend util::nostringstream& operator<<(util::nostringstream& stream, const HexDump&);
|
||||
|
||||
private:
|
||||
const unsigned char* m_ptr;
|
||||
size_t m_size;
|
||||
size_t m_group;
|
||||
const char* m_digitSeparator;
|
||||
const char* m_groupSeparator;
|
||||
};
|
||||
|
||||
inline util::nostringstream& operator<<(util::nostringstream& stream, const HexDump& hexDump)
|
||||
{
|
||||
stream << std::hex << std::setfill(PLOG_NSTR('0'));
|
||||
|
||||
for (size_t i = 0; i < hexDump.m_size;)
|
||||
{
|
||||
stream << std::setw(2) << static_cast<int>(hexDump.m_ptr[i]);
|
||||
|
||||
if (++i < hexDump.m_size)
|
||||
{
|
||||
if (hexDump.m_group > 0 && i % hexDump.m_group == 0)
|
||||
{
|
||||
stream << hexDump.m_groupSeparator;
|
||||
}
|
||||
else
|
||||
{
|
||||
stream << hexDump.m_digitSeparator;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline HexDump hexdump(const void* ptr, size_t size) { return HexDump(ptr, size); }
|
||||
|
||||
template<class Container>
|
||||
inline HexDump hexdump(const Container& container) { return HexDump(container.data(), container.size() * sizeof(*container.data())); }
|
||||
|
||||
template<class T, size_t N>
|
||||
inline HexDump hexdump(const T (&arr)[N]) { return HexDump(arr, N * sizeof(*arr)); }
|
||||
}
|
24
include/plog/Helpers/PrintVar.h
Normal file
24
include/plog/Helpers/PrintVar.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#define PLOG_IMPL_PRINT_VAR_1(a1) #a1 ": " << a1
|
||||
#define PLOG_IMPL_PRINT_VAR_2(a1, a2) PLOG_IMPL_PRINT_VAR_1(a1) PLOG_IMPL_PRINT_VAR_TAIL(a2)
|
||||
#define PLOG_IMPL_PRINT_VAR_3(a1, a2, a3) PLOG_IMPL_PRINT_VAR_2(a1, a2) PLOG_IMPL_PRINT_VAR_TAIL(a3)
|
||||
#define PLOG_IMPL_PRINT_VAR_4(a1, a2, a3, a4) PLOG_IMPL_PRINT_VAR_3(a1, a2, a3) PLOG_IMPL_PRINT_VAR_TAIL(a4)
|
||||
#define PLOG_IMPL_PRINT_VAR_5(a1, a2, a3, a4, a5) PLOG_IMPL_PRINT_VAR_4(a1, a2, a3, a4) PLOG_IMPL_PRINT_VAR_TAIL(a5)
|
||||
#define PLOG_IMPL_PRINT_VAR_6(a1, a2, a3, a4, a5, a6) PLOG_IMPL_PRINT_VAR_5(a1, a2, a3, a4, a5) PLOG_IMPL_PRINT_VAR_TAIL(a6)
|
||||
#define PLOG_IMPL_PRINT_VAR_7(a1, a2, a3, a4, a5, a6, a7) PLOG_IMPL_PRINT_VAR_6(a1, a2, a3, a4, a5, a6) PLOG_IMPL_PRINT_VAR_TAIL(a7)
|
||||
#define PLOG_IMPL_PRINT_VAR_8(a1, a2, a3, a4, a5, a6, a7, a8) PLOG_IMPL_PRINT_VAR_7(a1, a2, a3, a4, a5, a6, a7) PLOG_IMPL_PRINT_VAR_TAIL(a8)
|
||||
#define PLOG_IMPL_PRINT_VAR_9(a1, a2, a3, a4, a5, a6, a7, a8, a9) PLOG_IMPL_PRINT_VAR_8(a1, a2, a3, a4, a5, a6, a7, a8) PLOG_IMPL_PRINT_VAR_TAIL(a9)
|
||||
#define PLOG_IMPL_PRINT_VAR_TAIL(a) << ", " PLOG_IMPL_PRINT_VAR_1(a)
|
||||
|
||||
#define PLOG_IMPL_PRINT_VAR_EXPAND(x) x
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC system_header // disable warning: variadic macros are a C99 feature
|
||||
#endif
|
||||
|
||||
#define PLOG_IMPL_PRINT_VAR_GET_MACRO(x1, x2, x3, x4, x5, x6, x7, x8, x9, NAME, ...) NAME
|
||||
|
||||
#define PLOG_PRINT_VAR(...) PLOG_IMPL_PRINT_VAR_EXPAND(PLOG_IMPL_PRINT_VAR_GET_MACRO(__VA_ARGS__,\
|
||||
PLOG_IMPL_PRINT_VAR_9, PLOG_IMPL_PRINT_VAR_8, PLOG_IMPL_PRINT_VAR_7, PLOG_IMPL_PRINT_VAR_6, PLOG_IMPL_PRINT_VAR_5,\
|
||||
PLOG_IMPL_PRINT_VAR_4, PLOG_IMPL_PRINT_VAR_3, PLOG_IMPL_PRINT_VAR_2, PLOG_IMPL_PRINT_VAR_1, UNUSED)(__VA_ARGS__))
|
Loading…
Add table
Add a link
Reference in a new issue