mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-30 19:57:10 +01:00 
			
		
		
		
	Move <ctime> include out of line
This commit is contained in:
		| @@ -216,6 +216,56 @@ std::string StringMaker<double>::convert(double value) { | |||||||
|     return fpToString(value, 10); |     return fpToString(value, 10); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // Separate std::chrono::duration specialization | ||||||
|  | #if defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) | ||||||
|  | #include <ctime> | ||||||
|  |  | ||||||
|  | std::string ratio_string<std::atto>::symbol() { | ||||||
|  |     return "a"; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | std::string ratio_string<std::femto>::symbol() { | ||||||
|  |     return "f"; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | std::string ratio_string<std::pico>::symbol() { | ||||||
|  |     return "p"; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | std::string ratio_string<std::nano>::symbol() { | ||||||
|  |     return "n"; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | std::string ratio_string<std::micro>::symbol() { | ||||||
|  |     return "u"; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | std::string ratio_string<std::milli>::symbol() { | ||||||
|  |     return "m"; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | std::string time_t_toString(time_t const& toConvert) { | ||||||
|  |  | ||||||
|  | #ifdef _MSC_VER | ||||||
|  |     std::tm timeInfo = {}; | ||||||
|  |     gmtime_s(&timeInfo, &toConvert); | ||||||
|  | #else | ||||||
|  |     std::tm* timeInfo = std::gmtime(&toConvert); | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  |     auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); | ||||||
|  |     char timeStamp[timeStampSize]; | ||||||
|  |     const char * const fmt = "%Y-%m-%dT%H:%M:%SZ"; | ||||||
|  |  | ||||||
|  | #ifdef _MSC_VER | ||||||
|  |     std::strftime(timeStamp, timeStampSize, fmt, &timeInfo); | ||||||
|  | #else | ||||||
|  |     std::strftime(timeStamp, timeStampSize, fmt, timeInfo); | ||||||
|  | #endif | ||||||
|  |     return std::string(timeStamp, timeStampSize); | ||||||
|  | } | ||||||
|  | #endif // CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER | ||||||
|  |  | ||||||
| } // end namespace Catch | } // end namespace Catch | ||||||
|  |  | ||||||
|   | |||||||
| @@ -347,10 +347,13 @@ namespace Catch { | |||||||
|  |  | ||||||
| // Separate std::chrono::duration specialization | // Separate std::chrono::duration specialization | ||||||
| #if defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) | #if defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) | ||||||
| #include <ctime> |  | ||||||
| #include <ratio> | #include <ratio> | ||||||
| #include <chrono> | #include <chrono> | ||||||
|  |  | ||||||
|  | namespace Catch { | ||||||
|  |  | ||||||
|  | std::string time_t_toString(time_t const& toConvert); | ||||||
|  |  | ||||||
| template <class Ratio> | template <class Ratio> | ||||||
| struct ratio_string { | struct ratio_string { | ||||||
|     static std::string symbol(); |     static std::string symbol(); | ||||||
| @@ -365,30 +368,30 @@ std::string ratio_string<Ratio>::symbol() { | |||||||
| } | } | ||||||
| template <> | template <> | ||||||
| struct ratio_string<std::atto> { | struct ratio_string<std::atto> { | ||||||
|     static std::string symbol() { return "a"; } |     static std::string symbol(); | ||||||
| }; | }; | ||||||
| template <> | template <> | ||||||
| struct ratio_string<std::femto> { | struct ratio_string<std::femto> { | ||||||
|     static std::string symbol() { return "f"; } |     static std::string symbol(); | ||||||
| }; | }; | ||||||
| template <> | template <> | ||||||
| struct ratio_string<std::pico> { | struct ratio_string<std::pico> { | ||||||
|     static std::string symbol() { return "p"; } |     static std::string symbol(); | ||||||
| }; | }; | ||||||
| template <> | template <> | ||||||
| struct ratio_string<std::nano> { | struct ratio_string<std::nano> { | ||||||
|     static std::string symbol() { return "n"; } |     static std::string symbol(); | ||||||
| }; | }; | ||||||
| template <> | template <> | ||||||
| struct ratio_string<std::micro> { | struct ratio_string<std::micro> { | ||||||
|     static std::string symbol() { return "u"; } |     static std::string symbol(); | ||||||
| }; | }; | ||||||
| template <> | template <> | ||||||
| struct ratio_string<std::milli> { | struct ratio_string<std::milli> { | ||||||
|     static std::string symbol() { return "m"; } |     static std::string symbol(); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| namespace Catch { |  | ||||||
|     //////////// |     //////////// | ||||||
|     // std::chrono::duration specializations |     // std::chrono::duration specializations | ||||||
|     template<typename Value, typename Ratio> |     template<typename Value, typename Ratio> | ||||||
| @@ -433,32 +436,16 @@ namespace Catch { | |||||||
|             return ::Catch::Detail::stringify(time_point.time_since_epoch()) + " since epoch"; |             return ::Catch::Detail::stringify(time_point.time_since_epoch()) + " since epoch"; | ||||||
|         } |         } | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     // std::chrono::time_point<system_clock> specialization |     // std::chrono::time_point<system_clock> specialization | ||||||
|     template<typename Duration> |     template<typename Duration> | ||||||
|     struct StringMaker<std::chrono::time_point<std::chrono::system_clock, Duration>> { |     struct StringMaker<std::chrono::time_point<std::chrono::system_clock, Duration>> { | ||||||
|         static std::string convert(std::chrono::time_point<std::chrono::system_clock, Duration> const& time_point) { |         static std::string convert(std::chrono::time_point<std::chrono::system_clock, Duration> const& time_point) { | ||||||
|             auto converted = std::chrono::system_clock::to_time_t(time_point); |             auto converted = std::chrono::system_clock::to_time_t(time_point); | ||||||
|  |             return time_t_toString(converted); | ||||||
| #ifdef _MSC_VER |  | ||||||
|             std::tm timeInfo = {}; |  | ||||||
|             gmtime_s(&timeInfo, &converted); |  | ||||||
| #else |  | ||||||
|             std::tm* timeInfo = std::gmtime(&converted); |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
|             auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); |  | ||||||
|             char timeStamp[timeStampSize]; |  | ||||||
|             const char * const fmt = "%Y-%m-%dT%H:%M:%SZ"; |  | ||||||
|  |  | ||||||
| #ifdef _MSC_VER |  | ||||||
|             std::strftime(timeStamp, timeStampSize, fmt, &timeInfo); |  | ||||||
| #else |  | ||||||
|             std::strftime(timeStamp, timeStampSize, fmt, timeInfo); |  | ||||||
| #endif |  | ||||||
|             return std::string(timeStamp); |  | ||||||
|         } |         } | ||||||
|     }; |     }; | ||||||
| } | } // namespace Catch | ||||||
| #endif // CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER | #endif // CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Martin Hořeňovský
					Martin Hořeňovský