TimeSpan.h++

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002    commonc++ - A C++ Common Class Library
00003    Copyright (C) 2005-2012  Mark A Lindner
00004 
00005    This file is part of commonc++.
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public
00018    License along with this library; if not, write to the Free
00019    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020    ---------------------------------------------------------------------------
00021 */
00022 
00023 #ifndef __ccxx_TimeSpan_hxx
00024 #define __ccxx_TimeSpan_hxx
00025 
00026 #include <commonc++/Common.h++>
00027 #include <commonc++/String.h++>
00028 
00029 namespace ccxx {
00030 
00036 class COMMONCPP_API TimeSpan
00037 {
00038   public:
00039 
00044   TimeSpan(int64_t span = INT64_CONST(0)) throw();
00045 
00049   TimeSpan(int days, int hours, int minutes, int seconds, int msec = 0)
00050     throw();
00051 
00053   TimeSpan(const TimeSpan& other) throw();
00054 
00056   ~TimeSpan() throw();
00057 
00059   void setSpan(int days, int hours, int minutes, int seconds, int msec = 0)
00060     throw();
00061 
00063   void setSpan(int64_t seconds) throw();
00064 
00066   inline int64_t getSpan() const throw()
00067   { return(_span); }
00068 
00070   void setDays(int days) throw();
00071 
00073   void addDays(int days) throw();
00074 
00076   void subtractDays(int days) throw();
00077 
00079   inline int getDays() const throw()
00080   { return(_days); }
00081 
00083   void setHours(int hours) throw();
00084 
00086   void addHours(int hours) throw();
00087 
00089   void subtractHours(int hours) throw();
00090 
00092   inline int getHours() const throw()
00093   { return(_hours); }
00094 
00096   void setMinutes(int minutes) throw();
00097 
00099   void addMinutes(int minutes) throw();
00100 
00102   void subtractMinutes(int minutes) throw();
00103 
00105   inline int getMinutes() const throw()
00106   { return(_minutes); }
00107 
00109   void setSeconds(int seconds) throw();
00110 
00112   void addSeconds(int seconds) throw();
00113 
00115   void subtractSeconds(int seconds) throw();
00116 
00118   inline int getSeconds() const throw()
00119   { return(_seconds); }
00120 
00122   void setMilliseconds(int msec) throw();
00123 
00125   void addMilliseconds(int msec) throw();
00126 
00128   void subtractMilliseconds(int msec) throw();
00129 
00131   inline int getMilliseconds() const throw()
00132   { return(_msec); }
00133 
00134   TimeSpan& operator=(const TimeSpan& other) throw();
00135 
00136   inline bool operator==(const TimeSpan& other) const throw()
00137   { return(_span == other._span); }
00138 
00139   inline bool operator<(const TimeSpan& other) const throw()
00140   { return(_span < other._span); }
00141 
00142   inline bool operator<=(const TimeSpan& other) const throw()
00143   { return(_span <= other._span); }
00144 
00145   inline bool operator!=(const TimeSpan& other) const throw()
00146   { return(_span != other._span); }
00147 
00148   inline bool operator>(const TimeSpan& other) const throw()
00149   { return(_span > other._span); }
00150 
00151   inline bool operator>=(const TimeSpan& other) const throw()
00152   { return(_span >= other._span); }
00153 
00154   TimeSpan& operator+=(const TimeSpan& span) throw();
00155   TimeSpan& operator+=(int seconds) throw();
00156   TimeSpan& operator-=(const TimeSpan& span) throw();
00157   TimeSpan& operator-=(int seconds) throw();
00158 
00159   TimeSpan operator-() const throw();
00160 
00162   inline int64_t toSeconds() const throw()
00163   { return(_span / msInSecond); }
00164 
00166   inline operator int64_t() const throw()
00167   { return(_span); }
00168 
00170   inline int64_t toMilliseconds() const throw()
00171   { return(_span); }
00172 
00174   String toString() const;
00175 
00177   static const int msInSecond;
00178 
00180   static const int msInMinute;
00181 
00183   static const int msInHour;
00184 
00186   static const int msInDay;
00187 
00188   private:
00189 
00190   void _computeFields(int days, int hours, int minutes, int seconds,
00191                       int msec) throw();
00192   void _computeFields(int64_t span) throw();
00193 
00194   int _days;
00195   int _hours;
00196   int _minutes;
00197   int _seconds;
00198   int _msec;
00199   int64_t _span;
00200 };
00201 
00202 }; // namespace ccxx
00203 
00204 #endif // __ccxx_TimeSpan_hxx
00205 
00206 /* end of header file */
Generated on Sat Nov 26 16:49:07 2011 for libcommonc++ by  doxygen 1.6.3