GSatID.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: GSatID.hpp 1182 2008-04-04 14:07:43Z btolman $"
00002 
00003 //============================================================================
00004 //
00005 //  This file is part of GPSTk, the GPS Toolkit.
00006 //
00007 //  The GPSTk is free software; you can redistribute it and/or modify
00008 //  it under the terms of the GNU Lesser General Public License as published
00009 //  by the Free Software Foundation; either version 2.1 of the License, or
00010 //  any later version.
00011 //
00012 //  The GPSTk is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU Lesser General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU Lesser General Public
00018 //  License along with GPSTk; if not, write to the Free Software Foundation,
00019 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //  
00021 //  Copyright 2004, The University of Texas at Austin
00022 //
00023 //============================================================================
00024 
00025 //============================================================================
00026 //
00027 //This software developed by Applied Research Laboratories at the University of
00028 //Texas at Austin, under contract to an agency or agencies within the U.S. 
00029 //Department of Defense. The U.S. Government retains all rights to use,
00030 //duplicate, distribute, disclose, or release this software. 
00031 //
00032 //Pursuant to DoD Directive 523024 
00033 //
00034 // DISTRIBUTION STATEMENT A: This software has been approved for public 
00035 //                           release, distribution is unlimited.
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       // operator=, copy constructor and destructor built by compiler
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;  // default
00131          if(s.find_first_not_of(std::string(" \t\n"), 0) == std::string::npos)
00132             return;                    // all whitespace yields the default
00133 
00134          iss >> c;                     // read one character (non-whitespace)
00135          switch(c)
00136          {
00137                                        // no leading system character
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:                   // invalid system character
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    }; // class GSatID
00186 
00188    inline std::ostream& operator<<(std::ostream& s, const GSatID& sat) throw()
00189    {
00190       s << sat.toString();
00191       return s;
00192    }
00193 
00194 } // namespace gpstk
00195 
00196 #endif
00197 // nothing below this

Generated on Wed Feb 8 03:31:00 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1