iFun Engine API  1.0.0-b6053
Great Technology for Great Games
wall_clock.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2020 iFunFactory Inc. All Rights Reserved.
2 //
3 // This work is confidential and proprietary to iFunFactory Inc. and
4 // must not be used, disclosed, copied, or distributed without the prior
5 // consent of iFunFactory Inc.
6 
9 #ifndef INCLUDE_FUNAPI_TIME_WALL_CLOCK_H_
10 #define INCLUDE_FUNAPI_TIME_WALL_CLOCK_H_
11 
12 #include <boost/date_time/gregorian/greg_date.hpp>
13 #include <boost/date_time/posix_time/posix_time.hpp>
16 #include <funapi/types.h>
17 
18 
19 namespace fun {
20 
27 class FUNAPI_DLL_VISIBILITY WallClock : public Component {
28  public:
29  typedef boost::posix_time::ptime Value;
30  typedef boost::posix_time::time_duration Duration;
31 
33  static const Value kEpochClock;
34 
36  static const Duration kEmptyDuration;
37 
38  static bool Install(const ArgumentMap &arguments);
39  static bool Uninstall();
40 
42  static Duration FromSec(int64_t sec) {
43  return boost::posix_time::seconds(sec);
44  }
45 
47  static Duration FromMsec(int64_t msec) {
48  return boost::posix_time::milliseconds(msec);
49  }
50 
52  static Duration FromUsec(int64_t usec) {
53  return boost::posix_time::microseconds(usec);
54  }
55 
57  static WallClock::Value FromMonotonicClock(
58  const MonotonicClock::Value &mono_clock);
59 
61  static MonotonicClock::Value ToMonotonicClock(
62  const WallClock::Value &wall_clock);
63 
64  // @return Current WallClock::Value.
65  static WallClock::Value Now();
66 
67  // @return Current timestamp in second.
68  static int64_t GetTimestampInSec();
69 
70  // @return Timestamp in second.
71  static int64_t GetTimestampInSec(const WallClock::Value &value);
72 
73  // @return WallClock::Value from the timestamp in second.
74  static WallClock::Value FromTimestampInSec(int64_t timestamp_in_second);
75 
76  // @return Current timestamp in millisecond.
77  static int64_t GetTimestampInMsec();
78 
79  // @return Timestamp in millisecond.
80  static int64_t GetTimestampInMsec(const WallClock::Value &value);
81 
82  // @return WallClock::Value from the timestamp in msec.
83  static WallClock::Value FromTimestampInMsec(int64_t timestamp_in_msec);
84 
85  // @return Current timestamp in microsecond.
86  static int64_t GetTimestampInUsec();
87 
88  // @return Timestamp in microsecond.
89  static int64_t GetTimestampInUsec(const WallClock::Value &value);
90 
91  // @return WallClock::Value from the timestamp in usec.
92  static WallClock::Value FromTimestampInUsec(int64_t timestamp_in_usec);
93 
94  // @return Current iso-extended timestring.
95  static string GetTimestring();
96 
97  // @return iso-extended timestring of the value.
98  static string GetTimestring(const WallClock::Value &value);
99 
100  static string GetLocalTimestring();
101 
102  static string GetLocalTimestring(const WallClock::Value &value);
103 
104  // @return True if succeed. false otherwise.
105  static bool FromTimestring(const string &timestring, WallClock::Value *value);
106 
107  // @return Process start time.
108  static WallClock::Value GetProcessStartTime();
109 
110  // @return Process uptime.
111  static WallClock::Duration GetProcessUptime();
112 };
113 
114 } // namespace fun
115 
116 #endif // INCLUDE_FUNAPI_TIME_WALL_CLOCK_H_
Clock roughly representing wall clock.
Definition: wall_clock.h:27
ArgumentMap class manages application-specific run-time arguments.
Definition: argument_map.h:23
static Duration FromSec(int64_t sec)
Converts sec value into Duration.
Definition: wall_clock.h:42
static Duration FromUsec(int64_t usec)
Converts usec value into Duration.
Definition: wall_clock.h:52
Base class for any service in Funapi.
Definition: component.h:20
static Duration FromMsec(int64_t msec)
Converts msec value into Duration.
Definition: wall_clock.h:47
static const Duration kEmptyDuration
the value of 00:00:00.000000
Definition: wall_clock.h:36
Definition: json.h:18
static const Value kEpochClock
The value of time_t(0), 1970-01-01 00:00:00.000000 UTC.
Definition: wall_clock.h:33
int64_t Value
clock value in usec.
Definition: monotonic_clock.h:28