remove \r
[extl.git] / extl / win / counter / tick_counter.h
blob595c84177d00700d364fa9e3430d61655f5c76d7
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: tick_counter.h
4 * Created: 08.02.17
5 * Updated: 08.05.05
7 * Brief: tick_counter class - precision: ms
9 * [<Home>]
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
12 #ifndef EXTL_PLATFORM_WIN_TICK_COUNTER_H
13 #define EXTL_PLATFORM_WIN_TICK_COUNTER_H
15 /*!\file tick_counter.h
16 * \brief tick_counter class - precision: ms
18 #ifndef __cplusplus
19 # error tick_counter.h need be supported by c++.
20 #endif
22 /* ///////////////////////////////////////////////////////////////////////
23 * Includes
25 #include "../win.h"
27 /* ///////////////////////////////////////////////////////////////////////
28 * ::extl::platform::win namespace
30 EXTL_WIN_BEGIN_WHOLE_NAMESPACE
32 /*!\brief tick_counter class
33 * \ingroup extl_group_counter
35 class tick_counter
37 /// \name Constructors
38 /// @{
39 public :
40 tick_counter();
41 ~tick_counter();
42 /// @}
44 /// \name Types
45 /// @{
46 private:
47 typedef tick_counter class_type;
49 #ifdef EXTL_64BIT_INT_SUPPORT
50 typedef e_uint64_t interval_type;
51 #else
52 typedef e_uint32_t interval_type;
53 #endif
54 typedef DWORD size_type;
55 /// @}
57 /// \name Operations
58 /// @{
59 public:
60 inline void begin();
61 inline void end();
62 /// @}
64 /// \name Attributes
65 /// @{
66 public:
67 inline interval_type count() const;
68 inline interval_type seconds() const;
69 inline interval_type ms() const;
70 inline interval_type us() const;
71 /// @}
73 /// \name Members
74 /// @{
75 private:
76 size_type m_begin;
77 size_type m_end;
78 /// @}
81 /* ///////////////////////////////////////////////////////////////////////
82 * Class implementation
84 inline tick_counter::tick_counter()
85 :m_begin(0), m_end(0)
89 inline tick_counter::~tick_counter()
92 inline void tick_counter::begin()
94 m_begin = ::GetTickCount();
97 inline void tick_counter::end()
99 m_end = ::GetTickCount();
101 inline tick_counter::interval_type tick_counter::count() const
103 EXTL_ASSERT(m_end >= m_begin);
104 return static_cast<interval_type>(m_end - m_begin);
106 inline tick_counter::interval_type tick_counter::seconds() const
108 return count() / interval_type(1000);
110 inline tick_counter::interval_type tick_counter::ms() const
112 return count();
114 inline tick_counter::interval_type tick_counter::us() const
116 return count() * interval_type(1000);
119 /* ///////////////////////////////////////////////////////////////////////
120 * Unit-testing
122 #ifdef EXTL_COUNTER_TICK_COUNTER_TEST_ENABLE
123 # include "unit_test/tick_counter_test.h"
124 #endif
126 /* ///////////////////////////////////////////////////////////////////////
127 * ::extl::platform::win namespace
129 EXTL_WIN_END_WHOLE_NAMESPACE
131 /* //////////////////////////////////////////////////////////////////// */
132 #endif /* EXTL_PLATFORM_WIN_TICK_COUNTER_H */
133 /* //////////////////////////////////////////////////////////////////// */