Namelist.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: Namelist.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 
00046 #ifndef CLASS_NAMELIST_INCLUDE
00047 #define CLASS_NAMELIST_INCLUDE
00048 
00049 //------------------------------------------------------------------------------------
00050 // system includes
00051 #include <string>
00052 #include <vector>
00053 #include <algorithm>
00054 #include <iomanip>
00055 #include <ostream>
00056 #include <sstream>
00057 // GPSTk
00058 #include "Matrix.hpp"
00059 
00060 namespace gpstk
00061 {
00062 
00063 //------------------------------------------------------------------------------------
00064 class Namelist;
00066 class LabelledVector {
00067 public:
00068    int wid,prec,form;
00069    std::string msg;
00070    std::string tag;
00071    const Namelist& NL;
00072    Vector<double>& V;
00073    LabelledVector(const Namelist& nl, Vector<double>& v)
00074       : wid(12), prec(5), form(1), NL(nl), V(v) { }
00075    LabelledVector& setw(int w) { wid = w; return *this; }
00076    LabelledVector& setprecision(int p) { prec = p; return *this; }
00077    LabelledVector& fixed(void) { form = 1; return *this; }
00078    LabelledVector& scientific(void) { form = 2; return *this; }
00079    LabelledVector& message(const std::string& m) { msg=m; return *this; }
00080    LabelledVector& linetag(const std::string& m) { tag=m; return *this; }
00081 };
00082 
00084 class LabelledMatrix {
00085 public:
00086    int wid,prec;
00087    int form;         // format: 1=fixed, 2=scientific
00088    int rc;           // rows only (1) columns only (2) or both (0)
00089    std::string msg;
00090    std::string tag;
00091    const Namelist& NLrows;
00092    const Namelist& NLcols;
00093    const Matrix<double>& M;
00094    LabelledMatrix(const Namelist& nl, const Matrix<double>& m)
00095       : wid(12), prec(5), form(1), rc(0), NLrows(nl), NLcols(nl), M(m) { }
00096    LabelledMatrix(const Namelist& nlr, const Namelist& nlc, const Matrix<double>& m)
00097       : wid(12), prec(5), form(1), rc(0), NLrows(nlr), NLcols(nlc), M(m) { }
00098    LabelledMatrix& setw(int w) { wid = w; return *this; }
00099    LabelledMatrix& setprecision(int p) { prec = p; return *this; }
00100    LabelledMatrix& fixed(void) { form = 1; return *this; }
00101    LabelledMatrix& scientific(void) { form = 2; return *this; }
00102    LabelledMatrix& both(void) { rc=0; return *this; }
00103    LabelledMatrix& rows(void) { rc=1; return *this; }
00104    LabelledMatrix& cols(void) { rc=2; return *this; }
00105    LabelledMatrix& message(const std::string& m) { msg=m; return *this; }
00106    LabelledMatrix& linetag(const std::string& m) { tag=m; return *this; }
00107 };
00108 
00109 std::ostream& operator<<(std::ostream&, const LabelledMatrix&);
00110 std::ostream& operator<<(std::ostream&, const LabelledVector&);
00111 
00112 
00113 //------------------------------------------------------------------------------------
00122 class Namelist {
00123    friend class SRI;
00124    friend std::ostream& operator<<(std::ostream&, const LabelledMatrix&);
00125    friend std::ostream& operator<<(std::ostream&, const LabelledVector&);
00126 public:
00128    Namelist(void) {}
00130    Namelist(const unsigned int&);
00132    Namelist(const std::vector<std::string>&);
00134    Namelist(const Namelist& names) { labels = names.labels; }
00136    ~Namelist(void) { labels.clear(); }
00137 
00139    Namelist& operator=(const Namelist& right)
00140       { labels = right.labels; return *this; }
00142    Namelist& operator+=(const std::string&);
00144    Namelist& operator-=(const std::string&);
00145 
00148    void swap(const unsigned int&, const unsigned int&);
00150    void sort(void);
00152    void resize(unsigned int);
00154    void randomize(long seed=0);
00156    void clear(void) { labels.clear(); }
00157 
00160    bool valid(void) const;
00162    bool contains(const std::string&) const;
00164    friend bool operator==(const Namelist&, const Namelist&);
00166    friend bool operator!=(const Namelist&, const Namelist&);
00168    friend bool identical(const Namelist&, const Namelist&);
00169 
00171    friend Namelist operator&(const Namelist&, const Namelist&);
00173    friend Namelist operator|(const Namelist&, const Namelist&);
00175    friend Namelist operator^(const Namelist&, const Namelist&);
00177    Namelist& operator&=(const Namelist&);
00179    Namelist& operator|=(const Namelist&);
00181    Namelist& operator^=(const Namelist&);
00182 
00185    LabelledMatrix operator()(Matrix<double>& m)
00186       { return LabelledMatrix(*this,m); }
00187 
00190    LabelledVector operator()(Vector<double>& v)
00191       { return LabelledVector(*this,v); }
00192 
00193       // member access
00194 
00196    inline unsigned int size(void) const { return labels.size(); }
00197 
00198    //std::string& operator[](const unsigned int);
00199    //Don't do this, b/c it means user could create invalid Namelists,
00200    //and b/c passing an invalid int would require a throw
00201 
00204    std::string getName(const unsigned int) const;
00205 
00209    bool setName(const unsigned int, const std::string&);
00210 
00213    int index(const std::string&) const;
00214 
00216    friend std::ostream& operator<<(std::ostream& s, const Namelist&);
00217 
00218    // member data
00219 
00221    std::vector<std::string> labels;
00222 
00223 //private:
00224 }; // end class Namelist
00225 
00226 } // end of namespace gpstk
00227 
00228 #endif

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