src/foundation/ZTime.h

00001 /*  @(#) $Id: ZTime.h,v 1.10 2006/07/23 22:00:42 agreen Exp $ */
00002 
00003 /* ------------------------------------------------------------
00004 Copyright (c) 2003 Andrew Green and Learning in Motion, Inc.
00005 http://www.zoolib.org
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020 COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023 ------------------------------------------------------------ */
00024 
00025 #ifndef __ZTime__
00026 #define __ZTime__ 1
00027 #include "zconfig.h"
00028 
00029 #include "ZDebug.h"
00030 #include "ZTypes.h"
00031 
00032 #include "ZCompat_operator_bool.h"
00033 
00034 class ZMutex;
00035 
00036 // =================================================================================================
00037 #pragma mark -
00038 #pragma mark * ZTime
00039 
00040 class ZTime
00041         {
00042     ZOOLIB_DEFINE_OPERATOR_BOOL_TYPES(ZTime, operator_bool_generator_type, operator_bool_type);
00043 public:
00044         ZTime();
00045 
00046         ZTime(double iDouble) : fVal(iDouble) {}
00047 
00048         ZTime& operator=(double iDouble) { fVal = iDouble; return *this; }
00049 
00050         operator operator_bool_type() const;
00051 
00052         bool operator<(const ZTime& iOther) const;
00053 
00054         bool operator<=(const ZTime& iOther) const { return !(iOther < *this); }
00055 
00056         bool operator>(const ZTime& iOther) const { return iOther < *this; }
00057 
00058         bool operator>=(const ZTime& iOther) const { return !(*this < iOther); }
00059 
00060         bool operator==(const ZTime& iOther) const;
00061 
00062         bool operator!=(const ZTime& iOther) const { return !(*this == iOther); }
00063 
00064         int Compare(const ZTime& iOther) const;
00065 
00066         double operator-(const ZTime& iOther) const { return fVal - iOther.fVal; }
00067 
00068         ZTime operator-(double iInterval)
00069                 {
00070                 ZTime result = *this;
00071                 result.fVal -= iInterval;
00072                 return result;
00073                 }
00074 
00075         ZTime& operator-=(double iInterval)
00076                 { fVal -= iInterval; return *this; }
00077 
00078         ZTime operator+(double iInterval) const
00079                 {
00080                 ZTime result = *this;
00081                 result.fVal += iInterval;
00082                 return result;
00083                 }
00084 
00085         ZTime& operator+=(double iInterval)
00086                 { fVal += iInterval; return *this; }
00087 
00088         static ZTime sNow();
00089         static ZTime sSystem();
00090 
00091         double fVal;
00092 
00093         static ZMutex sMutex;
00094 
00095         static const uint32 kEpochDelta_1900_To_1904
00096                 = 4U * 365 * 24 * 60 * 60; // 126,144,000
00097 
00098         static const uint32 kEpochDelta_1904_To_1970
00099                 = ((66U * 365) + 17) * 24 * 60 * 60; // 2,082,844,800
00100 
00101         static const uint32 kEpochDelta_1900_To_1970
00102                 = ((70U * 365) + 17) * 24 * 60 * 60; // 2,208,988,800
00103 
00104         static const uint64 kEpochDelta_1601_To_1970
00105                 = ((369LLU * 365) + 89) * 24 * 60 * 60; // == 11,644,473,600
00106         };
00107 
00108 namespace ZooLib {
00109 template <class T> int sCompare_T(const T& iL, const T& iR);
00110 template <> inline int sCompare_T(const ZTime& iL, const ZTime& iR)
00111         { return iL.Compare(iR); }
00112 }
00113 
00114 #endif // __ZTime__

Generated on Thu Jul 26 11:21:51 2007 for ZooLib by  doxygen 1.4.7