00001 #pragma ident "$Id: UnixTime.hpp 1162 2008-03-27 21:18:13Z snelsen $"
00002
00003
00004
00005 #ifndef GPSTK_UNIXTIME_HPP
00006 #define GPSTK_UNIXTIME_HPP
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "TimeTag.hpp"
00031
00032 #ifdef _MSC_VER
00033
00034
00035 struct timeval {
00036 long tv_sec;
00037 long tv_usec;
00038 };
00039 #else
00040 #include <sys/time.h>
00041 #endif
00042
00043 namespace gpstk
00044 {
00048 class UnixTime : public TimeTag
00049 {
00050 public:
00056
00061 UnixTime( int sec = 0,
00062 int usec = 0 )
00063 throw()
00064 {
00065 tv.tv_sec = sec; tv.tv_usec = usec;
00066 }
00067
00071 UnixTime( struct timeval t )
00072 throw()
00073 {
00074 tv.tv_sec = t.tv_sec; tv.tv_usec = t.tv_usec;
00075 }
00076
00081 UnixTime( const UnixTime& right )
00082 throw()
00083 : tv( right.tv )
00084 {}
00085
00093 UnixTime( const TimeTag& right )
00094 throw( gpstk::InvalidRequest )
00095 {
00096 convertFromCommonTime( right.convertToCommonTime() );
00097 }
00098
00106 UnixTime( const CommonTime& right )
00107 throw( InvalidRequest )
00108 {
00109 convertFromCommonTime( right );
00110 }
00111
00117 UnixTime& operator=( const UnixTime& right )
00118 throw();
00119
00121 virtual ~UnixTime()
00122 throw()
00123 {}
00125
00126
00127 virtual CommonTime convertToCommonTime() const
00128 throw( InvalidRequest );
00129
00130 virtual void convertFromCommonTime( const CommonTime& ct )
00131 throw( InvalidRequest );
00132
00135 virtual std::string printf( const std::string& fmt ) const
00136 throw( gpstk::StringUtils::StringException );
00137
00140 virtual std::string printError( const std::string& fmt ) const
00141 throw( gpstk::StringUtils::StringException );
00142
00149 virtual bool setFromInfo( const IdToValue& info )
00150 throw();
00151
00154 virtual std::string getPrintChars() const
00155 throw()
00156 {
00157 return "Uu";
00158 }
00159
00161 virtual std::string getDefaultFormat() const
00162 throw()
00163 {
00164 return "%U %u";
00165 }
00166
00167 virtual bool isValid() const
00168 throw();
00169
00170 virtual void reset()
00171 throw();
00172
00181 virtual bool operator==( const UnixTime& right ) const
00182 throw();
00183 virtual bool operator!=( const UnixTime& right ) const
00184 throw();
00185 virtual bool operator<( const UnixTime& right ) const
00186 throw();
00187 virtual bool operator>( const UnixTime& right ) const
00188 throw();
00189 virtual bool operator<=( const UnixTime& right ) const
00190 throw();
00191 virtual bool operator>=( const UnixTime& right ) const
00192 throw();
00194
00195 struct timeval tv;
00196 };
00197
00198 }
00199
00200 #endif