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