mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Refactored logging of structs
This commit is contained in:
parent
12ad482d29
commit
b8a674ffdd
@ -7,19 +7,15 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T>
|
||||
bool isEmptyStruct(const T& t)
|
||||
{
|
||||
static T empty = {};
|
||||
empty.dwSize = t.dwSize;
|
||||
return 0 == memcmp(&t, &empty, sizeof(t));
|
||||
}
|
||||
|
||||
template <typename DevMode>
|
||||
std::ostream& streamDevMode(std::ostream& os, const DevMode& dm)
|
||||
{
|
||||
return os << "DM(" << dm.dmPelsWidth << ',' << dm.dmPelsHeight << ',' << dm.dmBitsPerPel <<
|
||||
',' << dm.dmDisplayFrequency << ',' << dm.dmDisplayFlags << ')';
|
||||
return Compat::LogStruct(os)
|
||||
<< dm.dmPelsWidth
|
||||
<< dm.dmPelsHeight
|
||||
<< dm.dmBitsPerPel
|
||||
<< dm.dmDisplayFrequency
|
||||
<< dm.dmDisplayFlags;
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,7 +57,11 @@ std::ostream& operator<<(std::ostream& os, const DEVMODEW& dm)
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const RECT& rect)
|
||||
{
|
||||
return os << "R(" << rect.left << ',' << rect.top << ',' << rect.right << ',' << rect.bottom << ')';
|
||||
return Compat::LogStruct(os)
|
||||
<< rect.left
|
||||
<< rect.top
|
||||
<< rect.right
|
||||
<< rect.bottom;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, HDC__& dc)
|
||||
@ -80,59 +80,72 @@ std::ostream& operator<<(std::ostream& os, HWND__& hwnd)
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const DDSCAPS& caps)
|
||||
{
|
||||
return os << "C(" << std::hex << caps.dwCaps << std::dec << ')';
|
||||
return Compat::LogStruct(os)
|
||||
<< Compat::hex(caps.dwCaps);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const DDSCAPS2& caps)
|
||||
{
|
||||
return os << "C(" << std::hex <<
|
||||
caps.dwCaps << ',' << caps.dwCaps2 << ',' << caps.dwCaps3 << ',' << caps.dwCaps4 << std::dec << ')';
|
||||
return Compat::LogStruct(os)
|
||||
<< Compat::hex(caps.dwCaps)
|
||||
<< Compat::hex(caps.dwCaps2)
|
||||
<< Compat::hex(caps.dwCaps3)
|
||||
<< Compat::hex(caps.dwCaps4);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const DDPIXELFORMAT& pf)
|
||||
{
|
||||
if (isEmptyStruct(pf))
|
||||
{
|
||||
return os << "PF()";
|
||||
}
|
||||
|
||||
return os << "PF(" << std::hex << pf.dwFlags << "," << pf.dwFourCC << "," <<
|
||||
std::dec << pf.dwRGBBitCount << "," <<
|
||||
std::hex << pf.dwRBitMask << "," << pf.dwGBitMask << "," << pf.dwBBitMask << "," <<
|
||||
pf.dwRGBAlphaBitMask << std::dec << ')';
|
||||
return Compat::LogStruct(os)
|
||||
<< Compat::hex(pf.dwFlags)
|
||||
<< Compat::hex(pf.dwFourCC)
|
||||
<< pf.dwRGBBitCount
|
||||
<< Compat::hex(pf.dwRBitMask)
|
||||
<< Compat::hex(pf.dwGBitMask)
|
||||
<< Compat::hex(pf.dwBBitMask)
|
||||
<< Compat::hex(pf.dwRGBAlphaBitMask);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC& sd)
|
||||
{
|
||||
DDSURFACEDESC2 sd2 = {};
|
||||
memcpy(&sd2, &sd, sizeof(sd));
|
||||
sd2.dwSize = sizeof(sd2);
|
||||
return os << sd2;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC2& sd)
|
||||
{
|
||||
if (isEmptyStruct(sd))
|
||||
{
|
||||
return os << "SD()";
|
||||
}
|
||||
|
||||
return os << "SD(" << std::hex << sd.dwFlags << std::dec << "," <<
|
||||
sd.dwHeight << "," << sd.dwWidth << "," << sd.lPitch << "," << sd.dwBackBufferCount << "," <<
|
||||
sd.dwMipMapCount << "," << sd.dwAlphaBitDepth << "," << sd.dwReserved << "," <<
|
||||
sd.lpSurface << "," << sd.ddpfPixelFormat << "," << sd.ddsCaps << "," << sd.dwTextureStage << ')';
|
||||
return Compat::LogStruct(os)
|
||||
<< Compat::hex(sd.dwFlags)
|
||||
<< sd.dwHeight
|
||||
<< sd.dwWidth
|
||||
<< sd.lPitch
|
||||
<< sd.dwBackBufferCount
|
||||
<< sd.dwMipMapCount
|
||||
<< sd.dwAlphaBitDepth
|
||||
<< sd.dwReserved
|
||||
<< sd.lpSurface
|
||||
<< sd.ddpfPixelFormat
|
||||
<< sd.ddsCaps
|
||||
<< sd.dwTextureStage;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const CWPSTRUCT& cwrp)
|
||||
{
|
||||
return os << "CWP(" << std::hex << cwrp.message << "," << std::dec << cwrp.hwnd << "," <<
|
||||
std::hex << cwrp.wParam << "," << cwrp.lParam << std::dec << ")";
|
||||
return Compat::LogStruct(os)
|
||||
<< Compat::hex(cwrp.message)
|
||||
<< cwrp.hwnd
|
||||
<< Compat::hex(cwrp.wParam)
|
||||
<< Compat::hex(cwrp.lParam);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const CWPRETSTRUCT& cwrp)
|
||||
{
|
||||
return os << "CWRP(" << std::hex << cwrp.message << "," << std::dec << cwrp.hwnd << "," <<
|
||||
std::hex << cwrp.wParam << "," << cwrp.lParam << "," << cwrp.lResult << std::dec << ")";
|
||||
return Compat::LogStruct(os)
|
||||
<< Compat::hex(cwrp.message)
|
||||
<< cwrp.hwnd
|
||||
<< Compat::hex(cwrp.wParam)
|
||||
<< Compat::hex(cwrp.lParam)
|
||||
<< Compat::hex(cwrp.lResult);
|
||||
}
|
||||
|
||||
namespace Compat
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <ddraw.h>
|
||||
#include <fstream>
|
||||
#include <ostream>
|
||||
#include <type_traits>
|
||||
|
||||
#define LOG_ONCE(msg) \
|
||||
@ -52,6 +53,15 @@ std::ostream& operator<<(std::ostream& os, T** t)
|
||||
|
||||
namespace Compat
|
||||
{
|
||||
template <typename Num>
|
||||
struct Hex
|
||||
{
|
||||
explicit Hex(Num val) : val(val) {}
|
||||
Num val;
|
||||
};
|
||||
|
||||
template <typename Num> Hex<Num> hex(Num val) { return Hex<Num>(val); }
|
||||
|
||||
class Log
|
||||
{
|
||||
public:
|
||||
@ -95,6 +105,37 @@ namespace Compat
|
||||
static std::ofstream s_logFile;
|
||||
};
|
||||
|
||||
class LogParams;
|
||||
|
||||
class LogFirstParam
|
||||
{
|
||||
public:
|
||||
LogFirstParam(std::ostream& os) : m_os(os) {}
|
||||
template <typename T> LogParams operator<<(const T& val) { m_os << val; return LogParams(m_os); }
|
||||
|
||||
protected:
|
||||
std::ostream& m_os;
|
||||
};
|
||||
|
||||
class LogParams
|
||||
{
|
||||
public:
|
||||
LogParams(std::ostream& os) : m_os(os) {}
|
||||
template <typename T> LogParams& operator<<(const T& val) { m_os << ',' << val; return *this; }
|
||||
|
||||
operator std::ostream&() { return m_os; }
|
||||
|
||||
private:
|
||||
std::ostream& m_os;
|
||||
};
|
||||
|
||||
class LogStruct : public LogFirstParam
|
||||
{
|
||||
public:
|
||||
LogStruct(std::ostream& os) : LogFirstParam(os) { m_os << '{'; }
|
||||
~LogStruct() { m_os << '}'; }
|
||||
};
|
||||
|
||||
#ifdef _DEBUG
|
||||
typedef Log LogDebug;
|
||||
|
||||
@ -122,19 +163,27 @@ namespace Compat
|
||||
}
|
||||
};
|
||||
#else
|
||||
class LogDebug
|
||||
class LogNull
|
||||
{
|
||||
public:
|
||||
template <typename T> LogDebug& operator<<(const T&) { return *this; }
|
||||
template <typename T> LogNull& operator<<(const T&) { return *this; }
|
||||
};
|
||||
|
||||
class LogEnter
|
||||
typedef LogNull LogDebug;
|
||||
|
||||
class LogEnter : public LogNull
|
||||
{
|
||||
public:
|
||||
template <typename... Params> LogEnter(const char*, Params...) {}
|
||||
template <typename Result> void operator<<(const Result&) {}
|
||||
};
|
||||
|
||||
typedef LogEnter LogLeave;
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename Num>
|
||||
std::ostream& operator<<(std::ostream& os, Compat::Hex<Num> hex)
|
||||
{
|
||||
os << "0x" << std::hex << hex.val << std::dec;
|
||||
return os;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user