00001 #pragma ident "$Id: Namelist.hpp 1182 2008-04-04 14:07:43Z btolman $"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00046 #ifndef CLASS_NAMELIST_INCLUDE
00047 #define CLASS_NAMELIST_INCLUDE
00048
00049
00050
00051 #include <string>
00052 #include <vector>
00053 #include <algorithm>
00054 #include <iomanip>
00055 #include <ostream>
00056 #include <sstream>
00057
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;
00088 int rc;
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
00194
00196 inline unsigned int size(void) const { return labels.size(); }
00197
00198
00199
00200
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
00219
00221 std::vector<std::string> labels;
00222
00223
00224 };
00225
00226 }
00227
00228 #endif