00001 #pragma ident "$Id: GSatID.hpp 1182 2008-04-04 14:07:43Z btolman $"
00002
00003
00004
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
00044 #ifndef CLASS_GEOMATIC_SATELLITE_ID_INCLUDE
00045 #define CLASS_GEOMATIC_SATELLITE_ID_INCLUDE
00046
00047 #include "Exception.hpp"
00048 #include "SatID.hpp"
00049
00050 namespace gpstk {
00051 class GSatID : public SatID
00052 {
00053 public:
00054
00056 GSatID() throw() { id=-1; system=systemGPS; }
00057
00059 GSatID(int p, SatelliteSystem s) throw()
00060 {
00061 id = p; system = s;
00062 switch(system) {
00063 case systemGPS:
00064 case systemGalileo:
00065 case systemGlonass:
00066 case systemGeosync:
00067 case systemLEO:
00068 case systemTransit: break;
00069 default:
00070 system = systemGPS;
00071 id = -1;
00072 }
00073 }
00074
00076 GSatID(std::string& str) throw(Exception)
00077 try { this->fromString(str); }
00078 catch(Exception& e) { GPSTK_RETHROW(e); }
00079
00081 GSatID(const SatID& sat) throw()
00082 { *this = GSatID(sat.id,sat.system); }
00083
00086 char setfill(char c) throw()
00087 { char csave=fillchar; fillchar=c; return csave; }
00088
00090 char getfill() throw()
00091 { return fillchar; }
00092
00093
00094
00096 char systemChar() const throw()
00097 {
00098 switch(system) {
00099 case systemGPS: return 'G';
00100 case systemGalileo: return 'E';
00101 case systemGlonass: return 'R';
00102 case systemGeosync: return 'S';
00103 case systemTransit: return 'T';
00104 case systemLEO: return 'L';
00105 default: return '?';
00106 }
00107 };
00108
00110 std::string systemString() const throw()
00111 {
00112 switch(system) {
00113 case systemGPS: return "GPS";
00114 case systemGalileo: return "Galileo";
00115 case systemGlonass: return "Glonass";
00116 case systemGeosync: return "Geosync";
00117 case systemTransit: return "Transit";
00118 case systemLEO: return "LEO";
00119 default: return "Unknown";
00120 }
00121 };
00122
00125 void fromString(const std::string s) throw(Exception)
00126 {
00127 char c;
00128 std::istringstream iss(s);
00129
00130 id = -1; system = systemGPS;
00131 if(s.find_first_not_of(std::string(" \t\n"), 0) == std::string::npos)
00132 return;
00133
00134 iss >> c;
00135 switch(c)
00136 {
00137
00138 case '0': case '1': case '2': case '3': case '4':
00139 case '5': case '6': case '7': case '8': case '9':
00140 iss.putback(c);
00141 system = SatID::systemGPS;
00142 break;
00143 case 'R': case 'r':
00144 system = SatID::systemGlonass;
00145 break;
00146 case 'T': case 't':
00147 system = SatID::systemTransit;
00148 break;
00149 case 'S': case 's':
00150 system = SatID::systemGeosync;
00151 break;
00152 case 'E': case 'e':
00153 system = SatID::systemGalileo;
00154 break;
00155 case 'L': case 'l':
00156 system = SatID::systemLEO;
00157 break;
00158 case ' ': case 'G': case 'g':
00159 system = SatID::systemGPS;
00160 break;
00161 default:
00162 Exception e(std::string("Invalid system character \"")
00163 + c + std::string("\""));
00164 GPSTK_THROW(e);
00165 }
00166 iss >> id;
00167 if(id <= 0) id = -1;
00168 }
00169
00171 std::string toString() const throw()
00172 {
00173 std::ostringstream oss;
00174 char savechar=oss.fill(fillchar);
00175 oss << systemChar()
00176 << std::setw(2) << id
00177 << std::setfill(savechar);
00178 return oss.str();
00179 }
00180
00181 private:
00182
00183 static char fillchar;
00184
00185 };
00186
00188 inline std::ostream& operator<<(std::ostream& s, const GSatID& sat) throw()
00189 {
00190 s << sat.toString();
00191 return s;
00192 }
00193
00194 }
00195
00196 #endif
00197