UnixTime.hpp

Go to the documentation of this file.
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 //  This file is part of GPSTk, the GPS Toolkit.
00011 //
00012 //  The GPSTk is free software; you can redistribute it and/or modify
00013 //  it under the terms of the GNU Lesser General Public License as published
00014 //  by the Free Software Foundation; either version 2.1 of the License, or
00015 //  any later version.
00016 //
00017 //  The GPSTk is distributed in the hope that it will be useful,
00018 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //  GNU Lesser General Public License for more details.
00021 //
00022 //  You should have received a copy of the GNU Lesser General Public
00023 //  License along with GPSTk; if not, write to the Free Software Foundation,
00024 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 //  
00026 //  Copyright 2004, The University of Texas at Austin
00027 //
00028 //============================================================================
00029 
00030 #include "TimeTag.hpp"
00031 
00032 #ifdef _MSC_VER
00033 // timeval is defined in winsock.h, which we don't want to include
00034 // because it breaks lots of this code
00035 struct timeval {
00036   long    tv_sec;         /* seconds */
00037   long    tv_usec;        /* and microseconds */
00038 };
00039 #else
00040 #include <sys/time.h>     // for struct timeval
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          // The following functions are required by TimeTag.
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 } // namespace
00199 
00200 #endif // GPSTK_UNIXTIME_HPP

Generated on Tue May 22 03:31:02 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1