00001 #pragma ident "$Id: SP3SatID.hpp 1161 2008-03-27 17:16:22Z ckiesch $"
00002
00003 #ifndef GPSTK_SP3_SATID_HPP
00004 #define GPSTK_SP3_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 SP3SatID : public SatID
00058 {
00059 public:
00060
00062 SP3SatID() throw() { id=-1; system=systemGPS; }
00063
00065 SP3SatID(int p, SatelliteSystem s) throw()
00066 {
00067 id = p; system = s;
00068 switch(system) {
00069 case systemGPS:
00070 case systemGlonass:
00071 case systemGalileo:
00072 case systemLEO: break;
00073
00074 default:
00075 system = systemUnknown;
00076 id = -1;
00077 }
00078 }
00079
00081 SP3SatID(const std::string& str) throw(Exception)
00082 {
00083 try { fromString(str); }
00084 catch(Exception& e) { GPSTK_RETHROW(e); }
00085 }
00086
00088 SP3SatID(const SatID& sat) throw()
00089 { *this = SP3SatID(sat.id,sat.system); }
00090
00093 char setfill(char c) throw()
00094 { char csave=fillchar; fillchar=c; return csave; }
00095
00097 char getfill() throw()
00098 { return fillchar; }
00099
00100
00101
00105 char systemChar() const throw()
00106 {
00107 switch (system) {
00108 case systemGPS: return 'G';
00109 case systemGalileo: return 'E';
00110 case systemGlonass: return 'R';
00111 case systemLEO: return 'L';
00112 case systemMixed: return 'M';
00113
00114 default: return '?';
00115 }
00116 };
00117
00118 std::string systemString() const throw()
00119 {
00120 switch (system) {
00121 case systemGPS: return "GPS";
00122 case systemGalileo: return "Galileo";
00123 case systemGlonass: return "Glonass";
00124 case systemLEO: return "LEO";
00125 case systemMixed: return "Mixed";
00126 default: return "Unknown";
00127 }
00128 };
00129
00130
00133 void fromString(const std::string s) throw(Exception)
00134 {
00135 char c;
00136 std::istringstream iss(s);
00137
00138 id = -1; system = systemGPS;
00139 if(s.find_first_not_of(std::string(" \t\n"), 0) == std::string::npos)
00140 return;
00141
00142 iss >> c;
00143 switch(c)
00144 {
00145
00146 case '0': case '1': case '2': case '3': case '4':
00147 case '5': case '6': case '7': case '8': case '9':
00148 iss.putback(c);
00149 system = SatID::systemGPS;
00150 break;
00151 case ' ': case 'G': case 'g':
00152 system = SatID::systemGPS;
00153 break;
00154 case 'R': case 'r':
00155 system = SatID::systemGlonass;
00156 break;
00157 case 'E': case 'e':
00158 system = SatID::systemGalileo;
00159 break;
00160 case 'L': case 'l':
00161 system = SatID::systemLEO;
00162 break;
00163 case 'M': case 'm':
00164 system = SatID::systemMixed;
00165 break;
00166 default:
00167 Exception e(std::string("Invalid system character \"")
00168 + c + std::string("\""));
00169 GPSTK_THROW(e);
00170 }
00171 iss >> id;
00172 if(id <= 0) id = -1;
00173 }
00174
00176 std::string toString() const throw()
00177 {
00178 std::ostringstream oss;
00179 oss.fill(fillchar);
00180 oss << systemChar()
00181 << std::setw(2) << id;
00182 return oss.str();
00183 }
00184
00185 private:
00186
00187 static char fillchar;
00188
00189 };
00190
00192 inline std::ostream& operator<<(std::ostream& s, const SP3SatID& sat)
00193 {
00194 s << sat.toString();
00195 return s;
00196 }
00197
00198 }
00199
00200 #endif