00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <itpp/itbase.h>
00013 #include <itpp/base/mat.h>
00014
00015 using std::cout;
00016 using std::endl;
00017 using std::string;
00018
00024 class uibase {
00025 protected:
00027 string name;
00029 string help;
00031 uibase* parent;
00033 int ilevel;
00034 public:
00036 uibase ( string com = "Abstract class, please ignore!", uibase* par=NULL ) :name ( com ),help ( "" ),parent ( par ) {
00037 if ( parent!=NULL ) {ilevel=parent->get_level() +1;}
00038 else {ilevel =0;}
00039 }
00040
00042 virtual void getsummary ( std::string &S ) {};
00043
00045 virtual void askuser() {};
00046
00048 virtual bool isvalid() {return true;}
00050 virtual ~uibase() {};
00052 virtual void save ( std::ostream &os ) {
00053 os.width(ilevel);
00054 os.fill(' ');
00055 os<<"#"<<help<<endl;
00056 os.width(ilevel);
00057 os.fill(' ');
00058 os<<name<<" = ";
00059 };
00061 virtual void load ( std::istream &is ) {
00062 char tmp[200];
00063 is.ignore ( ilevel+1,'#' );
00064 is.getline ( tmp,200 );help=tmp;
00065 is.ignore ( ilevel,'\0' );
00066 is.getline ( tmp,200,'=' ); name=tmp;
00067 };
00068
00070 int get_level(){return ilevel;}
00071 };
00072
00074 template<class T>
00075 class uiscalar : public uibase {
00076 protected:
00078 T N;
00079 public:
00081 uiscalar ( std::string com, uibase* par =NULL) :uibase ( com,par ) {N=T ( 0 );};
00082
00083 void getsummary ( std::string &S ) {S="Scalar";};
00084
00085 void askuser () {};
00086
00087 void save ( std::ostream &os ) {uibase::save ( os );os<<N<<endl;}
00088 void load ( std::istream &is ) {uibase::load ( is );is>>N;}
00090 ~uiscalar() {};
00091
00093 void set_value ( T N0 ) {N=N0;}
00094 };
00095
00097 class uistring : public uibase {
00098 protected:
00100 std::string S;
00101 public:
00102 void getsummary ( std::string &S ) {S="String";};
00103
00105 uistring ( std::string com , uibase* par=NULL) :uibase ( com,par ) {}
00106
00107 void askuser () {};
00108
00109 void save ( std::ostream &os ) {uibase::save ( os );os<<S<<endl;}
00110 void load ( std::istream &is ) {uibase::load ( is );is>>S;}
00111
00112 ~uistring() {};
00114 void set_value ( std::string S0 ) {S=S0;}
00115 };
00116
00118 template<class T>
00119 class uivector : public uibase {
00120 protected:
00122 itpp::Vec<T> V;
00123 public:
00124 void getsummary ( std::string &S ) { S="Vector of length "+ V.length();};
00125
00127 uivector ( std::string com, uibase* par=NULL ) :uibase ( com,par ) {};
00128
00129 void askuser () {};
00130
00131 void save ( std::ostream &os ) {uibase::save ( os );os<<V<<endl;;}
00132 void load ( std::istream &is ) {uibase::load ( is );is>>V;}
00133
00135 void set_value ( itpp::Vec<T> V0 ) {V=V0;}
00136
00137 };
00138
00140 template<class T>
00141 class uimatrix : public uibase {
00142 protected:
00144 itpp::Mat<T> M;
00145
00146 public:
00148 uimatrix ( std::string com, uibase* par=NULL ) :uibase ( com,par ) {}
00149
00150 void getsummary ( std::string &S ) { S="Matrix ";};
00151
00152 void askuser () {};
00153
00154 void save ( std::ostream &os ) {uibase::save ( os );os<<M<<endl;}
00155 void load ( std::istream &is ) {uibase::load ( is );is>>M;}
00156
00158 void set_value ( itpp::Mat<T> M0 ) {M=M0;}
00159 };
00160
00161
00162 typedef uimatrix<double> uimat;
00163 typedef uimatrix<int> uiimat;
00164
00165 typedef uivector<double> uivec;
00166 typedef uivector<int> uiivec;
00167