ScummVM API documentation
chrono.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /********************************************
23  DISCLAIMER:
24 
25  This is a wrapper code to mimic the relevant std:: class
26  Please use it ONLY when porting an existing code e.g. from the original sources
27 
28  For all new development please use classes from Common::
29  *********************************************/
30 
31 #ifndef COMMON_STD_CHRONO_H
32 #define COMMON_STD_CHRONO_H
33 
34 #include "common/system.h"
35 
36 namespace Std {
37 
38 namespace chrono {
39 
40 class duration {
41 private:
42  uint32 _value;
43 public:
44  duration() : _value(0) {
45  }
46  duration(uint32 value) : _value(value) {
47  }
48 
49  size_t count() const {
50  // durations for ScummVM are hardcoded to be in milliseconds
51  return 1000;
52  }
53 
54  operator uint32() const {
55  return _value;
56  }
57 
58  inline bool operator>=(const duration &rhs) const {
59  return _value >= rhs._value;
60  }
61 };
62 
63 class milliseconds : public duration {
64 public:
65  milliseconds() : duration(0) {}
66  milliseconds(uint32 val) : duration(val) {}
67 
68  static milliseconds zero() {
69  return milliseconds();
70  }
71 };
72 
73 class microseconds : public duration {
74 public:
75  microseconds() : duration(0) {}
76  microseconds(long val) : duration(val / 1000) {}
77 };
78 
79 
80 struct system_clock {
81 };
82 
83 
84 struct steady_clock { // wraps QueryPerformanceCounter
85  using rep = uint32;
86  using period = milliseconds;
87  using duration = milliseconds;
88  using time_point = uint32;
89  static constexpr bool is_steady = true;
90 
91  static time_point now() { // get current time
92  return g_system->getMillis();
93  }
94 };
95 
97 
98 template<class T>
99 duration duration_cast(T param);
100 
101 template<class T>
102 duration duration_cast(T param) {
103  return duration(param);
104 }
105 
106 } // namespace chrono
107 } // namespace Std
108 
109 #endif
Definition: chrono.h:40
Definition: chrono.h:80
virtual uint32 getMillis(bool skipRecord=false)=0
OSystem * g_system
Definition: chrono.h:63
Definition: chrono.h:84
Definition: chrono.h:73
Definition: algorithm.h:37