zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Timer_HQ.hxx
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef ZENI_TIMER_HQ_HXX
19 #define ZENI_TIMER_HQ_HXX
20 
21 #include <Zeni/Timer_HQ.h>
22 
23 namespace Zeni {
24 
26  m_ticks = ticks;
27  m_ticks_per_second = get_Timer_HQ().get_ticks_per_second();
28  return *this;
29  }
30 
32  return get_Timer_HQ().get_ticks() - m_ticks;
33  }
34 
35  long double Time_HQ::get_seconds_passed() const {
36  return static_cast<long double>(get_ticks_passed()) / m_ticks_per_second;
37  }
38 
40  return m_ticks - time.m_ticks;
41  }
42 
43  long double Time_HQ::get_seconds_since(const Time_HQ &time) const {
44  return static_cast<long double>(get_ticks_since(time)) / m_ticks_per_second;
45  }
46 
47  void Time_HQ::update() {
48  m_ticks = get_Timer_HQ().get_ticks();
49  }
50 
52  update();
53 #ifdef _WINDOWS
54  return m_ticks;
55 #else
56  return to_useconds(m_ticks);
57 #endif
58  }
59 
61  return m_ticks_per_second;
62  }
63 
64  long double Timer_HQ::get_seconds() {
65  return static_cast<long double>(double(get_ticks())) / m_ticks_per_second;
66  }
67 
69  update();
70 #ifdef _WINDOWS
71  return Time_HQ(m_ticks, m_ticks_per_second);
72 #else
73  return Time_HQ(to_useconds(m_ticks), m_ticks_per_second);
74 #endif
75  }
76 
77  void Timer_HQ::update() {
78 #if defined(_WINDOWS)
79  LARGE_INTEGER lpPerformanceCount;
80  QueryPerformanceCounter(&lpPerformanceCount);
81 
82  m_ticks = lpPerformanceCount.QuadPart;
83 #elif defined(_MACOSX)
84  m_ticks = orwl_gettime();
85 #else
86  clock_gettime(CLOCK_MONOTONIC, &m_ticks);
87 #endif
88  }
89 
90  bool Time_HQ::operator<(const Time_HQ &rhs) const {
91  return m_ticks < rhs.m_ticks;
92  }
93 
94 }
95 
96 #endif
bool operator<(const Time_HQ &rhs) const
Definition: Timer_HQ.hxx:90
A Snapshot of the Timer_HQ.
Definition: Timer_HQ.h:79
void update()
Update to current Time.
Definition: Timer_HQ.hxx:47
long double HQ_Tick_Type
Definition: Timer_HQ.h:69
Timer_HQ & get_Timer_HQ()
Get access to the singleton.
Definition: Timer_HQ.cpp:123
HQ_Tick_Type get_ticks()
Get the number of ticks passed since instantiation.
Definition: Timer_HQ.hxx:51
Time_HQ & operator=(const HQ_Tick_Type &ticks)
Definition: Timer_HQ.hxx:25
long double to_useconds(const timespec &ticks)
Definition: Timer_HQ.cpp:54
HQ_Tick_Type get_ticks_since(const Time_HQ &time) const
Get the number of clock ticks passed between &#39;time&#39; and this Time.
Definition: Timer_HQ.hxx:39
long double get_seconds_passed() const
Get the number of seconds passed since this Time.
Definition: Timer_HQ.hxx:35
Time_HQ get_time()
Get the current Time.
Definition: Timer_HQ.hxx:68
HQ_Tick_Type get_ticks_passed() const
Get the number of clock ticks passed since this Time.
Definition: Timer_HQ.hxx:31
HQ_Tick_Type get_ticks_per_second()
Get the number of ticks per second.
Definition: Timer_HQ.hxx:60
long double get_seconds()
Get the number of seconds passed since instantiation.
Definition: Timer_HQ.hxx:64
long double get_seconds_since(const Time_HQ &time) const
Get the number of seconds passed between &#39;time&#39; and this Time.
Definition: Timer_HQ.hxx:43