summaryrefslogtreecommitdiffstats
path: root/Primitives/interface
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-09-23 03:51:25 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-09-23 03:51:25 +0000
commit2f5b2dd6bb2db2464d9b9c9d95fc0a57559fa331 (patch)
tree2d5e8fecedb2d728c026a06ebb1930badd4aeccc /Primitives/interface
parentReworked vulkan dynamic heap deallocation to use main release queue (diff)
downloadDiligentCore-2f5b2dd6bb2db2464d9b9c9d95fc0a57559fa331.tar.gz
DiligentCore-2f5b2dd6bb2db2464d9b9c9d95fc0a57559fa331.zip
Reworked message formatting
Diffstat (limited to 'Primitives/interface')
-rw-r--r--Primitives/interface/Errors.h17
-rw-r--r--Primitives/interface/FormatString.h (renamed from Primitives/interface/FormatMessage.h)20
2 files changed, 20 insertions, 17 deletions
diff --git a/Primitives/interface/Errors.h b/Primitives/interface/Errors.h
index 187a55ce..d38d4cc5 100644
--- a/Primitives/interface/Errors.h
+++ b/Primitives/interface/Errors.h
@@ -28,7 +28,7 @@
#include <iostream>
#include "DebugOutput.h"
-#include "FormatMessage.h"
+#include "FormatString.h"
namespace Diligent
{
@@ -44,16 +44,14 @@ inline void ThrowIf<true>(std::string &&msg)
throw std::runtime_error( std::move(msg) );
}
-template<bool bThrowException, typename FirstArgType, typename... RestArgsType>
-void LogError( const char *Function, const char *FullFilePath, int Line, const FirstArgType& first, const RestArgsType&... RestArgs )
+template<bool bThrowException, typename... ArgsType>
+void LogError( const char *Function, const char *FullFilePath, int Line, const ArgsType&... Args )
{
std::string FileName(FullFilePath);
auto LastSlashPos = FileName.find_last_of("/\\");
if(LastSlashPos != std::string::npos)
FileName.erase(0, LastSlashPos+1);
- Diligent::MsgStream ss;
- Diligent::FormatMsg( ss, first, RestArgs... );
- auto Msg = ss.str();
+ auto Msg = Diligent::FormatString(Args...);
if(DebugMessageCallback != nullptr)
{
DebugMessageCallback( bThrowException ? DebugMessageSeverity::FatalError : DebugMessageSeverity::Error, Msg.c_str(), Function, FileName.c_str(), Line);
@@ -94,10 +92,9 @@ do{ \
#define LOG_DEBUG_MESSAGE(Severity, ...)\
-do{ \
- Diligent::MsgStream _msg_ss; \
- Diligent::FormatMsg( _msg_ss, ##__VA_ARGS__ );\
- if(Diligent::DebugMessageCallback != nullptr) Diligent::DebugMessageCallback( Severity, _msg_ss.str().c_str(), nullptr, nullptr, 0 );\
+do{ \
+ auto _msg = Diligent::FormatString(##__VA_ARGS__ );\
+ if(Diligent::DebugMessageCallback != nullptr) Diligent::DebugMessageCallback( Severity, _msg.c_str(), nullptr, nullptr, 0 );\
}while(false)
#define LOG_ERROR_MESSAGE(...) LOG_DEBUG_MESSAGE(Diligent::DebugMessageSeverity::Error, ##__VA_ARGS__)
diff --git a/Primitives/interface/FormatMessage.h b/Primitives/interface/FormatString.h
index bd4c20c7..08d1ca85 100644
--- a/Primitives/interface/FormatMessage.h
+++ b/Primitives/interface/FormatString.h
@@ -28,19 +28,25 @@
namespace Diligent
{
- typedef std::stringstream MsgStream;
-
template<typename SSType, typename ArgType>
- void FormatMsg( SSType &ss, const ArgType& Arg )
+ void FormatStrSS(SSType &ss, const ArgType& Arg)
{
ss << Arg;
}
template<typename SSType, typename FirstArgType, typename... RestArgsType>
- void FormatMsg( SSType &ss, const FirstArgType& FirstArg, const RestArgsType&... RestArgs )
+ void FormatStrSS(SSType &ss, const FirstArgType& FirstArg, const RestArgsType&... RestArgs)
+ {
+ FormatStrSS( ss, FirstArg );
+ FormatStrSS( ss, RestArgs... ); // recursive call using pack expansion syntax
+ }
+
+ template<typename... RestArgsType>
+ std::string FormatString(const RestArgsType&... Args)
{
- FormatMsg( ss, FirstArg );
- FormatMsg( ss, RestArgs... ); // recursive call using pack expansion syntax
+ std::stringstream ss;
+ FormatStrSS(ss, Args...);
+ return ss.str();
}
template<typename Type>
@@ -58,7 +64,7 @@ namespace Diligent
}
template<typename SSType, typename Type>
- void FormatMsg(SSType& ss, const MemorySizeFormatter<Type>& Arg)
+ void FormatStrSS(SSType& ss, const MemorySizeFormatter<Type>& Arg)
{
auto ref_size = Arg.ref_size != 0 ? Arg.ref_size : Arg.size;
if (ref_size >= (1 << 30))