00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00050 #ifndef TOPPERS_TIME_HPP_
00051 #define TOPPERS_TIME_HPP_
00052
00053 #include <toppers/raw_stub.hpp>
00054 #include <toppers/assert.hpp>
00055 #include <toppers/diagnostics.hpp>
00056
00057 #ifndef TOPPERS_DEFAULT_STUB
00058 #define TOPPERS_DEFAULT_STUB raw_stub<>
00059 #endif
00060
00061 namespace toppers
00062 {
00063
00075 template <class Diagnostics = TOPPERS_DEFAULT_DIAGNOSTICS,
00076 class Stub = TOPPERS_DEFAULT_STUB >
00077 class systemtime : Diagnostics
00078 {
00079 public:
00081 typedef ::SYSTIM time;
00082
00084 static ER set(const time& t)
00085 {
00086 ER ercd = Stub::stub_set_tim(&t);
00087 return static_handle_error(ercd);
00088 }
00089
00091 static ER get(time* p)
00092 {
00093 ER ercd = Stub::stub_get_tim(p);
00094 return static_handle_error(ercd);
00095 }
00096 };
00097
00106 template <class Diagnostics = TOPPERS_DEFAULT_DIAGNOSTICS,
00107 class Stub = TOPPERS_DEFAULT_STUB >
00108 class xsystemtime : Diagnostics
00109 {
00110 public:
00112 typedef ::SYSUTIM time;
00113
00115 static ER get(time* p)
00116 {
00117 ER ercd = Stub::stub_vxget_tim(p);
00118 return static_handle_error(ercd);
00119 }
00120 };
00121
00122 #ifdef TOPPERS_STRUCT_SYSTIM
00123
00124 inline const ::SYSTIM operator-(const ::SYSTIM& t1, const ::SYSTIM& t2)
00125 {
00126 ::SYSTIM t = t1;
00127 if (t.ltime < t2.ltime)
00128 --t.utime;
00129 t.ltime -= t2.ltime;
00130 t.utime -= t2.utime;
00131 return t;
00132 }
00133
00134 inline bool operator==(const ::SYSTIM& t1, const ::SYSTIM& t2)
00135 {
00136 return t1.utime == t2.utime && t1.ltime == t2.ltime;
00137 }
00138
00139 inline bool operator<(const ::SYSTIM& t1, const ::SYSTIM& t2)
00140 {
00141 return t1.utime < t2.utime || t1.ltime < t2.ltime;
00142 }
00143
00144 inline bool operator!=(const ::SYSTIM& t1, const ::SYSTIM& t2)
00145 {
00146 return !(t1 == t2);
00147 }
00148
00149 inline bool operator>(const ::SYSTIM& t1, const ::SYSTIM& t2)
00150 {
00151 return t2 < t1;
00152 }
00153
00154 inline bool operator<=(const ::SYSTIM& t1, const ::SYSTIM& t2)
00155 {
00156 return !(t2 < t1);
00157 }
00158
00159 inline bool operator>=(const ::SYSTIM& t1, const ::SYSTIM& t2)
00160 {
00161 return !(t1 < t2);
00162 }
00163
00164 #endif // TOPPERS_STRUCT_SYSTIM
00165
00176 template <class SystemTime>
00177 class timer
00178 {
00179 typename SystemTime::time time_;
00180 typename SystemTime::time* logbuf_;
00181
00182 public:
00184 explicit timer(typename SystemTime::time* log)
00185 : logbuf_(log)
00186 {
00187 SystemTime::get(&time_);
00188 }
00190 ~timer()
00191 {
00192 typename SystemTime::time t;
00193 if (SystemTime::get(&t) == E_OK)
00194 *logbuf_ = t - time_;
00195 }
00196 };
00197
00198 }
00199
00200 #endif // ! TOPPERS_TIME_HPP_