00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00023 #ifndef _LOG4CPLUS_HELPERS_TIME_HELPER_HEADER_
00024 #define _LOG4CPLUS_HELPERS_TIME_HELPER_HEADER_
00025
00026 #include "dcmtk/oflog/config.h"
00027 #include "dcmtk/oflog/tstring.h"
00028
00029 #ifdef TM_IN_SYS_TIME
00030 #include <sys/time.h>
00031 #endif
00032
00033
00034 #define INCLUDE_CTIME
00035 #include "dcmtk/ofstd/ofstdinc.h"
00036
00037
00038 namespace log4cplus {
00039
00040 namespace helpers {
00041
00045 class LOG4CPLUS_EXPORT Time {
00046 public:
00047 Time();
00048 Time(time_t tv_sec, long tv_usec);
00049 explicit Time(time_t time);
00050
00056 static Time gettimeofday();
00057
00058
00062 time_t sec() const { return tv_sec; }
00063
00067 long usec() const { return tv_usec; }
00068
00072 void sec(time_t s) { tv_sec = s; }
00073
00077 void usec(long us) { tv_usec = us; }
00078
00082 time_t setTime(struct tm* t);
00083
00087 time_t getTime() const;
00088
00093 void gmtime(struct tm* t) const;
00094
00099 void localtime(struct tm* t) const;
00100
00114 log4cplus::tstring getFormattedTime(const log4cplus::tstring& fmt,
00115 bool use_gmtime = false) const;
00116
00117
00118 Time& operator+=(const Time& rhs);
00119 Time& operator-=(const Time& rhs);
00120 Time& operator/=(long rhs);
00121 Time& operator*=(long rhs);
00122
00123 private:
00124 void build_q_value (log4cplus::tstring & q_str) const;
00125 void build_uc_q_value (log4cplus::tstring & uc_q_str) const;
00126
00127
00128 time_t tv_sec;
00129 long tv_usec;
00130 };
00131
00132
00133 LOG4CPLUS_EXPORT const log4cplus::helpers::Time operator+
00134 (const log4cplus::helpers::Time& lhs,
00135 const log4cplus::helpers::Time& rhs);
00136 LOG4CPLUS_EXPORT const log4cplus::helpers::Time operator-
00137 (const log4cplus::helpers::Time& lhs,
00138 const log4cplus::helpers::Time& rhs);
00139 LOG4CPLUS_EXPORT const log4cplus::helpers::Time operator/
00140 (const log4cplus::helpers::Time& lhs,
00141 long rhs);
00142 LOG4CPLUS_EXPORT const log4cplus::helpers::Time operator*
00143 (const log4cplus::helpers::Time& lhs,
00144 long rhs);
00145
00146 LOG4CPLUS_EXPORT bool operator<(const log4cplus::helpers::Time& lhs,
00147 const log4cplus::helpers::Time& rhs);
00148 LOG4CPLUS_EXPORT bool operator<=(const log4cplus::helpers::Time& lhs,
00149 const log4cplus::helpers::Time& rhs);
00150
00151 LOG4CPLUS_EXPORT bool operator>(const log4cplus::helpers::Time& lhs,
00152 const log4cplus::helpers::Time& rhs);
00153 LOG4CPLUS_EXPORT bool operator>=(const log4cplus::helpers::Time& lhs,
00154 const log4cplus::helpers::Time& rhs);
00155
00156 LOG4CPLUS_EXPORT bool operator==(const log4cplus::helpers::Time& lhs,
00157 const log4cplus::helpers::Time& rhs);
00158 LOG4CPLUS_EXPORT bool operator!=(const log4cplus::helpers::Time& lhs,
00159 const log4cplus::helpers::Time& rhs);
00160
00161 }
00162
00163 }
00164
00165
00166 #endif // _LOG4CPLUS_HELPERS_TIME_HELPER_HEADER_
00167