34 struct BeTimeUtilities
46 BENTLEYDLL_EXPORT static double QuerySecondsCounter () {
return QueryMillisecondsCounter() / 1000.0;}
64 static double GetCurrentTimeAsUnixMillisDouble () {
return (
double)(
Int64)GetCurrentTimeAsUnixMillis();}
92 static double ConvertFiletimeToUnixMillisDouble (_FILETIME
const& f) {
return (
double)(
Int64)ConvertFiletimeToUnixMillis(f);}
102 BENTLEYDLL_EXPORT static void ConvertUnixTimeToFiletime (_FILETIME& f, time_t t);
107 static void ConvertUnixMillisToFiletime (_FILETIME& f,
double u) {
return ConvertUnixMillisToFiletime(f, (
UInt64)u);}
126 static double ConvertTmToUnixMillisDouble (tm
const& t) {
return (
double)(
Int64)ConvertTmToUnixMillis(t);}
154 struct StopWatch : NonCopyableClass
157 WString m_description;
171 void Init(
bool start) {m_start=m_stop=0; SetFrequency();
if (start)
Start();}
175 explicit StopWatch (
WCharCP description = L
"",
bool startImmediately=
false) : m_description (description) {Init(startImmediately);}
179 StopWatch (
Utf8CP description,
bool startImmediately) : m_description (description, true) {Init(startImmediately);}
180 StopWatch (
bool startImmediately) : m_description (L
"") {Init(startImmediately);}
182 WString GetDescription() {
return m_description;}
185 void Start(){m_start = Now();}
187 void Stop() {m_stop = Now();}
190 double GetCurrentSeconds() {
return (Now() - m_start) / (double)m_frequency;}
193 double GetElapsedSeconds() {
return (m_stop - m_start) / (double)m_frequency;}
201 struct BeDuration : std::chrono::steady_clock::duration
204 typedef std::chrono::nanoseconds Nanoseconds;
205 typedef std::chrono::milliseconds Milliseconds;
206 typedef std::chrono::seconds Seconds;
208 constexpr BeDuration() : T_Super(0) {}
209 constexpr BeDuration(Seconds val) : T_Super(val) {}
210 constexpr BeDuration(Milliseconds val) : T_Super(val) {}
211 constexpr BeDuration(Nanoseconds val) : T_Super(val) {}
212 constexpr BeDuration(std::chrono::duration<double,BeDuration::period> val) : T_Super(std::chrono::duration_cast<T_Super>(val)) {}
213 BeDuration(
int) =
delete;
214 BeDuration(
double) =
delete;
217 constexpr
static BeDuration FromSeconds(
double val) {
return BeDuration(std::chrono::duration_cast<T_Super>(std::chrono::duration<double>(val)));}
220 constexpr
static BeDuration FromMilliseconds(
int64_t val) {
return BeDuration(Milliseconds(val));}
223 constexpr
operator double()
const {
return std::chrono::duration_cast<std::chrono::duration<double>>(*this).count();}
226 constexpr
double ToSeconds()
const {
return (
double) *
this;}
228 constexpr
operator Milliseconds()
const {
return std::chrono::duration_cast<Milliseconds>(*this);}
229 constexpr
operator Seconds()
const {
return std::chrono::duration_cast<Seconds>(*this);}
232 bool IsZero()
const {
return 0 ==
count();}
235 bool IsTowardsFuture()
const {
return 0 <
count();}
238 bool IsTowardsPast()
const {
return 0 >
count();}
249 struct BeTimePoint : std::chrono::steady_clock::time_point
252 using T_Super::time_point;
255 static BeTimePoint Now() {
return std::chrono::steady_clock::now();}
259 static BeTimePoint FromNow(BeDuration val) {
return Now()+val;}
263 static BeTimePoint BeforeNow(BeDuration val) {
return Now()-val;}
265 BeTimePoint::rep GetTicks()
const {
return time_since_epoch().count();}
268 bool IsValid()
const {
return 0 != GetTicks();}
272 bool IsInFuture()
const {
return IsValid() && (Now() < *
this);}
276 bool IsInPast()
const {
return IsValid() && (Now() > *
this);}
#define BENTLEYDLL_EXPORT
Definition: Bentley.h:249
long long int64_t
Definition: Bentley.r.h:94
size_type count(const key_type &__x) const
Definition: stdcxx/bstdmap.h:277
wchar_t const * WCharCP
Definition: Bentley.h:224
struct Bentley::WString * WStringP
Definition: Bentley.h:239
uint32_t UInt32
Definition: Bentley.r.h:128
#define BEGIN_BENTLEY_NAMESPACE
Definition: Bentley.r.h:24
BentleyStatus
Definition: Bentley.h:208
Defines typedefs and constants that can be used across other namespaces. All Bentley-authored C++ sou...
#define DEFINE_T_SUPER(B)
Definition: Bentley.h:167
uint64_t UInt64
Definition: Bentley.r.h:131
Utf8Char const * Utf8CP
Definition: Bentley.h:229
#define END_BENTLEY_NAMESPACE
Definition: Bentley.r.h:25
int64_t Int64
Definition: Bentley.r.h:130