tracy/server/TracyPrint.hpp

40 lines
997 B
C++
Raw Normal View History

2019-06-18 18:43:28 +00:00
#ifndef __TRACYPRINT_HPP__
#define __TRACYPRINT_HPP__
2020-01-31 00:30:33 +00:00
#if ( defined _MSC_VER && _MSVC_LANG >= 201703L ) || __cplusplus >= 201703L
# include <charconv>
#else
# include <stdio.h>
#endif
2020-01-31 00:19:08 +00:00
2019-06-18 18:43:28 +00:00
namespace tracy
{
2020-01-31 00:19:08 +00:00
template<typename T>
static inline char* PrintFloat( char* begin, char* end, T value, int precision )
{
2020-01-31 00:30:33 +00:00
#if ( defined _MSC_VER && _MSVC_LANG >= 201703L ) || __cplusplus >= 201703L
return std::to_chars( begin, end, value, std::chars_format::fixed, precision ).ptr;
#else
2020-01-31 00:19:08 +00:00
return begin + sprintf( begin, "%.*f", precision, value );
2020-01-31 00:30:33 +00:00
#endif
2020-01-31 00:19:08 +00:00
}
2020-01-31 00:44:38 +00:00
template<typename T>
static inline char* PrintFloat( char* begin, char* end, T value )
{
#if ( defined _MSC_VER && _MSVC_LANG >= 201703L ) || __cplusplus >= 201703L
return std::to_chars( begin, end, value, std::chars_format::fixed ).ptr;
#else
return begin + sprintf( begin, "%f", value );
#endif
}
2019-06-18 18:43:28 +00:00
const char* TimeToString( int64_t ns );
const char* RealToString( double val );
2019-06-18 18:43:28 +00:00
const char* MemSizeToString( int64_t val );
}
#endif