Week.hpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
42 
43 #ifndef GNSSTK_WEEK_HPP
44 #define GNSSTK_WEEK_HPP
45 
46 #define timeSystemCheck if(timeSystem != right.timeSystem && \
47  timeSystem != TimeSystem::Any && right.timeSystem != TimeSystem::Any) \
48  GNSSTK_THROW(InvalidRequest( \
49  "CommonTime objects not in same time system, cannot be compared"))
50 
51 #include "TimeTag.hpp"
52 #include "TimeConverters.hpp"
53 
54 namespace gnsstk
55 {
57 
58 
81  class Week : public TimeTag
82  {
83  public:
84 
90  virtual int Nbits(void) const = 0;
91 
97  virtual int bitmask(void) const = 0;
98 
101  virtual int rollover(void) const
102  { return bitmask()+1; }
103 
111  virtual long MJDEpoch(void) const = 0;
112 
115  int MAXWEEK(void) const
116  {
117  static const int mw=(CommonTime::END_LIMIT_JDAY - MJD_JDAY - MJDEpoch()) / 7;
118  return mw;
119  }
120 
123  : week(w)
124  { timeSystem = ts; }
125 
127  virtual ~Week()
128  {}
129 
131  Week& operator=(const Week& right);
132 
134 
135  inline bool operator==(const Week& right) const
136  {
137  // Any (wildcard) type exception allowed, otherwise must be same time systems
138  if(timeSystem != right.timeSystem &&
140  return false;
141 
142  return (week == right.week);
143  }
144 
145  inline bool operator!=(const Week& right) const
146  {
148  return (week != right.week);
149  }
150 
151  inline bool operator<(const Week& right) const
152  {
154  return week < right.week;
155  }
156 
157  inline bool operator<=(const Week& right) const
158  {
160  return week <= right.week;
161  }
162 
163  inline bool operator>(const Week& right) const
164  {
166  return week > right.week;
167  }
168 
169  inline bool operator>=(const Week& right) const
170  {
172  return week >= right.week;
173  }
175 
177 
178  inline virtual unsigned int getWeek() const
179  {
180  return week;
181  }
182 
183  inline virtual unsigned int getModWeek() const
184  {
185  return (week & bitmask());
186  }
187 
188  inline virtual unsigned int getEpoch() const
189  {
190  return (week >> Nbits());
191  }
192 
193  inline virtual void getEpochModWeek(unsigned int& e,
194  unsigned int& w) const
195  {
196  e = getEpoch();
197  w = getModWeek();
198  }
199 
200  inline virtual void setEpoch(unsigned int e)
201  {
202  week &= bitmask();
203  week |= e << Nbits();
204  }
205 
206  inline virtual void setModWeek(unsigned int w)
207  {
208  week &= ~bitmask();
209  week |= w & bitmask();
210  }
211 
212  inline virtual void setEpochModWeek(unsigned int e,
213  unsigned int w)
214  {
215  setEpoch(e);
216  setModWeek(w);
217  }
218 
219  inline virtual void adjustToYear(unsigned int y)
220  {
221  long jd1,jd2;
222  int ep1,ep2;
223  jd1 = convertCalendarToJD(y,1,1);
224  ep1 = (jd1 - MJD_JDAY - MJDEpoch())/7/rollover();
225  jd2 = convertCalendarToJD(y,12,31);
226  ep2 = (jd2 - MJD_JDAY - MJDEpoch())/7/rollover();
227  unsigned int halfroll = rollover()/2;
228  unsigned int mw = getModWeek();
229 
230  if(ep1 == ep2) // no rollover in given year
231  setEpoch(ep1);
232  else if(mw <= halfroll)
233  setEpoch(ep2); // rollover happened before mw -> use ep2
234  else
235  setEpoch(ep1); // rollover happened after mw
236  }
237 
239 
242  inline virtual std::string getPrintChars() const
243  {
244  return "EFGP";
245  }
246 
248  inline virtual std::string getDefaultFormat() const
249  {
250  return "%04F";
251  }
252 
253  virtual bool isValid() const
254  {
255  return ((week >= 0) && (week <= MAXWEEK()));
256  }
257 
258  inline virtual void reset()
259  {
260  week = 0;
261  }
262 
264  virtual unsigned int getDayOfWeek() const = 0;
265 
266  // member data
267  int week;
268  };
269 
271 
272 } // namespace
273 
274 #undef timeSystemCheck
275 
276 #endif // GNSSTK_WEEK_HPP
gnsstk::Week::getWeek
virtual unsigned int getWeek() const
Definition: Week.hpp:178
gnsstk::Week::adjustToYear
virtual void adjustToYear(unsigned int y)
Definition: Week.hpp:219
gnsstk::Week::getEpoch
virtual unsigned int getEpoch() const
Definition: Week.hpp:188
gnsstk::Week::operator=
Week & operator=(const Week &right)
Assignment Operator.
Definition: Week.cpp:46
gnsstk::Week
Definition: Week.hpp:81
gnsstk::Week::isValid
virtual bool isValid() const
Returns true if this object's members are valid, false otherwise.
Definition: Week.hpp:253
gnsstk::Week::operator!=
bool operator!=(const Week &right) const
Definition: Week.hpp:145
gnsstk::Week::~Week
virtual ~Week()
Virtual Destructor.
Definition: Week.hpp:127
gnsstk::TimeSystem::Any
@ Any
wildcard; allows comparison with any other type
gnsstk::Week::getEpochModWeek
virtual void getEpochModWeek(unsigned int &e, unsigned int &w) const
Definition: Week.hpp:193
gnsstk::MJD_JDAY
const long MJD_JDAY
'Julian day' offset from MJD
Definition: TimeConstants.hpp:53
gnsstk::Week::setEpoch
virtual void setEpoch(unsigned int e)
Definition: Week.hpp:200
gnsstk::Week::operator<=
bool operator<=(const Week &right) const
Definition: Week.hpp:157
gnsstk::Week::Nbits
virtual int Nbits(void) const =0
gnsstk::TimeSystem::Unknown
@ Unknown
unknown time frame; for legacy code compatibility
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::TimeTag::timeSystem
TimeSystem timeSystem
time system (representation) of the data
Definition: TimeTag.hpp:204
gnsstk::Week::operator==
bool operator==(const Week &right) const
Definition: Week.hpp:135
gnsstk::Week::setModWeek
virtual void setModWeek(unsigned int w)
Definition: Week.hpp:206
gnsstk::TimeTag
Definition: TimeTag.hpp:58
y
page HOWTO subpage DoxygenGuide Documenting Your Code page DoxygenGuide Documenting Your Code todo Flesh out this document section doctips Tips for Documenting When defining make sure that the prototype is identical between the cpp and hpp including both the namespaces and the parameter names for you have std::string as the return type in the hpp file and string as the return type in the cpp Doxygen may get confused and autolink to the cpp version with no documentation If you don t use the same parameter names between the cpp and hpp that will also confuse Doxygen Don t put type information in return or param documentation It doesn t really add anything and will often cause Doxygen to complain and not produce the documentation< br > use note Do not put a comma after a param name unless you mean to document multiple parameters< br/> the output stream</code >< br/> y
Definition: DOCUMENTING.dox:15
gnsstk::Week::getDefaultFormat
virtual std::string getDefaultFormat() const
Return a string containing the default format to use in printing.
Definition: Week.hpp:248
gnsstk::Week::Week
Week(int w=0, TimeSystem ts=TimeSystem::Unknown)
Constructor.
Definition: Week.hpp:122
gnsstk::Week::operator>
bool operator>(const Week &right) const
Definition: Week.hpp:163
gnsstk::TimeSystem
TimeSystem
Definition of various time systems.
Definition: TimeSystem.hpp:51
gnsstk::Week::operator>=
bool operator>=(const Week &right) const
Definition: Week.hpp:169
gnsstk::Week::bitmask
virtual int bitmask(void) const =0
TimeConverters.hpp
gnsstk::Week::week
int week
Full week number.
Definition: Week.hpp:267
TimeTag.hpp
gnsstk::Week::MAXWEEK
int MAXWEEK(void) const
Definition: Week.hpp:115
gnsstk::CommonTime::END_LIMIT_JDAY
static const GNSSTK_EXPORT long END_LIMIT_JDAY
Definition: CommonTime.hpp:99
gnsstk::Week::getDayOfWeek
virtual unsigned int getDayOfWeek() const =0
Force this interface on this classes descendants.
gnsstk::Week::MJDEpoch
virtual long MJDEpoch(void) const =0
gnsstk::Week::operator<
bool operator<(const Week &right) const
Definition: Week.hpp:151
gnsstk::convertCalendarToJD
long convertCalendarToJD(int yy, int mm, int dd)
Definition: TimeConverters.cpp:100
timeSystemCheck
#define timeSystemCheck
Definition: Week.hpp:46
gnsstk::Week::reset
virtual void reset()
Reset this object to the default state.
Definition: Week.hpp:258
gnsstk::Week::setEpochModWeek
virtual void setEpochModWeek(unsigned int e, unsigned int w)
Definition: Week.hpp:212
gnsstk::Week::getModWeek
virtual unsigned int getModWeek() const
Definition: Week.hpp:183
gnsstk::Week::rollover
virtual int rollover(void) const
Definition: Week.hpp:101
gnsstk::Week::getPrintChars
virtual std::string getPrintChars() const
Definition: Week.hpp:242


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:42