SP3SatID.hpp

Go to the documentation of this file.
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 //  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 of
00031 //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 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             // invalidate anything non-SP3
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       // operator=, copy constructor and destructor built by compiler
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             // non-SP3
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;  // default
00139          if(s.find_first_not_of(std::string(" \t\n"), 0) == std::string::npos)
00140             return;                    // all whitespace yields the default
00141 
00142          iss >> c;                     // read one character (non-whitespace)
00143          switch(c)
00144          {
00145                                        // no leading system character
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:                   // non-SP3 system character
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    }; // class SP3SatID
00190 
00192    inline std::ostream& operator<<(std::ostream& s, const SP3SatID& sat)
00193    {
00194       s << sat.toString();
00195       return s;
00196    }
00197 
00198 } // namespace gpstk
00199 
00200 #endif

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