RinexSatID.hpp

Go to the documentation of this file.
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 //  This file is part of GPSTk, the GPS Toolkit.
00009 //
00010 //  The GPSTk is free software; you can redistribute it and/or modify
00011 //  it under the terms of the GNU Lesser General Public License as published
00012 //  by the Free Software Foundation; either version 2.1 of the License, or
00013 //  any later version.
00014 //
00015 //  The GPSTk is distributed in the hope that it will be useful,
00016 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 //  GNU Lesser General Public License for more details.
00019 //
00020 //  You should have received a copy of the GNU Lesser General Public
00021 //  License along with GPSTk; if not, write to the Free Software Foundation,
00022 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 //  
00024 //  Copyright 2004, The University of Texas at Austin
00025 //
00026 //============================================================================
00027 
00028 //============================================================================
00029 //
00030 // This software developed by Applied Research Laboratories at the University
00031 // of Texas at Austin, under contract to an agency or agencies within the U.S. 
00032 // Department of Defense. The U.S. Government retains all rights to use,
00033 // duplicate, distribute, disclose, or release this software. 
00034 //
00035 // Pursuant to DoD Directive 523024 
00036 //
00037 // DISTRIBUTION STATEMENT A: This software has been approved for public 
00038 //                           release, distribution is unlimited.
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             // Invalidate anything non-RINEX.
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       // operator=, copy constructor and destructor built by compiler
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;  // default
00172          if(s.find_first_not_of(std::string(" \t\n"), 0) == std::string::npos)
00173             return;                    // all whitespace yields the default
00174 
00175          iss >> c;                     // read one character (non-whitespace)
00176          switch(c)
00177          {
00178                                        // no leading system character
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:                   // non-RINEX system character
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    }; // class RinexSatID
00229 
00231 
00232    inline std::ostream& operator<<(std::ostream& s, const RinexSatID& sat)
00233    {
00234       s << sat.toString();
00235       return s;
00236    }
00237 
00238 } // namespace gpstk
00239 
00240 #endif

Generated on Tue May 22 03:31:01 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1