zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Timer.h
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 
49 #ifndef ZENI_TIMER_H
50 #define ZENI_TIMER_H
51 
52 #include <Zeni/Chronometer.h>
53 #include <Zeni/Singleton.h>
54 
55 #ifdef _WINDOWS
56 #include <Windows.h>
57 #else
58 #include <sys/time.h>
59 #endif
60 
61 namespace Zeni {
62 
63  class ZENI_CORE_DLL Time {
64  public:
65  typedef size_t Tick_Type;
66  typedef float Second_Type;
67 
68  Time();
69  Time(const Tick_Type &ticks);
70  inline Time & operator=(const Tick_Type &ticks);
71 
72  // Accessors
73  // Time passed since last updated
74  inline Tick_Type get_ticks_passed() const;
75  inline float get_seconds_passed() const;
76  // From a specific time
77  inline Tick_Type get_ticks_since(const Time &time) const;
78  inline float get_seconds_since(const Time &time) const;
79 
80  // Modifiers
81  inline void update();
82 
83  // Comparisons
84  inline bool operator<(const Time &rhs) const;
85 
86  private:
87  Tick_Type m_ticks;
88  };
89 
90  class ZENI_CORE_DLL Timer;
91 
92 #ifdef _WINDOWS
93  ZENI_CORE_EXT template class ZENI_CORE_DLL Singleton<Timer>;
94  ZENI_CORE_EXT template class ZENI_CORE_DLL Chronometer<Time>;
95 #endif
96 
97  class ZENI_CORE_DLL Timer : public Singleton<Timer> {
98  friend class Singleton<Timer>;
99 
100  static Timer * create();
101 
102 #ifdef _WINDOWS
103 #pragma warning( push )
104 #pragma warning( disable : 4251 )
105 #endif
106  static Uninit g_uninit;
107  static Reinit g_reinit;
108 #ifdef _WINDOWS
109 #pragma warning( pop )
110 #endif
111 
112  Timer();
113  ~Timer();
114 
115  // Undefined
116  Timer(const Timer &);
117  Timer & operator=(const Timer &);
118 
119  public:
120  // Accessors
121  inline Time::Tick_Type get_ticks();
122  inline Time::Tick_Type get_ticks_per_second();
123  inline float get_seconds();
124  inline Time get_time();
125 
126  private:
127  void update();
128 
129  Time::Tick_Type m_ticks; // Wraps at around 49 days
130  };
131 
132  ZENI_CORE_DLL Timer & get_Timer();
133 
134 }
135 
136 #endif
bool operator<(const TiXmlString &a, const TiXmlString &b)
Definition: tinystr.h:273
static long get_time(void)
Definition: test_bbox.c:16
float Second_Type
Definition: Timer.h:66
Timer & get_Timer()
Get access to the singleton.
Definition: Timer.cpp:73
A Timer Singleton.
Definition: Timer.h:97
A stoppable running timer.
Definition: Chronometer.h:40
size_t Tick_Type
Definition: Timer.h:65
A Snapshot of the Timer.
Definition: Timer.h:63