diff options
Diffstat (limited to 'Primitives/interface')
| -rw-r--r-- | Primitives/interface/FormatMessage.h | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/Primitives/interface/FormatMessage.h b/Primitives/interface/FormatMessage.h index d0df1472..cde9669b 100644 --- a/Primitives/interface/FormatMessage.h +++ b/Primitives/interface/FormatMessage.h @@ -43,29 +43,35 @@ namespace Diligent FormatMsg( ss, RestArgs... ); // recursive call using pack expansion syntax } - - struct SizeFormatter + template<typename Type> + struct MemorySizeFormatter { - size_t size = 0; + Type size = 0; size_t precision = 0; - size_t ref_size = 0; + Type ref_size = 0; }; - template<typename SSType> - void FormatMsg(SSType &ss, const SizeFormatter& Arg) + template<typename Type> + MemorySizeFormatter<Type> FormatMemorySize(Type _size, size_t _precision = 0, Type _ref_size = 0) + { + return MemorySizeFormatter<Type>{_size, _precision, _ref_size}; + } + + template<typename SSType, typename Type> + void FormatMsg(SSType& ss, const MemorySizeFormatter<Type>& Arg) { auto ref_size = Arg.ref_size != 0 ? Arg.ref_size : Arg.size; if (ref_size >= (1 << 30)) { - ss << std::fixed << std::setprecision(Arg.precision) << Arg.size / double{ 1 << 30 } << " GB"; + ss << std::fixed << std::setprecision(Arg.precision) << static_cast<double>(Arg.size) / double{ 1 << 30 } << " GB"; } else if(ref_size >= (1 << 20)) { - ss << std::fixed << std::setprecision(Arg.precision) << Arg.size / double{ 1 << 20 } << " MB"; + ss << std::fixed << std::setprecision(Arg.precision) << static_cast<double>(Arg.size) / double{ 1 << 20 } << " MB"; } else if (ref_size >= (1 << 10)) { - ss << std::fixed << std::setprecision(Arg.precision) << Arg.size / double{ 1 << 10 } << " KB"; + ss << std::fixed << std::setprecision(Arg.precision) << static_cast<double>(Arg.size) / double{ 1 << 10 } << " KB"; } else { |
