NOOP, remove trailing tabs/whitespace.
[ardour.git] / libs / backends / wavesaudio / wavesapi / MiscUtils / UMicroseconds.h
1 /*
2     Copyright (C) 2014 Waves Audio Ltd.
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program 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 General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __UMicroseconds_h__
21         #define __UMicroseconds_h__
22
23 /* Copy to include
24 #include "UMicroseconds.h"
25 */
26
27
28
29 #include "BasicTypes/WUDefines.h"
30 #include "BasicTypes/WUTypes.h"
31
32 namespace wvNS {
33 // a wraper for Microseconds function from Timer.h
34 class DllExport UMicroseconds
35 {
36 public:
37
38 #ifdef PLATFORM_WINDOWS
39         typedef int64_t TimeKeeper;
40 #endif
41 #ifdef __APPLE__
42         typedef uint64_t TimeKeeper;
43 #endif
44 #ifdef __linux__
45         typedef uint64_t TimeKeeper;
46 #endif
47
48 private:
49         TimeKeeper theTime;
50
51 public:
52
53         UMicroseconds()
54         {
55                 ReadTime();
56         }
57
58         UMicroseconds(const TimeKeeper in_initVal) : theTime(in_initVal) {}
59
60         UMicroseconds(const UMicroseconds& inUM) : theTime(inUM.theTime) {}
61         UMicroseconds& operator=(const UMicroseconds& inUM) {theTime = inUM.theTime;  return *this;}
62         UMicroseconds& operator+=(const TimeKeeper in_timeToAdd)  {theTime += in_timeToAdd;  return *this;}
63
64         UMicroseconds& ReadTime();
65
66         TimeKeeper GetNativeTime() const {return theTime;}
67         operator uint64_t () {return static_cast<uint64_t>(theTime);}
68         operator double () const {return static_cast<const double>(theTime);}
69
70         double Seconds() const {return static_cast<double>(theTime) / double(1000000);}
71         double MilliSeconds() const {return static_cast<double>(theTime) / double(1000);}
72         double MicroSeconds() const {return static_cast<double>(theTime);}
73
74 #ifdef __APPLE__
75         uint32_t hi();
76         uint32_t lo();
77 #endif
78 };
79
80 inline UMicroseconds operator-(const UMicroseconds& in_one, const UMicroseconds& in_two)
81 {
82         UMicroseconds retVal(in_one.GetNativeTime() - in_two.GetNativeTime());
83         return retVal;
84 }
85
86 class UMicrosecondsAccumulator
87 {
88 public:
89         UMicrosecondsAccumulator() : m_start_time(0), m_accumulator(0) {}
90
91         void Start();
92         void Stop();
93         void Clear();
94
95         UMicroseconds GetAccumulatedTime() const;
96
97         UMicrosecondsAccumulator& operator+=(const UMicrosecondsAccumulator&);
98
99 protected:
100         UMicroseconds m_start_time;
101         UMicroseconds m_accumulator;
102 };
103
104 inline UMicroseconds operator-(const UMicrosecondsAccumulator& in_one, const UMicrosecondsAccumulator& in_two)
105 {
106         UMicroseconds retVal(in_one.GetAccumulatedTime() - in_two.GetAccumulatedTime());
107         return retVal;
108 }
109
110 //=========================================================================================//
111 inline void MicrosecondDelay(double amt)
112 //=========================================================================================//
113 {
114         UMicroseconds than;
115         UMicroseconds now;
116
117         do
118         {
119                 now.ReadTime();
120         }       while ((now.MicroSeconds() - than.MicroSeconds()) < amt);
121 }
122
123 } // namespace wvNS {
124 #endif //#ifndef __UMicroseconds_h__