system/PeriodClock: indent with tabs

This commit is contained in:
Max Kellermann 2016-12-27 22:49:13 +01:00
parent b042095ac2
commit e786207cc2

View File

@ -28,122 +28,122 @@
*/ */
class PeriodClock { class PeriodClock {
protected: protected:
typedef unsigned Stamp; typedef unsigned Stamp;
private: private:
Stamp last; Stamp last;
public: public:
/** /**
* Initializes the object, setting the last time stamp to "0", * Initializes the object, setting the last time stamp to "0",
* i.e. a Check() will always succeed. If you do not want this * i.e. a Check() will always succeed. If you do not want this
* default behaviour, call Update() immediately after creating the * default behaviour, call Update() immediately after creating the
* object. * object.
*/ */
constexpr constexpr
PeriodClock():last(0) {} PeriodClock():last(0) {}
protected: protected:
static Stamp GetNow() { static Stamp GetNow() {
return MonotonicClockMS(); return MonotonicClockMS();
} }
constexpr int Elapsed(Stamp now) const { constexpr int Elapsed(Stamp now) const {
return last == 0 return last == 0
? -1 ? -1
: now - last; : now - last;
} }
constexpr bool Check(Stamp now, unsigned duration) const { constexpr bool Check(Stamp now, unsigned duration) const {
return now >= last + duration; return now >= last + duration;
} }
void Update(Stamp now) { void Update(Stamp now) {
last = now; last = now;
} }
public: public:
constexpr bool IsDefined() const { constexpr bool IsDefined() const {
return last != 0; return last != 0;
} }
/** /**
* Resets the clock. * Resets the clock.
*/ */
void Reset() { void Reset() {
last = 0; last = 0;
} }
/** /**
* Returns the number of milliseconds elapsed since the last * Returns the number of milliseconds elapsed since the last
* update(). Returns -1 if update() was never called. * update(). Returns -1 if update() was never called.
*/ */
int Elapsed() const { int Elapsed() const {
return Elapsed(GetNow()); return Elapsed(GetNow());
} }
/** /**
* Combines a call to Elapsed() and Update(). * Combines a call to Elapsed() and Update().
*/ */
int ElapsedUpdate() { int ElapsedUpdate() {
const auto now = GetNow(); const auto now = GetNow();
int result = Elapsed(now); int result = Elapsed(now);
Update(now); Update(now);
return result; return result;
} }
/** /**
* Checks whether the specified duration has passed since the last * Checks whether the specified duration has passed since the last
* update. * update.
* *
* @param duration the duration in milliseconds * @param duration the duration in milliseconds
*/ */
bool Check(unsigned duration) const { bool Check(unsigned duration) const {
return Check(GetNow(), duration); return Check(GetNow(), duration);
} }
/** /**
* Updates the time stamp, setting it to the current clock. * Updates the time stamp, setting it to the current clock.
*/ */
void Update() { void Update() {
Update(GetNow()); Update(GetNow());
} }
/** /**
* Updates the time stamp, setting it to the current clock plus the * Updates the time stamp, setting it to the current clock plus the
* specified offset. * specified offset.
*/ */
void UpdateWithOffset(int offset) { void UpdateWithOffset(int offset) {
Update(GetNow() + offset); Update(GetNow() + offset);
} }
/** /**
* Checks whether the specified duration has passed since the last * Checks whether the specified duration has passed since the last
* update. If yes, it updates the time stamp. * update. If yes, it updates the time stamp.
* *
* @param duration the duration in milliseconds * @param duration the duration in milliseconds
*/ */
bool CheckUpdate(unsigned duration) { bool CheckUpdate(unsigned duration) {
Stamp now = GetNow(); Stamp now = GetNow();
if (Check(now, duration)) { if (Check(now, duration)) {
Update(now); Update(now);
return true; return true;
} else } else
return false; return false;
} }
/** /**
* Checks whether the specified duration has passed since the last * Checks whether the specified duration has passed since the last
* update. After that, it updates the time stamp. * update. After that, it updates the time stamp.
* *
* @param duration the duration in milliseconds * @param duration the duration in milliseconds
*/ */
bool CheckAlwaysUpdate(unsigned duration) { bool CheckAlwaysUpdate(unsigned duration) {
Stamp now = GetNow(); Stamp now = GetNow();
bool ret = Check(now, duration); bool ret = Check(now, duration);
Update(now); Update(now);
return ret; return ret;
} }
}; };
#endif #endif