TimeInfo.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Riegel         <juergen.riegel@web.de>                  *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #ifndef BASE_TIMEINFO_H
00025 #define BASE_TIMEINFO_H
00026 
00027 // Std. configurations
00028 
00029 
00030 #include <stdio.h>
00031 #include <sys/timeb.h>
00032 #include <time.h>
00033 
00034 #ifdef __GNUC__
00035 # include <stdint.h>
00036 #endif
00037 
00038 namespace Base
00039 {
00041 class BaseExport TimeInfo
00042 {
00043 
00044 public:
00046     TimeInfo();
00048     virtual ~TimeInfo();
00049 
00051     void setCurrent(void);
00052     void setTime_t (uint64_t seconds);
00053 
00054     uint64_t getSeconds(void) const; 
00055     unsigned short  getMiliseconds(void) const; 
00056 
00057     void operator =  (const TimeInfo &time); 
00058     bool operator == (const TimeInfo &time) const;
00059     bool operator != (const TimeInfo &time) const;
00060 
00061     bool operator <  (const TimeInfo &time) const;
00062     bool operator <= (const TimeInfo &time) const;
00063     bool operator >= (const TimeInfo &time) const;
00064     bool operator >  (const TimeInfo &time) const;
00065 
00066     static const char* currentDateTimeString();
00067     static std::string diffTime(const TimeInfo &timeStart,const TimeInfo &timeEnd );
00068     static float diffTimeF(const TimeInfo &timeStart,const TimeInfo &timeEnd );
00069     bool isNull() const;
00070     static TimeInfo null();
00071 
00072 protected:
00073 #if defined (_MSC_VER)
00074     struct _timeb timebuffer;
00075 #elif defined(__GNUC__)
00076     struct timeb timebuffer;
00077 #endif
00078 };
00079 
00080 
00081  inline uint64_t TimeInfo::getSeconds(void) const
00082  {
00083      return timebuffer.time;
00084  }
00085 
00086  inline unsigned short  TimeInfo::getMiliseconds(void) const
00087  {
00088      return timebuffer.millitm;
00089  } 
00090 
00091 inline bool
00092 TimeInfo::operator != (const TimeInfo &time) const
00093 {
00094     return (timebuffer.time != time.timebuffer.time || timebuffer.millitm != time.timebuffer.millitm);
00095 }
00096 
00097 inline void
00098 TimeInfo::operator = (const TimeInfo &time) 
00099 {
00100     timebuffer = time.timebuffer;
00101 }
00102 
00103 inline bool
00104 TimeInfo::operator == (const TimeInfo &time) const
00105 {
00106     return (timebuffer.time == time.timebuffer.time && timebuffer.millitm == time.timebuffer.millitm);
00107 }
00108 
00109 inline bool
00110 TimeInfo::operator <  (const TimeInfo &time) const
00111 {
00112     if (timebuffer.time == time.timebuffer.time)
00113         return timebuffer.millitm < time.timebuffer.millitm;
00114     else
00115         return timebuffer.time < time.timebuffer.time;
00116 }
00117 
00118 inline bool
00119 TimeInfo::operator <= (const TimeInfo &time) const
00120 {
00121     if (timebuffer.time == time.timebuffer.time)
00122         return timebuffer.millitm <= time.timebuffer.millitm;
00123     else
00124         return timebuffer.time <= time.timebuffer.time;
00125 }
00126 
00127 inline bool
00128 TimeInfo::operator >= (const TimeInfo &time) const
00129 {
00130     if (timebuffer.time == time.timebuffer.time)
00131         return timebuffer.millitm >= time.timebuffer.millitm;
00132     else
00133         return timebuffer.time >= time.timebuffer.time;
00134 }
00135 
00136 inline bool
00137 TimeInfo::operator >  (const TimeInfo &time) const
00138 {
00139     if (timebuffer.time == time.timebuffer.time)
00140         return timebuffer.millitm > time.timebuffer.millitm;
00141     else
00142         return timebuffer.time > time.timebuffer.time;
00143 }
00144 
00145 } //namespace Base
00146 
00147 
00148 #endif // BASE_TIMEINFO_H
00149 

Generated on Wed Nov 23 19:00:45 2011 for FreeCAD by  doxygen 1.6.1