root/bdm/userinfo.h @ 78

Revision 78, 4.0 kB (checked in by smidl, 16 years ago)

Prvni nastrel user-infa

  • Property svn:eol-style set to native
Line 
1//
2// C++ Interface: userinfo
3//
4// Description:
5//
6//
7// Author: smidl <smidl@utia.cas.cz>, (C) 2008
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#include <itpp/itbase.h>
13#include <itpp/base/mat.h>
14
15using std::cout;
16using std::endl;
17
18/*!
19@brief User Info base class
20
21This class is used to store information about parameters of an object. It support loading and saving of the information and, potentially, interaction with the user.
22*/
23class uibase {
24protected:
25        std::string comment;
26        std::string help;
27        uibase* parent;
28
29public:
30//!Default constructor
31        uibase ( std::string com = "Abstract class, please ignore!") :comment ( com ) {parent=NULL;}
32//!Default constructor
33        uibase ( std::string com,uibase *par ) :comment ( com ),parent ( par ) {}
34
35//! returns a summary of its contents (used in dialogs)
36        virtual void getsummary ( std::string &S ) {};
37
38//! interaction with the user
39        virtual void askuser(){};
40
41//! test if the info is valid
42        virtual bool isvalid() {return true;}
43        //! for future use
44        virtual ~uibase(){};
45};
46
47//! User info for scalars
48template<class T>
49class uiscalar : public uibase {
50protected:
51        T N;
52public:
53//!Default constructor
54        uiscalar ( std::string com,uibase* par ) :uibase ( com,par ) {N=T ( 0 );};
55        uiscalar ( std::string com) :uibase ( com ) {N=T ( 0 );};
56
57        void getsummary ( std::string &S ) {S="Scalar";};
58
59        void askuser (){};
60
61//! saving the info
62template<class T2>
63        friend std::ostream &operator<< ( std::ostream &os, const uiscalar<T2> &ui );
64
65//! saving the info
66template<class T2>
67        friend std::istream &operator>> ( std::istream &is, const uiscalar<T2> &ui );
68        ~uiscalar(){};
69};
70
71//! User info for strings
72class uistring : public uibase {
73protected:
74        std::string S;
75public:
76        void getsummary ( std::string &S ) {S="String";};
77
78//!Default constructor
79        uistring ( std::string com ) :uibase ( com ) {}
80       
81        void askuser (){};
82//! saving the info
83        friend std::ostream &operator<< ( std::ostream &os, const uistring &ui );
84
85//! saving the info
86        friend std::istream &operator>> ( std::istream &is, const uistring &ui );
87
88        ~uistring(){};
89};
90
91//! User info for vectors
92template<class T>
93class uivector : public uibase {
94protected:     
95        itpp::Vec<T> V;
96public:
97        void getsummary ( std::string &S ) { S="Vector of length "+ V.length();};
98
99//!Default constructor
100        uivector ( std::string com ) :uibase ( com ) {};
101
102        void askuser (){};
103        //! saving the info
104template<class T2>
105        friend std::ostream &operator<< ( std::ostream &os, const uivector<T2> &ui );
106
107//! saving the info
108template<class T2>
109        friend std::istream &operator>> ( std::istream &is, const uivector<T2> &ui );
110
111};
112
113//! User info for matrices
114template<class T>
115class uimatrix : public uibase {
116        itpp::Mat<T> M;
117       
118        //!Default constructor
119        uimatrix ( std::string com ) :uibase ( com ) {}
120
121        void getsummary ( std::string &S ) {sprintf ( S,"Matrix %dx%d",M.rows(),M.cols() );};
122
123        void askuser (){};
124//! saving the info
125template<class T2>
126        friend std::ostream &operator<< ( std::ostream &os, const uimatrix<T2> &ui );
127
128//! saving the info
129template<class T2>
130        friend std::istream &operator>> ( std::istream &is, const uimatrix<T2> &ui );
131
132};
133
134//!Compound user info
135class uicompound: public uibase {
136protected:
137        uibase** elems;
138public:
139//!Default constructor
140        uicompound ( const int n0 ) : elems(new uibase*[n0]) {};
141        ~uicompound(){delete elems;}
142};
143
144typedef uimatrix<double> uimat;
145typedef uimatrix<int> uiimat;
146
147typedef uivector<double> uivec;
148typedef uivector<int> uiivec;
149
150
151template<class T>
152std::istream &operator>> ( std::istream &is, const uiscalar<T> &ui ) {is>>ui.N;return is;};
153template<class T>
154std::ostream &operator<< ( std::ostream &os, const uiscalar<T> &ui ) {os<<ui.N;return os;};
155
156template<class T>
157std::istream &operator>> ( std::istream &is, const uivector<T> &ui ) {is>>ui.V;return is;};
158
159template<class T>
160std::ostream &operator<< ( std::ostream &os, const uivector<T> &ui ) {os<<ui.V; return os;};
161
162template<class T>
163std::istream &operator>> ( std::istream &is, const uimatrix<T> &ui ) {is>>ui.M;return is;};
164
165template<class T>
166std::ostream &operator<< ( std::ostream &os, const uimatrix<T> &ui ) {os<<ui.M;return os;};
Note: See TracBrowser for help on using the browser.