1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00

Minor logging improvements

This commit is contained in:
narzoul 2019-07-19 19:56:21 +02:00
parent 063cefb46e
commit 545b08c55b
6 changed files with 36 additions and 22 deletions

View File

@ -62,3 +62,9 @@ public:
std::swap(m_intf, other.m_intf); std::swap(m_intf, other.m_intf);
} }
}; };
template <typename T>
std::ostream& operator<<(std::ostream& os, const CompatPtr<T>& ptr)
{
return os << ptr.get();
}

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <ostream>
#include "Common/CompatVtable.h" #include "Common/CompatVtable.h"
template <typename Intf> template <typename Intf>
@ -28,3 +30,9 @@ public:
private: private:
Intf& m_intf; Intf& m_intf;
}; };
template <typename T>
std::ostream& operator<<(std::ostream& os, const CompatRef<T>& ref)
{
return os << &ref;
}

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <ostream>
#include "Common/CompatVtable.h" #include "Common/CompatVtable.h"
template <typename Intf> template <typename Intf>
@ -52,3 +54,9 @@ public:
protected: protected:
Intf* m_intf; Intf* m_intf;
}; };
template <typename T>
std::ostream& operator<<(std::ostream& os, const CompatWeakPtr<T>& ptr)
{
return os << ptr.get();
}

View File

@ -26,6 +26,11 @@ namespace
} }
} }
std::ostream& operator<<(std::ostream& os, std::nullptr_t)
{
return os << "null";
}
std::ostream& operator<<(std::ostream& os, const char* str) std::ostream& operator<<(std::ostream& os, const char* str)
{ {
if (!str) if (!str)

View File

@ -8,17 +8,21 @@
#include "Common/ScopedCriticalSection.h" #include "Common/ScopedCriticalSection.h"
#define CONCAT_(a, b) a##b
#define CONCAT(a, b) CONCAT_(a, b)
#define LOG_FUNC(...) Compat::LogFunc logFunc(__VA_ARGS__) #define LOG_FUNC(...) Compat::LogFunc logFunc(__VA_ARGS__)
#define LOG_RESULT(...) logFunc.setResult(__VA_ARGS__) #define LOG_RESULT(...) logFunc.setResult(__VA_ARGS__)
#define LOG_ONCE(msg) \ #define LOG_ONCE(msg) \
static bool isAlreadyLogged##__LINE__ = false; \ static bool CONCAT(isAlreadyLogged, __LINE__) = false; \
if (!isAlreadyLogged##__LINE__) \ if (!CONCAT(isAlreadyLogged, __LINE__)) \
{ \ { \
Compat::Log() << msg; \ Compat::Log() << msg; \
isAlreadyLogged##__LINE__ = true; \ CONCAT(isAlreadyLogged, __LINE__) = true; \
} }
std::ostream& operator<<(std::ostream& os, std::nullptr_t);
std::ostream& operator<<(std::ostream& os, const char* str); std::ostream& operator<<(std::ostream& os, const char* str);
std::ostream& operator<<(std::ostream& os, const unsigned char* data); std::ostream& operator<<(std::ostream& os, const unsigned char* data);
std::ostream& operator<<(std::ostream& os, const WCHAR* wstr); std::ostream& operator<<(std::ostream& os, const WCHAR* wstr);
@ -208,7 +212,7 @@ namespace Compat
public: public:
template <typename... Params> template <typename... Params>
LogFunc(const char* funcName, Params... params) LogFunc(const char* funcName, Params... params)
: m_printCall([=](Log& log) { log << funcName << '('; toList(log, params...); log << ')'; }) : m_printCall([=](Log& log) { log << funcName << '('; log.toList(params...); log << ')'; })
{ {
Log log; Log log;
log << "> "; log << "> ";
@ -238,23 +242,6 @@ namespace Compat
} }
private: private:
void toList(Log&)
{
}
template <typename Param>
void toList(Log& log, Param param)
{
log << param;
}
template <typename Param, typename... Params>
void toList(Log& log, Param firstParam, Params... remainingParams)
{
log << firstParam << ", ";
toList(log, remainingParams...);
}
std::function<void(Log&)> m_printCall; std::function<void(Log&)> m_printCall;
std::function<void(Log&)> m_printResult; std::function<void(Log&)> m_printResult;
}; };

View File

@ -356,7 +356,7 @@ namespace
void presentToPrimaryChain(CompatWeakPtr<IDirectDrawSurface7> src) void presentToPrimaryChain(CompatWeakPtr<IDirectDrawSurface7> src)
{ {
LOG_FUNC("RealPrimarySurface::presentToPrimaryChain", src.get()); LOG_FUNC("RealPrimarySurface::presentToPrimaryChain", src);
Gdi::VirtualScreen::update(); Gdi::VirtualScreen::update();