# timehelper.h

Go to the documentation of this file.

    00001 // Module:  Log4CPLUS
    00002 // File:    timehelper.h
    00003 // Created: 6/2003
    00004 // Author:  Tad E. Smith
    00005 //
    00006 //
    00007 // Copyright (C) Tad E. Smith  All rights reserved.
    00008 //
    00009 // This software is published under the terms of the Apache Software
    00010 // License version 1.1, a copy of which has been included with this
    00011 // distribution in the LICENSE.APL file.
    00012 //
    00013
    00016 #ifndef _LOG4CPLUS_HELPERS_TIME_HELPER_HEADER_
    00017 #define _LOG4CPLUS_HELPERS_TIME_HELPER_HEADER_
    00018
    00019 #include <log4cplus/config.h>
    00020 #include <log4cplus/tstring.h>
    00021
    00022 #ifdef TM_IN_SYS_TIME
    00023 #include <sys/time.h>
    00024 #endif
    00025
    00026 #include <time.h>
    00027
    00028
    00029 namespace log4cplus {
    00030     namespace helpers {
    00031
    00035         class LOG4CPLUS_EXPORT Time {
    00036         public:
    00037             Time();
    00038             Time(long tv_sec, long tv_usec);
    00039             Time(time_t time);
    00040
    00046             static Time gettimeofday();
    00047
    00048           // Methods
    00052             long sec() const { return tv_sec; }
    00053
    00057             long usec() const { return tv_usec; }
    00058
    00062             void sec(long s) { tv_sec = s; }
    00063
    00067             void usec(long us) { tv_usec = us; }
    00068
    00072             int setTime(struct tm* t);
    00073
    00077             time_t getTime() const;
    00078
    00083             void gmtime(struct tm* t) const;
    00084
    00089             void localtime(struct tm* t) const;
    00090
    00104             log4cplus::tstring getFormattedTime(const log4cplus::tstring& fmt,
    00105                                                 bool use_gmtime = false) const;
    00106
    00107           // Operators
    00108             Time& operator+=(const Time& rhs);
    00109             Time& operator-=(const Time& rhs);
    00110             Time& operator/=(long rhs);
    00111             Time& operator*=(long rhs);
    00112         bool operator==(const Time& rhs) { return tv_sec == rhs.tv_sec &&
    00113                                               tv_usec == rhs.tv_usec; }
    00114         bool operator!=(const Time& rhs) { return !(*this == rhs); }
    00115
    00116         private:
    00117           // Data
    00118             long  tv_sec;   /* seconds */
    00119             long  tv_usec;  /* microseconds */
    00120         };
    00121
    00122     }
    00123 }
    00124
    00125
    00126 LOG4CPLUS_EXPORT const log4cplus::helpers::Time operator+
    00127                                    (const log4cplus::helpers::Time& lhs,
    00128                                     const log4cplus::helpers::Time& rhs);
    00129 LOG4CPLUS_EXPORT const log4cplus::helpers::Time operator-
    00130                                    (const log4cplus::helpers::Time& lhs,
    00131                                     const log4cplus::helpers::Time& rhs);
    00132 LOG4CPLUS_EXPORT const log4cplus::helpers::Time operator/
    00133                                    (const log4cplus::helpers::Time& lhs,
    00134                                     long rhs);
    00135 LOG4CPLUS_EXPORT const log4cplus::helpers::Time operator*
    00136                                    (const log4cplus::helpers::Time& lhs,
    00137                                     long rhs);
    00138
    00139 LOG4CPLUS_EXPORT bool operator<(const log4cplus::helpers::Time& lhs,
    00140                                 const log4cplus::helpers::Time& rhs);
    00141 LOG4CPLUS_EXPORT bool operator<=(const log4cplus::helpers::Time& lhs,
    00142                                  const log4cplus::helpers::Time& rhs);
    00143
    00144 LOG4CPLUS_EXPORT bool operator>(const log4cplus::helpers::Time& lhs,
    00145                                 const log4cplus::helpers::Time& rhs);
    00146 LOG4CPLUS_EXPORT bool operator>=(const log4cplus::helpers::Time& lhs,
    00147                                  const log4cplus::helpers::Time& rhs);
    00148
    00149 LOG4CPLUS_EXPORT bool operator==(const log4cplus::helpers::Time& lhs,
    00150                                  const log4cplus::helpers::Time& rhs);
    00151 LOG4CPLUS_EXPORT bool operator!=(const log4cplus::helpers::Time& lhs,
    00152                                  const log4cplus::helpers::Time& rhs);
    00153
    00154 #endif // _LOG4CPLUS_HELPERS_TIME_HELPER_HEADER_
    00155