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
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
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 }
00294
00295 #endif