SNAP Library , Developer Reference
2013-01-07 14:03:36
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
00001 #include "bd.h" 00002 00004 // Forward 00005 class TILx; 00006 class TOLx; 00007 class TTm; 00008 00010 // Time-Units (round time to one of the buckets) 00011 typedef enum { 00012 tmuUndef, tmu1Sec, tmu1Min, tmu10Min, tmu15Min, tmu30Min, 00013 tmu1Hour, tmu2Hour, tmu4Hour, tmu6Hour, tmu12Hour, tmuDay, tmuWeek, // Sunday is the start of the week 00014 tmuMonth, tmuYear, tmuNodes, tmuEdges 00015 // wrap around time 00016 // tmuWrapHour, tmuWrapDay, tmuWrapWeek, tmuWrapMonth, tmuWrapYear 00017 } TTmUnit; 00018 00020 // Time-Info 00021 class TTmInfo{ 00022 private: 00023 static bool InitP; 00024 static TStrV UsMonthNmV; 00025 static TStrV SiMonthNmV; 00026 static TStrV UsDayOfWeekNmV; 00027 static TStrV SiDayOfWeekNmV; 00028 static void InitMonthNmV(); 00029 static void InitDayOfWeekNmV(); 00030 static void EnsureInit(){ 00031 if (!InitP){InitMonthNmV(); InitDayOfWeekNmV(); InitP=true;}} 00032 public: 00033 static int GetMonthN(const TStr& MonthNm, const TLoc& Loc=lUs); 00034 static bool IsMonthNm(const TStr& MonthNm, const TLoc& Loc=lUs){ 00035 return GetMonthN(MonthNm, Loc)!=-1;} 00036 static TStr GetMonthNm(const int& MonthN, const TLoc& Loc=lUs); 00037 static int GetDayOfWeekN(const TStr& DayOfWeekNm, const TLoc& Loc=lUs); 00038 static bool IsDayOfWeekNm(const TStr& DayOfWeekNm, const TLoc& Loc=lUs){ 00039 return GetDayOfWeekN(DayOfWeekNm, Loc)!=-1;} 00040 static TStr GetDayOfWeekNm(const int& DayOfWeekN, const TLoc& Loc=lUs); 00041 static TStr GetHmFromMins(const int& Mins); 00042 static int GetTmUnitSecs(const TTmUnit& TmUnit); 00043 static TStr GetTmUnitStr(const TTmUnit& TmUnit); 00044 static TStr GetTmZoneDiffStr(const TStr& TmZoneStr); 00045 00046 // day-of-week numbers 00047 static const int SunN; static const int MonN; 00048 static const int TueN; static const int WedN; 00049 static const int ThuN; static const int FriN; 00050 static const int SatN; 00051 00052 // month numbers 00053 static const int JanN; static const int FebN; 00054 static const int MarN; static const int AprN; 00055 static const int MayN; static const int JunN; 00056 static const int JulN; static const int AugN; 00057 static const int SepN; static const int OctN; 00058 static const int NovN; static const int DecN; 00059 00060 // time duration (msecs) 00061 static uint64 GetMinMSecs(){return 60*1000;} 00062 static uint64 GetHourMSecs(){return 60*60*1000;} 00063 static uint64 GetDayMSecs(){return 24*60*60*1000;} 00064 static uint64 GetWeekMSecs(){return 7*24*60*60*1000;} 00065 }; 00066 00068 // Julian-Dates 00069 class TJulianDate{ 00070 public: 00071 static int LastJulianDate; /* last day to use Julian calendar */ 00072 static int LastJulianDateN; /* jdn of same */ 00073 static int GetJulianDateN(int d, int m, int y); 00074 static void GetCalendarDate(int jdn, int& dd, int& mm, int& yy); 00075 }; 00076 00078 // Seconds-Time 00079 // NOTE: Time origin is relative to time zone. Regardless of computer time 00080 // zone second 0 maps to "Jan 1 1970 00:00" (so time zone information is lost) 00081 class TSecTm { 00082 private: 00083 TUInt AbsSecs; // pretend that local time zone is UTC 00084 private: 00085 // functions that interact with C time functions (time.h) 00086 static bool GetTmSec(const int& YearN, const int& MonthN, const int& DayN, 00087 const int& HourN, const int& MinN, const int& SecN, uint& AbsSec); 00088 static bool GetTmSec(struct tm& Tm, uint& AbsSec); 00089 static bool GetTmStruct(const uint& AbsSec, struct tm& Tm); 00090 static time_t MkGmTime(struct tm *t); // implementation of _mkgmtime 00091 public: 00092 TSecTm(): AbsSecs(TUInt::Mx){} 00093 explicit TSecTm(const uint& _AbsSecs): AbsSecs(_AbsSecs){} 00094 operator uint() const {return AbsSecs.Val;} 00095 TSecTm(const TSecTm& SecTm): AbsSecs(SecTm.AbsSecs){} 00096 TSecTm(const int& YearN, const int& MonthN, const int& DayN, 00097 const int& HourN=0, const int& MinN=0, const int& SecN=0); 00098 TSecTm(const TTm& Tm); 00099 explicit TSecTm(const PXmlTok& XmlTok); 00100 PXmlTok GetXmlTok() const; 00101 TSecTm(TSIn& SIn): AbsSecs(SIn){} 00102 void Load(TSIn& SIn){AbsSecs.Load(SIn);} 00103 void Save(TSOut& SOut) const {AbsSecs.Save(SOut);} 00104 00105 TSecTm& operator=(const TSecTm& SecTm){ 00106 AbsSecs=SecTm.AbsSecs; return *this;} 00107 TSecTm& operator=(const uint& _AbsSecs){ 00108 AbsSecs=_AbsSecs; return *this;} 00109 TSecTm& operator+=(const uint& Secs){ 00110 IAssert(IsDef()); AbsSecs()+=Secs; return *this;} 00111 TSecTm& operator-=(const uint& Secs){ 00112 IAssert(IsDef()); AbsSecs()-=Secs; return *this;} 00113 bool operator==(const TSecTm& SecTm) const { 00114 return AbsSecs==SecTm.AbsSecs;} 00115 bool operator<(const TSecTm& SecTm) const { 00116 IAssert(IsDef()&&SecTm.IsDef()); return AbsSecs<SecTm.AbsSecs;} 00117 int GetMemUsed() const {return AbsSecs.GetMemUsed();} 00118 00119 int GetPrimHashCd() const {return AbsSecs.GetPrimHashCd();} 00120 int GetSecHashCd() const {return AbsSecs.GetSecHashCd();} 00121 00122 // definition 00123 bool IsDef() const {return uint(AbsSecs)!=TUInt::Mx;} 00124 void Undef(){AbsSecs=TUInt::Mx;} 00125 00126 // string retrieval 00127 TStr GetStr(const TLoc& Loc=lUs) const; 00128 TStr GetStr(const TTmUnit& TmUnit) const; 00129 TStr GetDtStr(const TLoc& Loc=lUs) const; 00130 TStr GetDtMdyStr() const; 00131 TStr GetDtYmdStr() const; 00132 TStr GetYmdTmStr() const; // returns "y-m-d h:m:s" 00133 TStr GetTmStr() const; 00134 TStr GetTmMinStr() const; 00135 TStr GetDtTmSortStr() const; 00136 TStr GetDtTmSortFNmStr() const; 00137 00138 // component retrieval 00139 int GetYearN() const; 00140 int GetMonthN() const; 00141 TStr GetMonthNm(const TLoc& Loc=lUs) const; 00142 int GetDayN() const; 00143 int GetDayOfWeekN() const; 00144 TStr GetDayOfWeekNm(const TLoc& Loc=lUs) const; 00145 int GetHourN() const; 00146 int GetMinN() const; 00147 int GetSecN() const; 00148 void GetComps(int& Year, int& Month, int& Day, int& Hour, int& Min, int& Sec) const; 00149 uint GetAbsSecs() const {return AbsSecs();} 00150 TSecTm Round(const TTmUnit& TmUnit) const; 00151 uint GetInUnits(const TTmUnit& TmUnit) const; 00152 TStr GetDayPart() const; 00153 00154 // additions/substractions 00155 TSecTm& AddSecs(const int& Secs){ 00156 IAssert(IsDef()); AbsSecs.Val+=uint(Secs); return *this;} 00157 TSecTm& SubSecs(const int& Secs){ 00158 IAssert(IsDef()); AbsSecs.Val-=uint(Secs); return *this;} 00159 TSecTm& AddMins(const int& Mins){ 00160 IAssert(IsDef()); AbsSecs.Val+=uint(Mins*60); return *this;} 00161 TSecTm& SubMins(const int& Mins){ 00162 IAssert(IsDef()); AbsSecs.Val-=uint(Mins*60); return *this;} 00163 TSecTm& AddHours(const int& Hours){ 00164 IAssert(IsDef()); AbsSecs.Val+=uint(Hours*3600); return *this;} 00165 TSecTm& SubHours(const int& Hours){ 00166 IAssert(IsDef()); AbsSecs.Val-=uint(Hours*3600); return *this;} 00167 TSecTm& AddDays(const int& Days){ 00168 IAssert(IsDef()); AbsSecs.Val+=uint(Days*24*3600); return *this;} 00169 TSecTm& SubDays(const int& Days){ 00170 IAssert(IsDef()); AbsSecs.Val-=uint(Days*24*3600); return *this;} 00171 TSecTm& AddWeeks(const int& Weeks){ 00172 IAssert(IsDef()); AbsSecs.Val+=uint(Weeks*7*24*3600); return *this;} 00173 TSecTm& SubWeeks(const int& Weeks){ 00174 IAssert(IsDef()); AbsSecs.Val-=uint(Weeks*7*24*3600); return *this;} 00175 static uint GetDSecs(const TSecTm& SecTm1, const TSecTm& SecTm2); 00176 /*friend TSecTm operator+(const TSecTm& SecTm, const uint& Secs){ 00177 return TSecTm(SecTm)+=Secs;} 00178 friend TSecTm operator-(const TSecTm& SecTm, const uint& Secs){ 00179 return TSecTm(SecTm)-=Secs;} 00180 friend TSecTm operator+(const TSecTm& SecTm1, const TSecTm& SecTm2){ 00181 return TSecTm(SecTm1)+=SecTm2.AbsSecs;} 00182 friend TSecTm operator-(const TSecTm& SecTm1, const TSecTm& SecTm2){ 00183 return TSecTm(SecTm1)-=SecTm2.AbsSecs;}*/ 00184 00185 // time construction 00186 static TSecTm GetZeroTm(){return TSecTm(0).AddHours(23);} 00187 static TSecTm GetZeroWeekTm(); 00188 static TSecTm GetCurTm(); 00189 static TSecTm GetCurDtTm(){return GetDtTm(GetCurTm());} 00190 static TSecTm GetDtTmFromHmsStr(const TStr& HmsStr); 00191 static TSecTm GetDtTmFromMdyStr(const TStr& MdyStr); 00192 static TSecTm GetDtTmFromDmyStr(const TStr& DmyStr); 00193 static TSecTm GetDtTmFromMdyHmsPmStr(const TStr& MdyHmsPmStr, 00194 const char& DateSepCh='/', const char& TimeSepCh=':'); 00195 static TSecTm GetDtTmFromYmdHmsStr(const TStr& YmdHmsPmStr, 00196 const char& DateSepCh='-', const char& TimeSepCh=':'); 00197 static TSecTm GetDtTmFromStr(const TChA& YmdHmsPmStr, const int& YearId=0, const int& MonId=1, 00198 const int& DayId=2, const int& HourId=3, const int& MinId=4, const int& SecId=5); 00199 static TSecTm GetDtTm(const int& YearN, const int& MonthN, const int& DayN); 00200 static TSecTm GetDtTm(const TSecTm& Tm); 00201 00202 // text load/save 00203 static TSecTm LoadTxt(TILx& Lx); 00204 void SaveTxt(TOLx& Lx) const; 00205 }; 00206 typedef TVec<TSecTm> TSecTmV; 00207 typedef TKeyDat<TSecTm, TStr> TSecTmStrKd; 00208 typedef TVec<TSecTmStrKd> TSecTmStrKdV; 00209 00211 // Time 00212 class TTm{ 00213 private: 00214 TInt Year, Month, Day, DayOfWeek; 00215 TInt Hour, Min, Sec, MSec; 00216 public: 00217 TTm(): 00218 Year(-1), Month(-1), Day(-1), DayOfWeek(-1), 00219 Hour(-1), Min(-1), Sec(-1), MSec(-1){} 00220 TTm(const TTm& Tm): 00221 Year(Tm.Year), Month(Tm.Month), Day(Tm.Day), DayOfWeek(Tm.DayOfWeek), 00222 Hour(Tm.Hour), Min(Tm.Min), Sec(Tm.Sec), MSec(Tm.MSec){} 00223 TTm( 00224 const int& _Year, const int& _Month, const int& _Day, const int& _DayOfWeek=-1, 00225 const int& _Hour=0, const int& _Min=0, const int& _Sec=0, const int& _MSec=0): 00226 Year(_Year), Month(_Month), Day(_Day), DayOfWeek(_DayOfWeek), 00227 Hour(_Hour), Min(_Min), Sec(_Sec), MSec(_MSec){} 00228 TTm(const TSecTm& SecTm): 00229 Year(SecTm.GetYearN()), Month(SecTm.GetMonthN()), Day(SecTm.GetDayN()), 00230 DayOfWeek(SecTm.GetDayOfWeekN()), Hour(SecTm.GetHourN()), 00231 Min(SecTm.GetMinN()), Sec(SecTm.GetSecN()), MSec(0){} 00232 ~TTm(){} 00233 TTm(TSIn& SIn): 00234 Year(SIn), Month(SIn), Day(SIn), DayOfWeek(SIn), 00235 Hour(SIn), Min(SIn), Sec(SIn), MSec(SIn){} 00236 void Save(TSOut& SOut) const { 00237 Year.Save(SOut); Month.Save(SOut); Day.Save(SOut); DayOfWeek.Save(SOut); 00238 Hour.Save(SOut); Min.Save(SOut); Sec.Save(SOut); MSec.Save(SOut);} 00239 00240 TTm& operator=(const TTm& Tm){ 00241 Year=Tm.Year; Month=Tm.Month; Day=Tm.Day; DayOfWeek=Tm.DayOfWeek; 00242 Hour=Tm.Hour; Min=Tm.Min; Sec=Tm.Sec; MSec=Tm.MSec; 00243 return *this;} 00244 bool operator==(const TTm& Tm) const { 00245 return 00246 (Year==Tm.Year)&&(Month==Tm.Month)&&(Day==Tm.Day)&& 00247 (Hour==Tm.Hour)&&(Min==Tm.Min)&&(Sec==Tm.Sec)&&(MSec==Tm.MSec);} 00248 bool operator<(const TTm& Tm) const { 00249 return 00250 (Year<Tm.Year)|| 00251 ((Year==Tm.Year)&&(Month<Tm.Month))|| 00252 ((Year==Tm.Year)&&(Month==Tm.Month)&&(Day<Tm.Day))|| 00253 (((Year==Tm.Year)&&(Month==Tm.Month)&&(Day==Tm.Day))&&( 00254 (Hour<Tm.Hour)|| 00255 ((Hour==Tm.Hour)&&(Min<Tm.Min))|| 00256 ((Hour==Tm.Hour)&&(Min==Tm.Min)&&(Sec<Tm.Sec))|| 00257 ((Hour==Tm.Hour)&&(Min==Tm.Min)&&(Sec==Tm.Sec)&&(MSec<Tm.MSec))));} // saxo 00258 int GetMemUsed() const {return sizeof(TTm);} 00259 00260 int GetPrimHashCd() const {return Year*Month*Day+Hour*Min*Sec*MSec;} 00261 int GetSecHashCd() const {return Year*Month*Day;} 00262 00263 // defined 00264 bool IsDef() const { 00265 return (Year!=-1)&&(Month!=-1)&&(Day!=-1)&& 00266 (Hour!=-1)&&(Min!=-1)&&(Sec!=-1)&&(MSec!=-1);} 00267 void Undef(){ 00268 Year=-1; Month=-1; Day=-1; DayOfWeek=-1; 00269 Hour=-1; Min=-1; Sec=-1; MSec=-1;} 00270 // check if time is defined 00271 bool IsTimeDef() const { return !(Hour==0 && Min==0 && Sec==0 && MSec==0); } 00272 00273 // get components 00274 int GetYear() const {return Year;} 00275 int GetMonth() const {return Month;} 00276 TStr GetMonthNm() const {return TTmInfo::GetMonthNm(Month);} 00277 int GetDay() const {return Day;} 00278 int GetDayOfWeek() const {return DayOfWeek;} 00279 TStr GetDayOfWeekNm() const {return TTmInfo::GetDayOfWeekNm(DayOfWeek);} 00280 int GetHour() const {return Hour;} 00281 int GetMin() const {return Min;} 00282 int GetSec() const {return Sec;} 00283 int GetMSec() const {return MSec;} 00284 00285 // time string formats 00286 TStr GetStr(const bool& MSecP=true) const; 00287 TStr GetYMDDashStr() const; 00288 TStr GetHMSTColonDotStr(const bool& FullP=false, const bool& MSecP=true) const; 00289 TStr GetWebLogDateStr() const {return GetYMDDashStr();} 00290 TStr GetWebLogTimeStr() const {return GetHMSTColonDotStr(false);} 00291 TStr GetWebLogDateTimeStr(const bool& FullP=false, const TStr& DateTimeSepCh=" ", const bool& MSecP=true) const { 00292 return GetYMDDashStr()+DateTimeSepCh+GetHMSTColonDotStr(FullP, MSecP);} 00293 TStr GetIdStr() const; 00294 TSecTm GetSecTm() const { 00295 return TSecTm(Year, Month, Day, Hour, Min, Sec);} 00296 00297 // calculation 00298 void AddTime(const int& Hours, const int& Mins=0, const int& Secs=0, const int& MSecs=0); 00299 void AddDays(const int& Days){AddTime(Days*24);} 00300 void SubTime(const int& Hours, const int& Mins=0, const int& Secs=0, const int& MSecs=0); 00301 void SubDays(const int& Days){SubTime(Days*24);} 00302 00303 // static functions 00304 static TTm GetCurUniTm(); 00305 static TTm GetUniqueCurUniTm(); 00306 static TTm GetUniqueCurUniTm(const int& UniqueSpaces, const int& UniqueSpaceN); 00307 static TTm GetCurLocTm(); 00308 static uint64 GetCurUniMSecs(); 00309 static uint64 GetCurLocMSecs(); 00310 static uint64 GetMSecsFromTm(const TTm& Tm); 00311 static TTm GetTmFromMSecs(const uint64& MSecs); 00312 static uint GetMSecsFromOsStart(); 00313 static uint64 GetPerfTimerFq(); 00314 static uint64 GetPerfTimerTicks(); 00315 static void GetDiff(const TTm& Tm1, const TTm& Tm2, int& Days, 00316 int& Hours, int& Mins, int& Secs, int& MSecs); 00317 static uint64 GetDiffMSecs(const TTm& Tm1, const TTm& Tm2); 00318 static uint64 GetDiffSecs(const TTm& Tm1, const TTm& Tm2){ 00319 return GetDiffMSecs(Tm1, Tm2)/uint64(1000);} 00320 static uint64 GetDiffMins(const TTm& Tm1, const TTm& Tm2){ 00321 return GetDiffMSecs(Tm1, Tm2)/uint64(1000*60);} 00322 static uint64 GetDiffHrs(const TTm& Tm1, const TTm& Tm2){ 00323 return GetDiffMSecs(Tm1, Tm2)/uint64(1000*60*60);} 00324 static uint64 GetDiffDays(const TTm& Tm1, const TTm& Tm2){ 00325 return GetDiffMSecs(Tm1, Tm2)/uint64(1000*60*60*24);} 00326 static TTm GetLocTmFromUniTm(const TTm& Tm); 00327 static TTm GetUniTmFromLocTm(const TTm& Tm); 00328 static TTm GetTmFromWebLogTimeStr(const TStr& TimeStr, 00329 const char TimeSepCh=':', const char MSecSepCh='.'); 00330 static TTm GetTmFromWebLogDateTimeStr(const TStr& DateTimeStr, 00331 const char DateSepCh='-', const char TimeSepCh=':', 00332 const char MSecSepCh='.', const char DateTimeSepCh=' '); 00333 static TTm GetTmFromIdStr(const TStr& IdStr); 00334 00335 // unique sortable 32-bit integer from date and time (TTmDateTime) 00336 static uint GetDateTimeInt(const int& Year = 0, const int& Month = 1, 00337 const int& Day = 1, const int& Hour = 0, const int& Min = 0, 00338 const int& Sec = 0); 00339 static uint GetDateIntFromTm(const TTm& Tm); 00340 static uint GetMonthIntFromTm(const TTm& Tm); 00341 static uint GetYearIntFromTm(const TTm& Tm); 00342 static uint GetDateTimeIntFromTm(const TTm& Tm); 00343 static TTm GetTmFromDateTimeInt(const uint& DateTimeInt); 00344 static TSecTm GetSecTmFromDateTimeInt(const uint& DateTimeInt); 00345 static uint KeepMonthInDateTimeInt(const uint& DateTimeInt); 00346 static uint KeepDayInDateTimeInt(const uint& DateTimeInt); 00347 static uint KeepHourInDateTimeInt(const uint& DateTimeInt); 00348 }; 00349 typedef TVec<TTm> TTmV; 00350 typedef TPair<TTm, TStr> TTmStrPr; 00351 typedef TPair<TStr, TTm> TStrTmPr; 00352 typedef TVec<TTmStrPr> TTmStrPrV; 00353 typedef TVec<TStrTmPr> TStrTmPrV; 00354 00356 // Execution-Time 00357 class TExeTm{ 00358 private: 00359 int LastTick; 00360 public: 00361 TExeTm(): LastTick(0) { Tick(); } 00362 TExeTm(const TExeTm& Tm): LastTick(Tm.LastTick) { } 00363 TExeTm& operator=(const TExeTm& Tm){ 00364 LastTick=Tm.LastTick; return *this;} 00365 00366 void Tick(){LastTick=(int)clock();} 00367 int GetTime() const {return int(clock()-LastTick);} 00368 double GetSecs() const {return double(clock()-LastTick)/double(CLOCKS_PER_SEC);} 00369 int GetSecInt() { return TFlt::Round(GetSecs()); } 00370 const char* GetStr() const {return GetTmStr();} 00371 TStr GetStr2() const {return GetTmStr();} 00372 const char* GetTmStr() const { static char TmStr[32]; 00373 if (GetSecs() < 60) { sprintf(TmStr, "%.2fs", GetSecs()); } 00374 else if (GetSecs() < 3600) { sprintf(TmStr, "%02dm%02ds", int(GetSecs())/60, int(GetSecs())%60); } 00375 else { sprintf(TmStr, "%02dh%02dm", int(GetSecs())/3600, (int(GetSecs())%3600)/60); } return TmStr; } 00376 static char* GetCurTm(){ static TStr TmStr; TmStr=TSecTm::GetCurTm().GetTmStr(); return TmStr.CStr(); } 00377 }; 00378 00380 // Time-Stop-Watch 00381 class TTmStopWatch { 00382 private: 00383 int TmSoFar; 00384 bool RunningP; 00385 TExeTm ExeTm; 00386 public: 00387 TTmStopWatch(const bool& Start = false): TmSoFar(0), RunningP(Start) { } 00388 00389 void Start() { if (!RunningP) { RunningP = true; ExeTm.Tick(); } } 00390 void Stop() { if (RunningP) { RunningP = false; TmSoFar += ExeTm.GetTime(); } } 00391 void Reset(const bool& Start) { TmSoFar = 0; RunningP = Start; ExeTm.Tick(); } 00392 00393 int GetTime() const { return TmSoFar + (RunningP ? ExeTm.GetTime() : 0); } 00394 double GetSec() const { return double(GetTime()) / double(CLOCKS_PER_SEC); } 00395 int GetSecInt() const { return TFlt::Round(GetSec()); } 00396 double GetMSec() const { return double(GetTime()) / double(CLOCKS_PER_SEC/1000); } 00397 int GetMSecInt() const { return TFlt::Round(GetMSec()); } 00398 }; 00399 00401 // Time-Profiler - poor-man's profiler 00402 ClassTP(TTmProfiler, PTmProfiler)//{ 00403 private: 00404 TInt MxNmLen; 00405 THash<TStr, TTmStopWatch> TimerH; 00406 00407 public: 00408 TTmProfiler() { } 00409 static PTmProfiler New() { return new TTmProfiler; } 00410 00411 int AddTimer(const TStr& TimerNm); 00412 int GetTimerId(const TStr& TimerNm) const { return TimerH.GetKeyId(TimerNm); } 00413 TStr GetTimerNm(const int& TimerId) const { return TimerH.GetKey(TimerId); } 00414 int GetTimers() const { return TimerH.Len(); } 00415 int GetTimerIdFFirst() const { return TimerH.FFirstKeyId(); } 00416 bool GetTimerIdFNext(int& TimerId) const { return TimerH.FNextKeyId(TimerId); } 00417 // starts counting 00418 void StartTimer(const TStr& TimerNm) { TimerH.GetDat(TimerNm).Start(); } 00419 void StartTimer(const int& TimerId) { TimerH[TimerId].Start(); } 00420 // stops counting 00421 void StopTimer(const TStr& TimerNm) { TimerH.GetDat(TimerNm).Stop(); } 00422 void StopTimer(const int& TimerId) { TimerH[TimerId].Stop(); } 00423 // reset 00424 void ResetAll(); 00425 void ResetTimer(const TStr& TimerNm) { TimerH.GetDat(TimerNm).Reset(false); } 00426 void ResetTimer(const int& TimerId) { TimerH[TimerId].Reset(false); } 00427 // report 00428 double GetTimerSumSec() const; 00429 double GetTimerSec(const int& TimerId) const; 00430 void PrintReport(const TStr& ProfileNm = "") const; 00431 }; 00432 00434 // Timer 00435 class TTmTimer { 00436 private: 00437 int MxMSecs; 00438 TTmStopWatch StopWatch; 00439 00440 UndefDefaultCopyAssign(TTmTimer); 00441 public: 00442 TTmTimer(const int& _MxMSecs): MxMSecs(_MxMSecs), StopWatch(true) { } 00443 00444 // restarts the timer from 0 00445 void Restart() { StopWatch.Reset(true); } 00446 // returns true if the time has ran out 00447 bool IsTimeUp() const { return (StopWatch.GetMSecInt() > MxMSecs); } 00448 };