00001 // Module: Log4CPLUS 00002 // File: timehelper.h 00003 // Created: 6/2003 00004 // Author: Tad E. Smith 00005 // 00006 // 00007 // Copyright 2003-2009 Tad E. Smith 00008 // 00009 // Licensed under the Apache License, Version 2.0 (the "License"); 00010 // you may not use this file except in compliance with the License. 00011 // You may obtain a copy of the License at 00012 // 00013 // http://www.apache.org/licenses/LICENSE-2.0 00014 // 00015 // Unless required by applicable law or agreed to in writing, software 00016 // distributed under the License is distributed on an "AS IS" BASIS, 00017 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 // See the License for the specific language governing permissions and 00019 // limitations under the License. 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 //#include <time.h> 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 // Methods 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 // Operators 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 // Data 00128 time_t tv_sec; /* seconds */ 00129 long tv_usec; /* microseconds */ 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 } // namespace helpers 00162 00163 } // namespace log4cplus 00164 00165 00166 #endif // _LOG4CPLUS_HELPERS_TIME_HELPER_HEADER_ 00167