00001 #pragma ident "$Id: RinexSatID.hpp 2319 2010-02-18 22:25:45Z raindave $"
00002
00003 #ifndef GPSTK_RINEX_SATID_HPP
00004 #define GPSTK_RINEX_SATID_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 <iostream>
00043 #include <sstream>
00044 #include <iomanip>
00045
00046 #include "Exception.hpp"
00047 #include "SatID.hpp"
00048
00055 namespace gpstk
00056 {
00057 class RinexSatID : public SatID
00058 {
00059
00060 public:
00061
00063
00064 RinexSatID()
00065 throw()
00066 { id = -1; system = systemUnknown; }
00067
00068
00070
00071 RinexSatID(int p, SatelliteSystem s)
00072 throw()
00073 {
00074 id = p; system = s;
00075 switch(s)
00076 {
00077 case systemGPS:
00078 case systemGalileo:
00079 case systemGlonass:
00080 case systemGeosync:
00081 case systemTransit:
00082 break;
00083
00084 default:
00085 system = systemUnknown;
00086 id = -1;
00087 }
00088 }
00089
00090
00092
00093 RinexSatID(const std::string& str)
00094 throw(Exception)
00095 {
00096 try { fromString(str); }
00097 catch(Exception& e) { GPSTK_RETHROW(e); }
00098 }
00099
00100
00102
00103 RinexSatID(const SatID& sat)
00104 throw()
00105 { *this = RinexSatID(sat.id,sat.system); }
00106
00107
00110
00111 char setfill(char c)
00112 throw()
00113 { char csave = fillchar; fillchar = c; return csave; }
00114
00115
00117
00118 char getfill()
00119 throw()
00120 { return fillchar; }
00121
00122
00123
00124
00125
00128
00129 char systemChar() const
00130 throw()
00131 {
00132 switch(system)
00133 {
00134 case systemGPS: return 'G';
00135 case systemGalileo: return 'E';
00136 case systemGlonass: return 'R';
00137 case systemGeosync: return 'S';
00138 case systemTransit: return 'T';
00139 default: return '?';
00140 }
00141 };
00142
00143
00146
00147 std::string systemString() const
00148 throw()
00149 {
00150 switch(system)
00151 {
00152 case systemGPS: return "GPS";
00153 case systemGalileo: return "Galileo";
00154 case systemGlonass: return "GLONASS";
00155 case systemGeosync: return "Geosync";
00156 case systemTransit: return "Transit";
00157 default: return "Unknown";
00158 }
00159 };
00160
00161
00164
00165 void fromString(const std::string s)
00166 throw(Exception)
00167 {
00168 char c;
00169 std::istringstream iss(s);
00170
00171 id = -1; system = systemGPS;
00172 if(s.find_first_not_of(std::string(" \t\n"), 0) == std::string::npos)
00173 return;
00174
00175 iss >> c;
00176 switch(c)
00177 {
00178
00179 case '0': case '1': case '2': case '3': case '4':
00180 case '5': case '6': case '7': case '8': case '9':
00181 iss.putback(c);
00182 system = SatID::systemGPS;
00183 break;
00184 case 'R': case 'r':
00185 system = SatID::systemGlonass;
00186 break;
00187 case 'T': case 't':
00188 system = SatID::systemTransit;
00189 break;
00190 case 'S': case 's':
00191 system = SatID::systemGeosync;
00192 break;
00193 case 'E': case 'e':
00194 system = SatID::systemGalileo;
00195 break;
00196 case 'M': case 'm':
00197 system = SatID::systemMixed;
00198 break;
00199 case ' ': case 'G': case 'g':
00200 system = SatID::systemGPS;
00201 break;
00202 default:
00203 Exception e(std::string("Invalid system character \"")
00204 + c + std::string("\""));
00205 GPSTK_THROW(e);
00206 }
00207 iss >> id;
00208 if(id <= 0) id = -1;
00209 }
00210
00211
00213
00214 std::string toString() const
00215 throw()
00216 {
00217 std::ostringstream oss;
00218 oss.fill(fillchar);
00219 oss << systemChar() << std::setw(2) << id;
00220 return oss.str();
00221 }
00222
00223
00224 private:
00225
00226 static char fillchar;
00227
00228 };
00229
00231
00232 inline std::ostream& operator<<(std::ostream& s, const RinexSatID& sat)
00233 {
00234 s << sat.toString();
00235 return s;
00236 }
00237
00238 }
00239
00240 #endif