Line data Source code
1 : #ifndef E54887CD_F652_4F07_8CCB_961E814F1517_HPP 2 : #define E54887CD_F652_4F07_8CCB_961E814F1517_HPP 3 : 4 : #include "Vector2d.hpp" 5 : 6 : #include <chrono> 7 : #include <sstream> 8 : #include <string> 9 : 10 : namespace cell::stringutils 11 : { 12 : 13 : /** 14 : * @brief Creates a string with the passed time in a sensible unit 15 : */ 16 : std::string timeString(long long timeNs, int digits = -1); 17 : 18 : /** 19 : * @brief Fall-back to std::string 20 : */ 21 : template <typename T> std::string toString(const T& value) 22 : { 23 : return std::to_string(value); 24 : } 25 : 26 : template <> inline std::string toString<std::chrono::nanoseconds>(const std::chrono::nanoseconds& value) 27 : { 28 : return timeString(value.count()); 29 : } 30 : 31 2 : template <> inline std::string toString<Vector2d>(const Vector2d& value) 32 : { 33 2 : std::ostringstream oss; 34 2 : oss << value; 35 : 36 4 : return oss.str(); 37 2 : } 38 : 39 : } // namespace cell::stringutils 40 : 41 : #endif /* E54887CD_F652_4F07_8CCB_961E814F1517_HPP */