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
00023 class uibase {
00024 protected:
00025 std::string comment;
00026 std::string help;
00027 uibase* parent;
00028
00029 public:
00031 uibase ( std::string com = "Abstract class, please ignore!") :comment ( com ) {parent=NULL;}
00033 uibase ( std::string com,uibase *par ) :comment ( com ),parent ( par ) {}
00034
00036 virtual void getsummary ( std::string &S ) {};
00037
00039 virtual void askuser(){};
00040
00042 virtual bool isvalid() {return true;}
00044 virtual ~uibase(){};
00045 };
00046
00048 template<class T>
00049 class uiscalar : public uibase {
00050 protected:
00051 T N;
00052 public:
00054 uiscalar ( std::string com,uibase* par ) :uibase ( com,par ) {N=T ( 0 );};
00055 uiscalar ( std::string com) :uibase ( com ) {N=T ( 0 );};
00056
00057 void getsummary ( std::string &S ) {S="Scalar";};
00058
00059 void askuser (){};
00060
00062 template<class T2>
00063 friend std::ostream &operator<< ( std::ostream &os, const uiscalar<T2> &ui );
00064
00066 template<class T2>
00067 friend std::istream &operator>> ( std::istream &is, const uiscalar<T2> &ui );
00068 ~uiscalar(){};
00069 };
00070
00072 class uistring : public uibase {
00073 protected:
00074 std::string S;
00075 public:
00076 void getsummary ( std::string &S ) {S="String";};
00077
00079 uistring ( std::string com ) :uibase ( com ) {}
00080
00081 void askuser (){};
00083 friend std::ostream &operator<< ( std::ostream &os, const uistring &ui );
00084
00086 friend std::istream &operator>> ( std::istream &is, const uistring &ui );
00087
00088 ~uistring(){};
00089 };
00090
00092 template<class T>
00093 class uivector : public uibase {
00094 protected:
00095 itpp::Vec<T> V;
00096 public:
00097 void getsummary ( std::string &S ) { S="Vector of length "+ V.length();};
00098
00100 uivector ( std::string com ) :uibase ( com ) {};
00101
00102 void askuser (){};
00104 template<class T2>
00105 friend std::ostream &operator<< ( std::ostream &os, const uivector<T2> &ui );
00106
00108 template<class T2>
00109 friend std::istream &operator>> ( std::istream &is, const uivector<T2> &ui );
00110
00111 };
00112
00114 template<class T>
00115 class uimatrix : public uibase {
00116 itpp::Mat<T> M;
00117
00119 uimatrix ( std::string com ) :uibase ( com ) {}
00120
00121 void getsummary ( std::string &S ) {sprintf ( S,"Matrix %dx%d",M.rows(),M.cols() );};
00122
00123 void askuser (){};
00125 template<class T2>
00126 friend std::ostream &operator<< ( std::ostream &os, const uimatrix<T2> &ui );
00127
00129 template<class T2>
00130 friend std::istream &operator>> ( std::istream &is, const uimatrix<T2> &ui );
00131
00132 };
00133
00135 class uicompound: public uibase {
00136 protected:
00137 uibase** elems;
00138 public:
00140 uicompound ( const int n0 ) : elems(new uibase*[n0]) {};
00141 ~uicompound(){delete elems;}
00142 };
00143
00144 typedef uimatrix<double> uimat;
00145 typedef uimatrix<int> uiimat;
00146
00147 typedef uivector<double> uivec;
00148 typedef uivector<int> uiivec;
00149
00150
00151 template<class T>
00152 std::istream &operator>> ( std::istream &is, const uiscalar<T> &ui ) {is>>ui.N;return is;};
00153 template<class T>
00154 std::ostream &operator<< ( std::ostream &os, const uiscalar<T> &ui ) {os<<ui.N;return os;};
00155
00156 template<class T>
00157 std::istream &operator>> ( std::istream &is, const uivector<T> &ui ) {is>>ui.V;return is;};
00158
00159 template<class T>
00160 std::ostream &operator<< ( std::ostream &os, const uivector<T> &ui ) {os<<ui.V; return os;};
00161
00162 template<class T>
00163 std::istream &operator>> ( std::istream &is, const uimatrix<T> &ui ) {is>>ui.M;return is;};
00164
00165 template<class T>
00166 std::ostream &operator<< ( std::ostream &os, const uimatrix<T> &ui ) {os<<ui.M;return os;};
00167