DDid.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: DDid.cpp 3140 2012-06-18 15:03:02Z susancummins $"
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110, 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 
00045 //------------------------------------------------------------------------------------
00046 // system includes
00047 #include "DDid.hpp"
00048 
00049 //------------------------------------------------------------------------------------
00050 using namespace gpstk;
00051 using namespace std;
00052 
00053 namespace gpstk {
00054 //------------------------------------------------------------------------------------
00055 // empty constructor - sites are empty and sats are GPS,-1
00056 //DDid::DDid(void)
00057 //{
00058 //   site1 = site2 = string("");
00059 //   sat1 = sat2 = GSatID(-1,systemGPS);
00060 //   ssat = ssite = 1;
00061 //}
00062 
00063 //------------------------------------------------------------------------------------
00064 // explicit constructor - may reorder input to standard form
00065 DDid::DDid(string s1, string s2, GSatID p1, GSatID p2)
00066 {
00067    if(s1 == s2 || p1.id == p2.id || p1.system != p2.system) {
00068       Exception e("DDid constructor with identical parts");
00069       GPSTK_THROW(e);
00070    }
00071    if(s1 < s2) ssite=1; else ssite=-1;
00072    site1 = (s1 < s2 ? s1 : s2);
00073    site2 = (s1 < s2 ? s2 : s1);
00074 
00075    if(p1.id < p2.id) ssat=1; else ssat=-1;
00076    sat1 = (p1.id < p2.id ? p1 : p2);
00077    sat2 = (p1.id < p2.id ? p2 : p1);
00078 }
00079 
00080 //------------------------------------------------------------------------------------
00081 // return 0 if either is invalid
00082 // return +1 if the same, -1 if the same except for one switch
00083 // return +2 if left is greater than right
00084 // return -2 if left is less than right
00085 int DDid::compare(const DDid& left, const DDid& right)
00086 {
00087    if(left.site1 == left.site2 || left.sat1 == left.sat2 ||
00088       right.site1 == right.site2 || right.sat1 == right.sat2) return 0;
00089    if(left.site1 < right.site1) return -2;
00090    if(left.site1 > right.site1) return  2;
00091    if(left.site2 < right.site2) return -2;
00092    if(left.site2 > right.site2) return  2;
00093    if(left.sat1.id < right.sat1.id) return -2;
00094    if(left.sat1.id > right.sat1.id) return  2;
00095    if(left.sat2.id < right.sat2.id) return -2;
00096    if(left.sat2.id > right.sat2.id) return  2;
00097    return left.ssite*right.ssite*left.ssat*right.ssat;
00098 }
00099 
00100 //------------------------------------------------------------------------------------
00101 bool DDid::operator>(const DDid& that) const
00102 {
00103    return (DDid::compare(*this,that) == 2);
00104 }
00105 
00106 //------------------------------------------------------------------------------------
00107 bool DDid::operator==(const DDid& that) const
00108 {
00109    return (abs(DDid::compare(*this,that)) == 1);
00110 }
00111 
00112 //------------------------------------------------------------------------------------
00113 bool DDid::operator!=(const DDid& that) const
00114 {
00115    return (abs(DDid::compare(*this,that)) != 1);
00116 }
00117 
00118 //------------------------------------------------------------------------------------
00119 bool DDid::operator<(const DDid &that) const
00120 {
00121    return (DDid::compare(*this,that) == -2);
00122 }
00123 
00124 //------------------------------------------------------------------------------------
00125 ostream& operator<<(ostream& s, const DDid& t)
00126 {
00127    if(t.ssite > 0) s << t.site1 << " " << t.site2 << " ";
00128    else            s << t.site2 << " " << t.site1 << " ";
00129    if(t.ssat  > 0) s << t.sat1 << " " << t.sat2;
00130    else            s << t.sat2 << " " << t.sat1;
00131    return s;
00132 }
00133 
00134 //------------------------------------------------------------------------------------
00135 //------------------------------------------------------------------------------------
00136 // empty constructor - sites are empty and sats are GPS,-1
00137 //SDid::SDid(void)
00138 //{
00139 //   site1 = site2 = string("");
00140 //   sat = GSatID(-1,systemGPS);
00141 //   ssite = 1;
00142 //}
00143 
00144 //------------------------------------------------------------------------------------
00145 // explicit constructor - may reorder input to standard form
00146 SDid::SDid(string s1, string s2, GSatID p)
00147 {
00148    if(s1 == s2) {
00149       Exception e("SDid constructor with identical sites");
00150       GPSTK_THROW(e);
00151    }
00152    if(s1 < s2) ssite=1; else ssite=-1;
00153    site1 = (s1 < s2 ? s1 : s2);
00154    site2 = (s1 < s2 ? s2 : s1);
00155    sat = p;
00156 }
00157 
00158 //------------------------------------------------------------------------------------
00159 // return 0 if either is invalid
00160 // return +1 if the same, -1 if the same except for one switch
00161 // return +2 if left is greater than right
00162 // return -2 if left is less than right
00163 int SDid::compare(const SDid& left, const SDid& right)
00164 {
00165    if(left.site1 == left.site2 || right.site1 == right.site2) return 0;
00166    if(left.site1 < right.site1) return -2;
00167    if(left.site1 > right.site1) return  2;
00168    if(left.site2 < right.site2) return -2;
00169    if(left.site2 > right.site2) return  2;
00170    if(left.sat.id < right.sat.id) return -2;
00171    if(left.sat.id > right.sat.id) return  2;
00172    return left.ssite*right.ssite;
00173 }
00174 
00175 //------------------------------------------------------------------------------------
00176 bool SDid::operator>(const SDid& that) const
00177 {
00178    return (SDid::compare(*this,that) == 2);
00179 }
00180 
00181 //------------------------------------------------------------------------------------
00182 bool SDid::operator==(const SDid& that) const
00183 {
00184    return (abs(SDid::compare(*this,that)) == 1);
00185 }
00186 
00187 //------------------------------------------------------------------------------------
00188 bool SDid::operator<(const SDid &that) const
00189 {
00190    return (SDid::compare(*this,that) == -2);
00191 }
00192 
00193 //------------------------------------------------------------------------------------
00194 ostream& operator<<(ostream& s, const SDid& t)
00195 {
00196    if(t.ssite > 0) s << t.site1 << " " << t.site2 << " " << t.sat;
00197    else            s << t.site2 << " " << t.site1 << " " << t.sat;
00198    return s;
00199 }
00200 
00201 //------------------------------------------------------------------------------------
00202 //------------------------------------------------------------------------------------
00203 // empty constructor - sites are empty and sats are GPS,-1
00204 //OWid::OWid(void)
00205 //{
00206 //   site = string("");
00207 //   sat = GSatID(-1,systemGPS);
00208 //}
00209 
00210 //------------------------------------------------------------------------------------
00211 // explicit constructor - may reorder input to standard form
00212 OWid::OWid(string& s, GSatID& p)
00213 {
00214    site = s;
00215    sat = p;
00216 }
00217 
00218 //------------------------------------------------------------------------------------
00219 // return 0 if either is invalid
00220 // return +1 if the same, -1 if the same except for one switch
00221 // return +2 if left is greater than right
00222 // return -2 if left is less than right
00223 int OWid::compare(const OWid& left, const OWid& right)
00224 {
00225    int isit=0;
00226    if(     left.site == right.site) isit=1;
00227    else if(left.site < right.site) return -2;
00228    else if(left.site > right.site) return 2;
00229    int isat=0;
00230    if(     left.sat.id == right.sat.id) isat=1;
00231    else if(left.sat.id < right.sat.id) return -2;
00232    else if(left.sat.id > right.sat.id) return 2;
00233 
00234    return isit*isat;
00235 }
00236 
00237 //------------------------------------------------------------------------------------
00238 bool OWid::operator>(const OWid& that) const
00239 {
00240    return (OWid::compare(*this,that) == 2);
00241 }
00242 
00243 //------------------------------------------------------------------------------------
00244 bool OWid::operator==(const OWid& that) const
00245 {
00246    return (abs(OWid::compare(*this,that)) == 1);
00247 }
00248 
00249 //------------------------------------------------------------------------------------
00250 bool OWid::operator<(const OWid &that) const
00251 {
00252    return (OWid::compare(*this,that) == -2);
00253 }
00254 
00255 //------------------------------------------------------------------------------------
00256 ostream& operator<<(ostream& s, const OWid& t)
00257 {
00258    s << t.site << " " << t.sat;
00259    return s;
00260 }
00261 
00262 } // end namespace gpstk
00263 //------------------------------------------------------------------------------------
00264 //------------------------------------------------------------------------------------

Generated on Sat May 18 03:31:03 2013 for GPS ToolKit Software Library by  doxygen 1.3.9.1