iutest  1.17.1.0
iutest_time.hpp
[詳解]
1 //======================================================================
2 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_TIME_HPP_C6B9E65B_4059_4175_A6DB_397DBF338AA8_
16 #define INCG_IRIS_IUTEST_TIME_HPP_C6B9E65B_4059_4175_A6DB_397DBF338AA8_
17 
18 //======================================================================
19 // include
20 #include "iutest_internal_defs.hpp"
21 #include <time.h>
22 
23 #if IUTEST_HAS_CXX_HDR_CHRONO
24 # include <chrono>
25 #endif
26 
27 #if IUTEST_HAS_HDR_SYSTIME
28 # include <sys/time.h>
29 #elif defined(IUTEST_OS_WINDOWS) && !defined(IUTEST_OS_WINDOWS_MOBILE)
30 # include <sys/timeb.h>
31 #endif
32 
33 //======================================================================
34 // define
36 #if !defined(IUTEST_GetMillisec) && !IUTEST_HAS_CXX_HDR_CHRONO && !IUTEST_HAS_GETTIMEOFDAY && !defined(IUTEST_OS_WINDOWS) && !IUTEST_HAS_CLOCK
37 # define IUTEST_NO_GETTIMEINMILLIS
38 #endif
39 
40 namespace iutest {
41 namespace detail
42 {
43 
44 //======================================================================
45 // declare
53 bool Localtime(time_t sec, struct tm* dst);
54 
61 ::std::string FormatTimeInMillisec(TimeInMillisec msec);
62 
69 ::std::string FormatTimeInMillisecAsSecond(TimeInMillisec msec);
70 
77 ::std::string FormatTimeInMillisecAsIso8601(TimeInMillisec msec);
78 
82 time_t GetTime();
83 
87 TimeInMillisec GetTimeInMillis();
88 
92 unsigned int GetIndefiniteValue();
93 
94 //======================================================================
95 // class
100 class iuStopWatch
101 {
102 private:
103  TimeInMillisec m_begin;
104 public:
105  iuStopWatch() : m_begin(0) {}
106 
107 public:
108  // 現在の時間をミリ秒単位で取得
109  static TimeInMillisec get_millisec()
110  {
111 #if defined(IUTEST_NOT_SUPPORT_STOPWATCH)
112  return 0;
113 #else
114  return GetTimeInMillis();
115 #endif
116  }
117 public:
118  void start()
119  {
120  m_begin = get_millisec();
121  }
122  TimeInMillisec stop() const
123  {
124  return get_millisec() - m_begin;
125  }
126 };
127 
128 } // end of namespace detail
129 } // end of namespace iutest
130 
131 #if !IUTEST_HAS_LIB
132 # include "../impl/iutest_time.ipp"
133 #endif
134 
135 #endif // INCG_IRIS_IUTEST_TIME_HPP_C6B9E65B_4059_4175_A6DB_397DBF338AA8_
iutest_internal_defs.hpp
internal definition
iutest_config.hpp
iris unit test config
iutest
iutest root namespace
Definition: iutest_charcode.hpp:31
iutest::TimeInMillisec
detail::type_least_t< 8 >::UInt TimeInMillisec
ミリ秒単位を扱う型
Definition: iutest_defs.hpp:445