Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

PhxTimes.h

00001 /******************************************************************************
00002 *       04/01/2005 Snugglebear
00003 *       Time utility classes
00004 *       This file contains utility classes used to describe time values. These
00005 *       classes are based off POSIX time standards, notably the structs TimeVal and
00006 *       tm, found in any POSIX time.h. Both structs have been enhanced, having been
00007 *       converted from methodless structs to full fledged classes with private data
00008 *       members and various functions for manipulation. These classes form the
00009 *       basis for time description in PHX.
00010 *
00011 *       For POSIX time reference, see:
00012 *       http://www.opengroup.org/onlinepubs/009695399/basedefs/time.h.html
00013 ******************************************************************************/
00014 
00015 #ifndef PHX_TIMES_H
00016 #define PHX_TIMES_H
00017 
00018 #include <Phx/PhxConfig.h>
00019 #include <Phx/PhxTypes.h>
00020 #include <iostream>
00021 
00022 #ifdef PHX_PLATFORM_WIN32
00023 #include <windows.h>
00024 #include <MMSystem.h>
00025 #endif
00026 
00027 // suck in POSIX timers
00028 //#ifndef PHX_PLATFORM_WIN32
00029 //#include <time.h>
00030 //#endif
00031 
00032 namespace Phx {
00033 
00034 /******************************************************************************
00035 *       04/01/2005 Snugglebear
00036 *       Basic Time class
00037 *       This class forms the foundation for more useful derived Time types. Time
00038 *       consists of a single member variable, mSeconds, which represents the count
00039 *       of seconds since some arbitrary point. This variable is intentionally
00040 *       signed.
00041 ******************************************************************************/
00042 class Time
00043 {
00044         private:
00045                 int64_t mSeconds;                               // unbound count of seconds
00046 
00047         public:
00048                 // garden variety constructors
00049                 Time();
00050                 Time(const int64_t);
00051                 Time(const Time&);
00052 
00053                 // get & sets
00054                 int64_t seconds() const;
00055 
00056                 void seconds(const int64_t);
00057 
00058                 // function to print Time to the standard output
00059                 void printTime() const;
00060 
00061                 // operator overloads
00062                         // comparison ops - homogenous
00063                 virtual bool operator!=(const Time&) const;
00064                 virtual bool operator==(const Time&) const;
00065                 virtual bool operator<(const Time&) const;
00066                 virtual bool operator>(const Time&) const;
00067                 virtual bool operator<=(const Time&) const;
00068                 virtual bool operator>=(const Time&) const;
00069                         // arithmatic ops - homogenous
00070                 virtual Time operator+(const Time&) const;
00071                 virtual Time operator-(const Time&) const;
00072                 virtual Time operator*(const Time&) const;
00073                 virtual Time operator/(const Time&) const;
00074                 virtual Time operator%(const Time&) const;
00075                         // assignment ops - homogenous
00076                 virtual Time& operator=(const Time&);
00077                 virtual Time& operator+=(const Time&);
00078                 virtual Time& operator-=(const Time&);
00079                 virtual Time& operator*=(const Time&);
00080                 virtual Time& operator/=(const Time&);
00081                 virtual Time& operator%=(const Time&);
00082                 virtual Time& operator++();
00083                 virtual Time& operator--();
00084 
00085                         // arithmatic ops - heterogenous
00086                 virtual Time operator+(const int64_t);
00087                 virtual Time operator-(const int64_t);
00088                 virtual Time operator*(const int64_t);
00089                 virtual Time operator/(const int64_t);
00090                 virtual Time operator%(const int64_t);
00091                         // assignment ops - heterogenous
00092                 virtual Time& operator=(const int64_t);
00093                 virtual Time& operator+=(const int64_t);
00094                 virtual Time& operator-=(const int64_t);
00095                 virtual Time& operator*=(const int64_t);
00096                 virtual Time& operator/=(const int64_t);
00097                 virtual Time& operator%=(const int64_t);
00098 
00099 //              ostream& operator<<(ostream&, const Time&);
00100 
00101                 // @todo test/validate functions
00102 };
00103 
00104 /******************************************************************************
00105 *       04/01/2005 Snugglebear
00106 *       NanoTime class - derivative of Time
00107 *       The NanoTime class is a basic time type that includes a bounded count of
00108 *       nanoseconds. Combined with its parent, this class forms the equivalent of
00109 *       a posix timeval struct. However, given the hard bounds on nanoseconds, this
00110 *       class does automatic carrying when necessary.
00111 ******************************************************************************/
00112 
00113 class NanoTime : public Time
00114 {
00115         private:
00116                 int32_t mNanoSeconds;                   // count of nanoseconds
00117                                                                                 // bounds [-1.0e9 + 1, 1.0e9 - 1]
00118                 const static int32_t    LB_NANOSECONDS = 999999999;
00119                 const static int32_t    UB_NANOSECONDS = -999999999;
00120 
00121         public:
00122                 // garden variety constructors
00123                 NanoTime();
00124                 NanoTime(const int64_t, const int32_t);
00125                 NanoTime(const double);
00126                 NanoTime(const NanoTime&);
00127 
00128                 // get & sets
00129                 int32_t nanoSeconds() const;
00130                 void nanoSeconds(const int32_t);
00131                 void setNanoTime(const double);
00132 
00133                 // function to print NanoTime to the standard output
00134                 void printNanoTime() const;
00135                 void printNanoSeconds() const;
00136 
00137                 // operator overloads
00138                         // comparison ops - homogenous
00139                 virtual bool operator!=(const NanoTime&) const;
00140                 virtual bool operator==(const NanoTime&) const;
00141                 virtual bool operator<(const NanoTime&) const;
00142                 virtual bool operator>(const NanoTime&) const;
00143                 virtual bool operator<=(const NanoTime&) const;
00144                 virtual bool operator>=(const NanoTime&) const;
00145                         // arithmatic ops - homogenous
00146                 virtual NanoTime operator+(const NanoTime&);
00147                 virtual NanoTime operator-(const NanoTime&);
00148                 virtual NanoTime operator*(const NanoTime&);
00149                 virtual NanoTime operator/(const NanoTime&);
00150                 virtual NanoTime operator%(const NanoTime&);
00151                         // assignment ops - homogenous
00152                 virtual NanoTime& operator=(const NanoTime&);
00153                 virtual NanoTime& operator+=(const NanoTime&);
00154                 virtual NanoTime& operator-=(const NanoTime&);
00155                 virtual NanoTime& operator*=(const NanoTime&);
00156                 virtual NanoTime& operator/=(const NanoTime&);
00157                 virtual NanoTime& operator%=(const NanoTime&);
00158 
00159                         // arithmatic ops - heterogenous double
00160                 virtual NanoTime operator+(const double);
00161                 virtual NanoTime operator-(const double);
00162                 virtual NanoTime operator*(const double);
00163                 virtual NanoTime operator/(const double);
00164                 virtual NanoTime operator%(const double);
00165                         // assignment ops - heterogenous double
00166                 virtual NanoTime& operator=(const double);
00167                 virtual NanoTime& operator+=(const double);
00168                 virtual NanoTime& operator-=(const double);
00169                 virtual NanoTime& operator*=(const double);
00170                 virtual NanoTime& operator/=(const double);
00171                 virtual NanoTime& operator%=(const double);
00172 
00173 //              virtual ostream& operator<<(ostream&, const NanoTime&);
00174 
00176 };
00177 
00178 /*
00179 class MilTime : public Time
00180 {
00181         private:
00182                 uint16_t        mHour,                          // count of hours, bounds [0-23]
00183                                         mMinute,                        // count of minutes, bounds [0-59]
00184                                         mSecond;                        // count of seconds, bounds [0-60]
00185 
00186                 const static uint16_t   LB_HOUR = 0;
00187                 const static uint16_t   UB_HOUR = 23;
00188                 const static uint16_t   LB_MINUTE = 0;
00189                 const static uint16_t   UB_MINUTE = 59;
00190                 const static uint16_t   LB_SECOND = 0;
00191                 const static uint16_t   UB_SECOND = 60; // leap seconds
00192 
00193         public:
00194                 // garden variety constructors
00195                 MilTime();
00196                 MilTime(uint16_t, uint16_t, uint16_t, uint64_t);
00197                 MilTime(const MilTime&);
00198 
00199                 // get & sets
00200                 uint16_t hour() const;
00201                 uint16_t minute() const;
00202                 uint16_t second() const;
00203 
00204                 void hour(const uint16_t);
00205                 void minute(const uint16_t);
00206                 void second(const uint16_t);
00207 
00208                 void reconcileOverflow();
00209 
00210                 // output functions to display on the standard output
00211                         // display logic must add one for base shift
00212                 void printMilTime() const;
00213                 void printHour() const;
00214                 void printMinute() const;
00215                 void printSecond() const;
00216 
00217                 // operator overloads
00218                         // comparison ops - homogenous
00219                 virtual bool operator!=(const MilTime&) const;
00220                 virtual bool operator==(const MilTime&) const;
00221                 virtual bool operator<(const MilTime&) const;
00222                 virtual bool operator>(const MilTime&) const;
00223                 virtual bool operator<=(const MilTime&) const;
00224                 virtual bool operator>=(const MilTime&) const;
00225 
00226                 virtual ostream& operator<<(ostream&, const MilTime&);
00227 
00228                 // math overloads - just add & subtract for homogenous ops
00229                 // others are nonsensical and/or of dubious value
00230                 virtual MilTime operator+(const MilTime&) const;
00231                 virtual MilTime operator-(const MilTime&) const;
00232                 virtual MilTime& operator+=(const MilTime&);
00233                 virtual MilTime& operator-=(const MilTime&);
00234                 virtual MilTime& operator=(const MilTime&);
00235 
00236                 // math overloads for doubles - only two make sense
00237                 // multiplication and division
00238                 // all are vectorized - no overflow considered
00239                 virtual MilTime operator*(const double) const;
00240                 virtual MilTime operator/(const double) const;
00241                 virtual MilTime& operator*=(const double);
00242                 virtual MilTime& operator/=(const double);
00244 };
00245 */
00246 };      // end namespace Phx
00247 #endif

Generated on Mon Jul 10 19:45:29 2006 for Phoenix OSFS by  doxygen 1.4.2