SourceID.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: SourceID.cpp 1889 2009-05-11 15:47:23Z afarris $"
00002 
00008 //============================================================================
00009 //
00010 //  This file is part of GPSTk, the GPS Toolkit.
00011 //
00012 //  The GPSTk is free software; you can redistribute it and/or modify
00013 //  it under the terms of the GNU Lesser General Public License as published
00014 //  by the Free Software Foundation; either version 2.1 of the License, or
00015 //  any later version.
00016 //
00017 //  The GPSTk is distributed in the hope that it will be useful,
00018 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //  GNU Lesser General Public License for more details.
00021 //
00022 //  You should have received a copy of the GNU Lesser General Public
00023 //  License along with GPSTk; if not, write to the Free Software Foundation,
00024 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 //
00026 //  Dagoberto Salazar - gAGE ( http://www.gage.es ). 2006, 2007, 2008
00027 //
00028 //============================================================================
00029 
00030 
00031 #include "SourceID.hpp"
00032 
00033 
00034 namespace gpstk
00035 {
00036 
00037    std::map< SourceID::SourceType, std::string > SourceID::stStrings;
00038 
00039 
00040    SourceID::Initializer SourceIDsingleton;
00041 
00042 
00043    SourceID::Initializer::Initializer()
00044    {
00045       stStrings[Unknown]   = "UnknownSource";
00046       stStrings[GPS]       = "GPS";
00047       stStrings[Galileo]   = "Galileo";
00048       stStrings[Glonass]   = "Glonass";
00049       stStrings[Geosync]   = "Geosync";
00050       stStrings[LEO]       = "LEO";
00051       stStrings[Transit]   = "Transit";
00052       stStrings[DGPS]      = "DGPS";
00053       stStrings[RTK]       = "RTK";
00054       stStrings[INS]       = "INS";
00055       stStrings[Mixed]     = "Mixed";
00056    }
00057 
00058 
00059 
00060       // Assignment operator
00061    SourceID& SourceID::operator=(const SourceID& right)
00062    {
00063 
00064       if ( this == &right )
00065       {
00066          return (*this);
00067       }
00068 
00069       type = right.type;
00070       sourceName = right.sourceName;
00071 
00072       return *this;
00073 
00074    }  // End of 'SourceID::operator=()'
00075 
00076 
00077 
00078       // Convenience output method
00079    std::ostream& SourceID::dump(std::ostream& s) const
00080    {
00081 
00082       s << SourceID::stStrings[type] << " "
00083         << sourceName;
00084 
00085       return s;
00086 
00087    }  // End of method 'SourceID::dump()'
00088 
00089 
00090 
00091       // Returns true if this is a valid SourceID. Basically just
00092       // checks that none of the fields are undefined.
00093    bool SourceID::isValid() const
00094    {
00095 
00096       return !(type==Unknown || sourceName=="");
00097 
00098    }  // End of method 'SourceID::isValid()'
00099 
00100 
00101 
00102       // Method to create a new source type.
00103    SourceID::SourceType SourceID::newSourceType(const std::string& s)
00104    {
00105 
00106       SourceType newId =
00107          static_cast<SourceType>(SourceID::stStrings.rbegin()->first + 1);
00108 
00109       SourceID::stStrings[newId] = s;
00110 
00111       return newId;
00112 
00113    }  // End of method 'SourceID::newSourceType()'
00114 
00115 
00116 
00117       // Equality operator requires all fields to be the same.
00118    bool SourceID::operator==(const SourceID& right) const
00119    {
00120 
00121       return (type==right.type && sourceName==right.sourceName);
00122 
00123    }  // End of 'SourceID::operator==()'
00124 
00125 
00126 
00127       // Ordering is arbitrary but required to be able to use a SourceID
00128       // as an index to a std::map. If an application needs
00129       // some other ordering, inherit and override this function.
00130    bool SourceID::operator<(const SourceID& right) const
00131    {
00132 
00133       if (type == right.type)
00134       {
00135          return sourceName < right.sourceName;
00136       }
00137       else
00138       {
00139          return type < right.type;
00140       }
00141 
00142    }  // End of 'SourceID::operator<()'
00143 
00144 
00145 
00146    namespace StringUtils
00147    {
00148 
00149          // convert this object to a string representation
00150       std::string asString(const SourceID& p)
00151       {
00152 
00153          std::ostringstream oss;
00154          p.dump(oss);
00155 
00156          return oss.str();
00157 
00158       }  // End of function 'asString()'
00159 
00160    }  // End of namespace StringUtils
00161 
00162 
00163 
00164       // Stream output for SourceID
00165    std::ostream& operator<<( std::ostream& s,
00166                              const SourceID& p )
00167    {
00168 
00169       p.dump(s);
00170 
00171       return s;
00172 
00173    }  // End of 'operator<<'
00174 
00175 
00176 }  // End of namespace gpstk

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