SNAP Library 2.2, Developer Reference  2014-03-11 19:15:55
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
tm.h
Go to the documentation of this file.
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() && uint(Secs) < AbsSecs); 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() && uint(Mins*60) < AbsSecs); 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() && uint(Hours*3600) < AbsSecs); 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() && uint(Days*24*3600) < AbsSecs); 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() && uint(Weeks*7*24*3600) < AbsSecs); 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+1);}
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   // get unix timestamp
00336   static uint GetDateTimeInt(const int& Year = 0, const int& Month = 0, 
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 };
00346 typedef TVec<TTm> TTmV;
00347 typedef TPair<TTm, TStr> TTmStrPr;
00348 typedef TPair<TStr, TTm> TStrTmPr;
00349 typedef TVec<TTmStrPr> TTmStrPrV;
00350 typedef TVec<TStrTmPr> TStrTmPrV;
00351 
00353 // Execution-Time
00354 class TExeTm{
00355 private:
00356   int LastTick;
00357 public:
00358   TExeTm(): LastTick(0) { Tick(); }
00359   TExeTm(const TExeTm& Tm): LastTick(Tm.LastTick) { }
00360   TExeTm& operator=(const TExeTm& Tm){
00361     LastTick=Tm.LastTick; return *this;}
00362 
00363   void Tick(){LastTick=(int)clock();}
00364   int GetTime() const {return int(clock()-LastTick);}
00365   double GetSecs() const {return double(clock()-LastTick)/double(CLOCKS_PER_SEC);}
00366   int GetSecInt() { return TFlt::Round(GetSecs()); }
00367   const char* GetStr() const {return GetTmStr();}
00368   TStr GetStr2() const {return GetTmStr();}
00369   const char* GetTmStr() const { static char TmStr[32];
00370     if (GetSecs() < 60) { sprintf(TmStr, "%.2fs", GetSecs()); }
00371     else if (GetSecs() < 3600) { sprintf(TmStr, "%02dm%02ds", int(GetSecs())/60, int(GetSecs())%60); }
00372     else { sprintf(TmStr, "%02dh%02dm", int(GetSecs())/3600, (int(GetSecs())%3600)/60); }  return TmStr; }
00373   static char* GetCurTm(){ static TStr TmStr; TmStr=TSecTm::GetCurTm().GetTmStr(); return TmStr.CStr(); }
00374 };
00375 
00377 // Time-Stop-Watch
00378 class TTmStopWatch {
00379 private:
00380     int TmSoFar;
00381     bool RunningP;
00382     TExeTm ExeTm;
00383 public:
00384     TTmStopWatch(const bool& Start = false): TmSoFar(0), RunningP(Start) { }
00385 
00386     void Start() { if (!RunningP) { RunningP = true; ExeTm.Tick(); } }
00387     void Stop() { if (RunningP) { RunningP = false; TmSoFar += ExeTm.GetTime(); } }
00388     void Reset(const bool& Start) { TmSoFar = 0; RunningP = Start; ExeTm.Tick(); }
00389 
00390     int GetTime() const { return TmSoFar + (RunningP ? ExeTm.GetTime() : 0); }
00391     double GetSec() const { return double(GetTime()) / double(CLOCKS_PER_SEC); }
00392     int GetSecInt() const { return TFlt::Round(GetSec()); }
00393     double GetMSec() const { return double(GetTime()) / double(CLOCKS_PER_SEC/1000); }
00394     int GetMSecInt() const { return TFlt::Round(GetMSec()); }
00395 };
00396 
00398 // Time-Profiler - poor-man's profiler
00399 ClassTP(TTmProfiler, PTmProfiler)//{
00400 private:
00401         TInt MxNmLen;
00402         THash<TStr, TTmStopWatch> TimerH;
00403 
00404 public:
00405         TTmProfiler() { }
00406         static PTmProfiler New() { return new TTmProfiler; }
00407 
00408         int AddTimer(const TStr& TimerNm);
00409         int GetTimerId(const TStr& TimerNm) const { return TimerH.GetKeyId(TimerNm); }
00410     TStr GetTimerNm(const int& TimerId) const { return TimerH.GetKey(TimerId); }
00411         int GetTimers() const { return TimerH.Len(); }
00412         int GetTimerIdFFirst() const { return TimerH.FFirstKeyId(); }
00413         bool GetTimerIdFNext(int& TimerId) const { return TimerH.FNextKeyId(TimerId); }
00414         // starts counting
00415         void StartTimer(const TStr& TimerNm) { TimerH.GetDat(TimerNm).Start(); }
00416         void StartTimer(const int& TimerId) { TimerH[TimerId].Start(); }
00417         // stops counting
00418         void StopTimer(const TStr& TimerNm) { TimerH.GetDat(TimerNm).Stop(); }
00419         void StopTimer(const int& TimerId) { TimerH[TimerId].Stop(); }
00420     // reset
00421     void ResetAll();
00422     void ResetTimer(const TStr& TimerNm) { TimerH.GetDat(TimerNm).Reset(false); }
00423     void ResetTimer(const int& TimerId) { TimerH[TimerId].Reset(false); }
00424         // report
00425         double GetTimerSumSec() const;
00426         double GetTimerSec(const int& TimerId) const;
00427         void PrintReport(const TStr& ProfileNm = "") const;
00428 };
00429 
00431 // Timer
00432 class TTmTimer {
00433 private:
00434     int MxMSecs; 
00435     TTmStopWatch StopWatch;
00436 
00437     UndefDefaultCopyAssign(TTmTimer);
00438 public:
00439     TTmTimer(const int& _MxMSecs): MxMSecs(_MxMSecs), StopWatch(true) { }
00440 
00441     // restarts the timer from 0
00442     void Restart() { StopWatch.Reset(true); }
00443     // returns true if the time has ran out
00444     bool IsTimeUp() const { return (StopWatch.GetMSecInt() > MxMSecs); }
00445 };