diff --git a/DDrawCompat/Common/CompatPtr.h b/DDrawCompat/Common/CompatPtr.h index 3e57e24..2d68f0b 100644 --- a/DDrawCompat/Common/CompatPtr.h +++ b/DDrawCompat/Common/CompatPtr.h @@ -62,3 +62,9 @@ public: std::swap(m_intf, other.m_intf); } }; + +template +std::ostream& operator<<(std::ostream& os, const CompatPtr& ptr) +{ + return os << ptr.get(); +} diff --git a/DDrawCompat/Common/CompatRef.h b/DDrawCompat/Common/CompatRef.h index 34e96b6..cf23e77 100644 --- a/DDrawCompat/Common/CompatRef.h +++ b/DDrawCompat/Common/CompatRef.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "Common/CompatVtable.h" template @@ -28,3 +30,9 @@ public: private: Intf& m_intf; }; + +template +std::ostream& operator<<(std::ostream& os, const CompatRef& ref) +{ + return os << &ref; +} diff --git a/DDrawCompat/Common/CompatWeakPtr.h b/DDrawCompat/Common/CompatWeakPtr.h index 9c79cc0..3ab8150 100644 --- a/DDrawCompat/Common/CompatWeakPtr.h +++ b/DDrawCompat/Common/CompatWeakPtr.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "Common/CompatVtable.h" template @@ -52,3 +54,9 @@ public: protected: Intf* m_intf; }; + +template +std::ostream& operator<<(std::ostream& os, const CompatWeakPtr& ptr) +{ + return os << ptr.get(); +} diff --git a/DDrawCompat/Common/Log.cpp b/DDrawCompat/Common/Log.cpp index 7ceb886..970afa0 100644 --- a/DDrawCompat/Common/Log.cpp +++ b/DDrawCompat/Common/Log.cpp @@ -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) { if (!str) diff --git a/DDrawCompat/Common/Log.h b/DDrawCompat/Common/Log.h index b38263e..4289ac5 100644 --- a/DDrawCompat/Common/Log.h +++ b/DDrawCompat/Common/Log.h @@ -8,17 +8,21 @@ #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_RESULT(...) logFunc.setResult(__VA_ARGS__) #define LOG_ONCE(msg) \ - static bool isAlreadyLogged##__LINE__ = false; \ - if (!isAlreadyLogged##__LINE__) \ + static bool CONCAT(isAlreadyLogged, __LINE__) = false; \ + if (!CONCAT(isAlreadyLogged, __LINE__)) \ { \ 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 unsigned char* data); std::ostream& operator<<(std::ostream& os, const WCHAR* wstr); @@ -208,7 +212,7 @@ namespace Compat public: template 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 << "> "; @@ -238,23 +242,6 @@ namespace Compat } private: - void toList(Log&) - { - } - - template - void toList(Log& log, Param param) - { - log << param; - } - - template - void toList(Log& log, Param firstParam, Params... remainingParams) - { - log << firstParam << ", "; - toList(log, remainingParams...); - } - std::function m_printCall; std::function m_printResult; }; diff --git a/DDrawCompat/DDraw/RealPrimarySurface.cpp b/DDrawCompat/DDraw/RealPrimarySurface.cpp index 4a59465..4b16a83 100644 --- a/DDrawCompat/DDraw/RealPrimarySurface.cpp +++ b/DDrawCompat/DDraw/RealPrimarySurface.cpp @@ -356,7 +356,7 @@ namespace void presentToPrimaryChain(CompatWeakPtr src) { - LOG_FUNC("RealPrimarySurface::presentToPrimaryChain", src.get()); + LOG_FUNC("RealPrimarySurface::presentToPrimaryChain", src); Gdi::VirtualScreen::update();