GPSWeek.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: GPSWeek.hpp 3140 2012-06-18 15:03:02Z susancummins $"
00002 
00003 #ifndef GPSTK_GPSWEEK_HPP
00004 #define GPSTK_GPSWEEK_HPP
00005 
00006 //============================================================================
00007 //
00008 //  This file is part of GPSTk, the GPS Toolkit.
00009 //
00010 //  The GPSTk is free software; you can redistribute it and/or modify
00011 //  it under the terms of the GNU Lesser General Public License as published
00012 //  by the Free Software Foundation; either version 2.1 of the License, or
00013 //  any later version.
00014 //
00015 //  The GPSTk is distributed in the hope that it will be useful,
00016 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 //  GNU Lesser General Public License for more details.
00019 //
00020 //  You should have received a copy of the GNU Lesser General Public
00021 //  License along with GPSTk; if not, write to the Free Software Foundation,
00022 //  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
00023 //  
00024 //  Copyright 2004, The University of Texas at Austin
00025 //
00026 //============================================================================
00027 
00028 //============================================================================
00029 //
00030 //This software developed by Applied Research Laboratories at the University of
00031 //Texas at Austin, under contract to an agency or agencies within the U.S. 
00032 //Department of Defense. The U.S. Government retains all rights to use,
00033 //duplicate, distribute, disclose, or release this software. 
00034 //
00035 //Pursuant to DoD Directive 523024 
00036 //
00037 // DISTRIBUTION STATEMENT A: This software has been approved for public 
00038 //                           release, distribution is unlimited.
00039 //
00040 //=============================================================================
00041 
00042 #include "TimeTag.hpp"
00043 
00044 namespace gpstk
00045 {
00078    class GPSWeek : public TimeTag
00079    {
00080    public:
00083       static const int bits10 = 0x3FF;
00086       static const int MAX_WEEK;
00087 
00089       GPSWeek( int w = 0,
00090                TimeSystem ts = TimeSystem::Unknown )
00091          throw()
00092             : week(w) 
00093       { timeSystem = ts; }
00094       
00096       virtual ~GPSWeek()
00097          throw()
00098       {}
00099       
00101       GPSWeek& operator=(const GPSWeek& right)
00102          throw();
00103       
00105 
00106       inline bool operator==(const GPSWeek& right) const
00107          throw()
00108       {
00110          if ((timeSystem != TimeSystem::Any &&
00111               right.timeSystem != TimeSystem::Any) &&
00112              timeSystem != right.timeSystem)
00113             return false;
00114 
00115          return week == right.week;
00116       }
00117       
00118       inline bool operator!=(const GPSWeek& right) const
00119          throw( gpstk::InvalidRequest )
00120       {
00122          if ((timeSystem != TimeSystem::Any &&
00123               right.timeSystem != TimeSystem::Any) &&
00124              timeSystem != right.timeSystem)
00125          {
00126             gpstk::InvalidRequest ir("CommonTime objects not in same time system, cannot be compared");
00127             GPSTK_THROW(ir);
00128          }
00129 
00130          return week != right.week;
00131       }
00132       
00133       inline bool operator<(const GPSWeek& right) const
00134          throw( gpstk::InvalidRequest )
00135       {
00137          if ((timeSystem != TimeSystem::Any &&
00138               right.timeSystem != TimeSystem::Any) &&
00139              timeSystem != right.timeSystem)
00140          {
00141             gpstk::InvalidRequest ir("CommonTime objects not in same time system, cannot be compared");
00142             GPSTK_THROW(ir);
00143          }
00144 
00145          return week < right.week;
00146       }
00147       
00148       inline bool operator<=(const GPSWeek& right) const
00149          throw( gpstk::InvalidRequest )
00150       {
00152          if ((timeSystem != TimeSystem::Any &&
00153               right.timeSystem != TimeSystem::Any) &&
00154              timeSystem != right.timeSystem)
00155          {
00156             gpstk::InvalidRequest ir("CommonTime objects not in same time system, cannot be compared");
00157             GPSTK_THROW(ir);
00158          }
00159 
00160          return week <= right.week;
00161       }
00162       
00163       inline bool operator>(const GPSWeek& right) const
00164          throw( gpstk::InvalidRequest )
00165       {
00167          if ((timeSystem != TimeSystem::Any &&
00168               right.timeSystem != TimeSystem::Any) &&
00169              timeSystem != right.timeSystem)
00170          {
00171             gpstk::InvalidRequest ir("CommonTime objects not in same time system, cannot be compared");
00172             GPSTK_THROW(ir);
00173          }
00174 
00175          return week > right.week;
00176       }
00177       
00178       inline bool operator>=(const GPSWeek& right) const
00179          throw( gpstk::InvalidRequest )
00180       {
00182          if ((timeSystem != TimeSystem::Any &&
00183               right.timeSystem != TimeSystem::Any) &&
00184              timeSystem != right.timeSystem)
00185          {
00186             gpstk::InvalidRequest ir("CommonTime objects not in same time system, cannot be compared");
00187             GPSTK_THROW(ir);
00188          }
00189 
00190          return week >= right.week;
00191       }
00193 
00196 
00197       inline virtual unsigned int getEpoch() const
00198          throw()
00199       {
00200          return week >> 10;
00201       }
00202       
00203       inline virtual unsigned int getWeek10() const
00204          throw()
00205       {
00206          return week & bits10;
00207       }
00208       
00209       inline virtual void getEpochWeek10(unsigned int& e, 
00210                                          unsigned int& w) const
00211          throw()
00212       {
00213          e = getEpoch(); 
00214          w = getWeek10();
00215       }
00216       
00217       inline virtual void setEpoch(unsigned int e)
00218          throw()
00219       {
00220          week &= bits10;
00221          week |= e << 10;
00222       }
00223 
00224       inline virtual void setWeek10(unsigned int w)
00225          throw()
00226       { 
00227          week &= ~bits10; 
00228          week |= w & bits10;
00229       }
00230       
00231       inline virtual void setEpochWeek10(unsigned int e,
00232                                          unsigned int w)
00233          throw()
00234       {
00235          setEpoch(e);
00236          setWeek10(w);
00237       }
00239       
00242       virtual std::string printf( const std::string& fmt ) const
00243          throw( gpstk::StringUtils::StringException );
00244       
00247       virtual std::string printError( const std::string& fmt ) const
00248          throw( gpstk::StringUtils::StringException );
00249 
00256       virtual bool setFromInfo( const IdToValue& info )
00257          throw();
00258 
00261       inline virtual std::string getPrintChars() const
00262          throw()
00263       { 
00264          return "EFGP";
00265       }
00266          
00268       inline virtual std::string getDefaultFormat() const
00269          throw()
00270       {
00271          return "%04F";
00272       }
00273 
00274       virtual bool isValid() const
00275          throw()
00276       {
00277          return (week >= 0 && week <= MAX_WEEK);
00278       }
00279       
00280       inline virtual void reset()
00281          throw()
00282       {
00283          week = 0;
00284       }
00285       
00287       virtual unsigned int getDayOfWeek() const
00288          throw() = 0;
00289 
00290       int week;
00291    };
00292 
00293 } // namespace
00294 
00295 #endif // GPSTK_GPSTIME_HPP

Generated on Thu May 23 03:31:08 2013 for GPS ToolKit Software Library by  doxygen 1.3.9.1