GSatID.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 
40 
41 #ifndef CLASS_GEOMATIC_SATELLITE_ID_INCLUDE
42 #define CLASS_GEOMATIC_SATELLITE_ID_INCLUDE
43 
44 #include "gnsstk_export.h"
45 #include "Exception.hpp"
46 #include "SatID.hpp"
47 
48 namespace gnsstk
49 {
50  class GSatID : public SatID
51  {
52  public:
55  {
56  id = -1;
58  }
59 
62  {
63  id = p;
64  system = s;
65  switch (system)
66  {
76  break;
77  default:
79  id = -1;
80  }
81  }
82 
86  GSatID(std::string& str)
87  {
88  try
89  {
90  this->fromString(str);
91  }
92  catch (Exception& e)
93  {
94  GNSSTK_RETHROW(e);
95  }
96  }
97 
99  GSatID(const SatID& sat) { *this = GSatID(sat.id, sat.system); }
100 
102  char setfill(char c)
103  {
104  char csave = fillchar;
105  fillchar = c;
106  return csave;
107  }
108 
110  char getfill() { return fillchar; }
111 
112  // operator=, copy constructor and destructor built by compiler
113 
115  bool operator==(const GSatID& right) const
116  {
117  return ((system == right.system) && (id == right.id));
118  }
119 
121  bool operator<(const GSatID& right) const
122  {
123  if (system == right.system)
124  {
125  return (id < right.id);
126  }
127  return (system < right.system);
128  }
129 
130  // the rest follow from Boolean algebra...
132  bool operator!=(const GSatID& right) const
133  {
134  return !operator==(right);
135  }
136 
138  bool operator>=(const GSatID& right) const
139  {
140  return !operator<(right);
141  }
142 
144  bool operator<=(const GSatID& right) const
145  {
146  return (operator<(right) || operator==(right));
147  }
148 
150  bool operator>(const GSatID& right) const
151  {
152  return (!operator<(right) && !operator==(right));
153  }
154 
156  char systemChar() const
157  {
158  switch (system)
159  {
161  return 'G';
163  return 'E';
165  return 'R';
167  return 'S';
169  return 'T';
171  return 'L';
173  return 'J';
175  return 'C';
177  return 'I';
178  default:
179  return '?';
180  }
181  };
182 
184  std::string systemString() const
185  {
186  switch (system)
187  {
189  return "GPS";
191  return "Galileo";
193  return "Glonass";
195  return "Geosync";
197  return "Transit";
199  return "LEO";
201  return "QZSS";
203  return "BeiDou";
205  return "IRNSS";
206  default:
207  return "Unknown";
208  }
209  };
210 
216  void fromString(const std::string& s)
217  {
218  char c;
219  std::istringstream iss(s);
220 
221  id = -1;
222  system = SatelliteSystem::GPS; // default
223  if (s.find_first_not_of(std::string(" \t\n"), 0) == std::string::npos)
224  {
225  return; // all whitespace yields the default
226  }
227 
228  iss >> c; // read one character (non-whitespace)
229  switch (c)
230  {
231  // no leading system character
232  case '0':
233  case '1':
234  case '2':
235  case '3':
236  case '4':
237  case '5':
238  case '6':
239  case '7':
240  case '8':
241  case '9':
242  iss.putback(c);
244  break;
245  case 'R':
246  case 'r':
248  break;
249  case 'T':
250  case 't':
252  break;
253  case 'S':
254  case 's':
256  break;
257  case 'E':
258  case 'e':
260  break;
261  case 'L':
262  case 'l':
264  break;
265  case ' ':
266  case 'G':
267  case 'g':
269  break;
270  case 'J':
271  case 'j':
273  break;
274  case 'C':
275  case 'c':
277  break;
278  case 'I':
279  case 'i':
281  break;
282  default: // invalid system character
283  Exception e(std::string("Invalid system character \"") + c +
284  std::string("\""));
285  GNSSTK_THROW(e);
286  }
287  iss >> id;
288  if (id <= 0)
289  {
290  id = -1;
291  }
292  }
293 
295  std::string toString() const
296  {
297  std::ostringstream oss;
298  char savechar = oss.fill(fillchar);
299  oss << systemChar() << std::setw(2) << id << std::setfill(savechar);
300  return oss.str();
301  }
302 
303  private:
304 
305  GNSSTK_EXPORT
306  static char fillchar;
307 
308  }; // class GSatID
309 
311  inline std::ostream& operator<<(std::ostream& s, const GSatID& sat)
312  {
313  s << sat.toString();
314  return s;
315  }
316 
317 } // namespace gnsstk
318 
319 #endif
320 // nothing below this
gnsstk::SatelliteSystem::IRNSS
@ IRNSS
Official name changed from IRNSS to NavIC.
gnsstk::SatID::id
int id
Satellite identifier, e.g. PRN.
Definition: SatID.hpp:154
gnsstk::GSatID::operator>=
bool operator>=(const GSatID &right) const
boolean operator>=
Definition: GSatID.hpp:138
gnsstk::GSatID::operator<
bool operator<(const GSatID &right) const
operator< (used by STL to sort)
Definition: GSatID.hpp:121
gnsstk::GSatID::operator<=
bool operator<=(const GSatID &right) const
boolean operator<=
Definition: GSatID.hpp:144
gnsstk::GSatID::fromString
void fromString(const std::string &s)
Definition: GSatID.hpp:216
gnsstk::GSatID::GSatID
GSatID(int p, SatelliteSystem s)
explicit constructor, no defaults
Definition: GSatID.hpp:61
gnsstk::GSatID::fillchar
static GNSSTK_EXPORT char fillchar
fill character used during stream output
Definition: GSatID.hpp:306
gnsstk::SatelliteSystem::LEO
@ LEO
gnsstk::SatelliteSystem
SatelliteSystem
Supported satellite systems.
Definition: SatelliteSystem.hpp:55
gnsstk::GSatID::operator==
bool operator==(const GSatID &right) const
operator ==
Definition: GSatID.hpp:115
gnsstk::SatelliteSystem::Transit
@ Transit
gnsstk::SatID
Definition: SatID.hpp:89
SatID.hpp
gnsstk::GSatID::GSatID
GSatID(std::string &str)
Definition: GSatID.hpp:86
gnsstk::GSatID::GSatID
GSatID(const SatID &sat)
cast SatID to GSatID
Definition: GSatID.hpp:99
gnsstk::GSatID::setfill
char setfill(char c)
set the fill character used in output return the current fill character
Definition: GSatID.hpp:102
gnsstk::SatelliteSystem::Geosync
@ Geosync
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::Exception
Definition: Exception.hpp:151
gnsstk::SatelliteSystem::GPS
@ GPS
gnsstk::GSatID::GSatID
GSatID()
empty constructor, creates an invalid object
Definition: GSatID.hpp:54
gnsstk::GSatID
Definition: GSatID.hpp:50
gnsstk::GSatID::toString
std::string toString() const
convert to string
Definition: GSatID.hpp:295
gnsstk::GSatID::operator>
bool operator>(const GSatID &right) const
boolean operator>
Definition: GSatID.hpp:150
gnsstk::operator<<
std::ostream & operator<<(std::ostream &s, const ObsEpoch &oe) noexcept
Definition: ObsEpochMap.cpp:54
gnsstk::GSatID::systemChar
char systemChar() const
return the single-character system descriptor
Definition: GSatID.hpp:156
gnsstk::GSatID::operator!=
bool operator!=(const GSatID &right) const
boolean operator!=
Definition: GSatID.hpp:132
GNSSTK_RETHROW
#define GNSSTK_RETHROW(exc)
Definition: Exception.hpp:369
gnsstk::SatID::system
SatelliteSystem system
System for this satellite.
Definition: SatID.hpp:156
gnsstk::GSatID::systemString
std::string systemString() const
return string describing system
Definition: GSatID.hpp:184
Exception.hpp
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::SatelliteSystem::Glonass
@ Glonass
gnsstk::SatelliteSystem::BeiDou
@ BeiDou
aka Compass
gnsstk::SatelliteSystem::QZSS
@ QZSS
gnsstk::SatelliteSystem::Galileo
@ Galileo
gnsstk::GSatID::getfill
char getfill()
get the fill character used in output
Definition: GSatID.hpp:110


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