/* Copyright (c) 2014 IOnU Security Inc. All rights reserved Created February 2014 by Kendrick Webster Time.h - header for time utilities */ #pragma once #include #include namespace ionu { namespace time { struct CStopWatch { #define SC std::chrono CStopWatch() : m_t0(SC::steady_clock::now()) {} void Reset(void) {m_t0 = SC::steady_clock::now();} uint64_t u64_Microseconds(void) {return SC::duration_cast(SC::steady_clock::now() - m_t0).count();} unsigned int Microseconds(void) {return static_cast(u64_Microseconds());} uint64_t u64_Milliseconds(void) {return SC::duration_cast(SC::steady_clock::now() - m_t0).count();} unsigned int Milliseconds(void) {return static_cast(u64_Milliseconds());} void DecreaseMilliseconds(unsigned int n) {m_t0 += SC::milliseconds(n);} void DecreaseMicroseconds(unsigned int n) {m_t0 += SC::microseconds(n);} protected: SC::steady_clock::time_point m_t0; #undef SC }; struct CTimer { #define SC std::chrono CTimer() : m_t(SC::steady_clock::time_point::max()) {} void SetSeconds(unsigned int n) {m_t = SC::steady_clock::now() + SC::seconds(n);} void SetMilliseconds(unsigned int n) {m_t = SC::steady_clock::now() + SC::milliseconds(n);} void SetMicroseconds(unsigned int n) {m_t = SC::steady_clock::now() + SC::microseconds(n);} bool IsExpired(void) {return m_t <= SC::steady_clock::now();} void Stop(void) {m_t = SC::steady_clock::time_point::max();} protected: SC::steady_clock::time_point m_t; #undef SC }; }}