|
AndroMeta
2.0.0
|
00001 /* 00002 * Copyright 2009-2012 AndroMeta LLC. All rights reserved. 00003 * 00004 * AndroMeta LLC retains all intellectual property and proprietary 00005 * rights to this software and related documentation and any modifications 00006 * thereto. Any use, reproduction, disclosure, or distribution of this 00007 * software and related documentation without an express license agreement 00008 * from AndroMeta LLC is strictly prohibited. 00009 * 00010 */ 00011 00018 #ifndef ANDROMETA_M_TIME_H 00019 #define ANDROMETA_M_TIME_H 00020 00021 #include <AndroMeta/MStr.h> 00022 #include <AndroMeta/MObjectBase.h> 00023 00024 namespace Meta{ 00025 00036 class MTime : public MObjectBase{ 00037 public: 00038 00042 MTime(); 00043 00054 MTime(double sec, bool absolute=false); 00055 00059 MTime(uint64_t sec, uint64_t nsec); 00060 00064 MTime(const MTime& time); 00065 00069 MTime(const MVar& v, RestoreOpt opt); 00070 00074 MTime(mnode n); 00075 00079 ~MTime(); 00080 00084 void store(mvar& v) const; 00085 00089 static MTime now(); 00090 00094 static void sleep(const MTime& timeout); 00095 00100 static void dayInfo(int year, 00101 int month, 00102 int day, 00103 int& dayOfYear, 00104 int& dayOfWeek); 00105 00106 00113 static void dayOfYear(uint64_t year, 00114 int dayOfYear, 00115 int& month, 00116 int& day); 00117 00121 uint64_t sec() const; 00122 00126 uint64_t nsec() const; 00127 00131 void setSec(uint64_t sec); 00132 00136 void setNSec(uint64_t nsec); 00137 00138 MTime& operator=(const MTime& time); 00139 00143 MTime& operator+=(double sec); 00144 00145 MTime& operator+=(const MTime& time); 00146 00150 MTime operator+(double sec) const{ 00151 MTime ret(*this); 00152 return ret += sec; 00153 } 00154 00155 MTime operator+(const MTime& time) const{ 00156 MTime ret(*this); 00157 return ret += time; 00158 } 00159 00163 MTime& operator-=(double sec); 00164 00165 MTime& operator-=(const MTime& time); 00166 00170 MTime operator-(double sec) const{ 00171 MTime ret(*this); 00172 return ret -= sec; 00173 } 00174 00175 MTime operator-(const MTime& time) const{ 00176 MTime ret(*this); 00177 return ret -= time; 00178 } 00179 00180 bool operator<(const MTime& time) const; 00181 00182 bool operator>(const MTime& time) const; 00183 00184 bool operator<=(const MTime& time) const; 00185 00186 bool operator>=(const MTime& time) const; 00187 00188 bool operator==(const MTime& time) const; 00189 00190 bool operator!=(const MTime& time) const; 00191 00196 mstr toStr(const mstr& format="%Y-%m-%d %T.$nsec") const; 00197 00198 double asDouble() const; 00199 00200 inline operator double() const{ 00201 return asDouble(); 00202 } 00203 00204 friend class MTime_; 00205 00206 private: 00207 class MTime_* x_; 00208 }; 00209 00210 inline std::ostream& operator<<(std::ostream& ostr, const MTime& t){ 00211 return ostr << t.toStr(); 00212 } 00213 00214 typedef MTime mtime; 00215 00216 } // end namespace Meta 00217 00218 #endif // ANDROMETA_M_TIME_H
1.7.6.1