PCMTimer.cpp
Go to the documentation of this file.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 #include "../include/PCMTimer.h"
00030 
00031 #include "../include/PCMStringConverter.h"
00032 
00033 namespace ParCompMark
00034 {
00035 
00036   
00037   
00038   
00039 
00040   const Real Timer::EPSILONDELAY = 0.000001;
00041 
00042   
00043   
00044   
00045 
00046   Real Timer::mTimeCorrection = 0.0;
00047   Real Timer::mStartTime = 0.0;
00048 
00049   
00050   
00051   
00052 
00053    std::string Timer::getTimeString(const bool & microseconds, const bool & seconds,
00054                                    const bool & minutes, const bool & hours,
00055                                    const Real & correction)
00056   {
00057         return getTimeDateString(microseconds, seconds, minutes, hours, false, false, false, correction);
00058   }
00059 
00060  
00061 
00062   std::string Timer::getDateString(const bool & days, const bool & months, const bool & years,
00063                                   const Real & correction)
00064   {
00065         return getTimeDateString(false, false, false, false, days, months, years, correction);
00066   }
00067 
00068  
00069 
00070   std::string Timer::getTimeDateString(const bool & microseconds, const bool & seconds,
00071                                          const bool & minutes, const bool & hours, const bool & days,
00072                                          const bool & months, const bool & years,
00073                                          const Real & correction)
00074   {
00075         time_t tloc;
00076         struct tm result;
00077 
00078         
00079         time(&tloc);
00080 
00081         
00082         Real tloc_ms = getSystemTime();
00083 
00084         
00085         tloc += (time_t) correction;
00086         tloc_ms += correction - floor(correction);
00087 
00088         localtime_r(&tloc, &result);
00089 
00090         return (hours ? StringConverter::toString(result.tm_hour) : "") + (minutes ? ":" +
00091                                                                          StringConverter::toString(result.
00092                                                                                                   tm_min) : "") +
00093          (seconds ? ":" + StringConverter::toString(result.tm_min) : "") + (microseconds ? "." +
00094                                                                            StringConverter::
00095 									   toString((tloc_ms -
00096                                                                                          tloc) * 1000000) : "") +
00097          (years ? " " + StringConverter::toString(result.tm_year + 1900) : "") + (months ? "-" +
00098                                                                                   StringConverter::toString(result.
00099                                                                                                            tm_mon +
00100                                                                                                            1) : "")
00101          + (days ? "-" + StringConverter::toString(result.tm_mday) : "");
00102   }
00103 
00104  
00105 
00106 }