Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

/magnus/back_end/SessionManager/include/ViewContents.h

Go to the documentation of this file.
00001 /*
00002  *   $Id: ViewContents.h,v 1.4 2000/09/21 21:17:41 alex Exp $
00003  */
00004 
00005 // Copyright (C) 1997 The New York Group Theory Cooperative
00006 // See magnus/doc/COPYRIGHT for the full notice.
00007 
00008 // Contents: 
00009 //           
00010 //
00011 // Principal Author: Alexei Myasnikov
00012 //
00013 // Status: in progress
00014 //
00015 // Revision History:
00016 //
00017 
00018 #ifndef _VIEWCONTENTS_H_
00019 #define _VIEWCONTENTS_H_
00020 
00021 
00022 #include "global.h"
00023 #include "values.h"
00024 #include "Chars.h"
00025 #include "Word.h"
00026 #include "iostream.h"
00027 #include "ARCSlotID.h"
00028 #include "FreeGroup.h"
00029 #include "OID.h"
00030 #include "FEData.h"
00031 
00032 class PValue
00033 {
00034 public:
00035   PValue(int p): ivalue(p), theType(INT) { }
00036   PValue(Chars p): cvalue(p), theType(CHARS) { }
00037   PValue(Word p): wvalue(p), theType(WORD) { }
00038   PValue(const PValue& p): 
00039     ivalue(p.ivalue),
00040     cvalue(p.cvalue),
00041     wvalue(p.wvalue),
00042     theType(p.theType) { }
00043   
00044   operator int( ) { 
00045     if ( theType != INT )
00046       error("PValue::operator int( ): value is not integer");
00047     return ivalue;
00048   }
00049   operator Chars( ) { 
00050     if ( theType != CHARS )
00051       error("PValue::operator Chars( ): value is not Chars");
00052     return cvalue;
00053   }
00054   operator Word( ) { 
00055     if ( theType != WORD )
00056       error("PValue::operator Word( ): value is not Word");
00057     return wvalue;
00058   }
00059 private:
00060   enum VType { INT, CHARS, WORD };
00061   int ivalue;
00062   Chars cvalue;
00063   Word wvalue;
00064   VType theType;
00065 };
00066 
00067 //------------------------ ViewContent -------------------- //
00068 
00069 class ViewContent
00070 {
00071 public:
00072 
00073   ViewContent(const Chars& name): theName(name) {}
00074 
00075   ViewContent(const ViewContent& v):  theName(v.theName) {}
00076   
00077   virtual const char* type( ) const = 0;
00078 
00079   virtual ViewContent* clone( ) const = 0;
00080 
00081   const Chars& name()const { return theName; }
00082 
00083   virtual void submit(ostream& ostr)const=0;
00084 
00085   virtual PValue getValue(Chars name ) const = 0;
00086 
00087   virtual void setValue( istream& is,Chars& errMsg,Chars name) = 0;
00088   
00089   virtual const ViewContent* contentOf( const Chars& name )const = 0;
00090 
00091 private:
00092   
00093   Chars theName;
00094 
00095 };
00096 // ----------------------------- ViewContentCell -----------------------------//
00097 struct ViewContentCell
00098 {
00099   ViewContentCell( const ViewContent& content): c(content.clone()), n(NULL) { }
00100   const ViewContent& content() const { return *c; }
00101   ViewContentCell* next() {return n; }
00102   void setNext(ViewContentCell* next) { n = next; }
00103   ViewContent* pcontent() { return c; }
00104 private:
00105   ViewContent* c;
00106   ViewContentCell* n;
00107 };
00108 
00109 // ----------------------------- EditInteger  -----------------------------//
00110 
00111 class EditInteger : public  ViewContent
00112 {
00113 public:
00114   EditInteger( const Chars& name,const Chars& text,int change = 0,int def = 0,
00115                int minV = 0,int maxV = MAXINT):
00116     ViewContent(name),
00117     theText( text ),
00118     changeable( change ),
00119     defaultValue( def ),
00120     minValue(minV),
00121     maxValue(maxV) { }
00122 
00123   EditInteger(const EditInteger& i):
00124     ViewContent(i),
00125     theText( i.theText ),
00126     changeable( i.changeable ),
00127     defaultValue( i.defaultValue ),
00128     minValue(i.minValue),
00129     maxValue(i.maxValue) { }
00130 
00131   EditInteger* clone() const { return new EditInteger(*this); }
00132 
00133   const char* type( ) const { return "int"; }
00134 
00135   PValue getValue(Chars name = Chars() ) const { return PValue( defaultValue ); }
00136  
00137   void setValue( istream& is,Chars& errMsg,Chars name = Chars()) { 
00138     int tmpI;
00139     is >> tmpI;
00140     if (tmpI < minValue) {
00141       errMsg = theText+Chars(": this parameter can't be less than ")
00142         + Chars( minValue );
00143       return;
00144     }
00145     if (tmpI > maxValue) {
00146       errMsg = theText+Chars(": this parameter can't be greater than ")
00147         + Chars( maxValue );
00148       return;
00149     }
00150     defaultValue = tmpI; 
00151   }
00152 
00153   const ViewContent* contentOf( const Chars& n ) const{
00154     if (name() == n ){
00155       return this;
00156     }
00157     return NULL;
00158   }
00159 
00160   void submit(ostream& ostr)const;
00161 
00162 private:
00163   int changeable;
00164   int defaultValue;
00165   int minValue;
00166   int maxValue;
00167   Chars theText;
00168 };
00169 
00170 // ----------------------------- EditBool  -----------------------------//
00171 
00172 class EditBool : public  ViewContent
00173 {
00174 public:
00175   EditBool( const Chars& name,const Chars& text,int change = 0,int def = 0):
00176     ViewContent(name),
00177     theText( text ),
00178     changeable( change ),
00179     defaultValue( def ) { }
00180 
00181   EditBool(const EditBool& i):
00182     ViewContent(i),
00183     theText( i.theText ),
00184     changeable( i.changeable ),
00185     defaultValue( i.defaultValue ) { }
00186 
00187   EditBool* clone() const { return new EditBool(*this); }
00188 
00189   const char* type( ) const { return "bool"; }
00190 
00191   PValue getValue(Chars name = Chars() ) const { return PValue( defaultValue ); }
00192  
00193   void setValue( istream& is,Chars& errMsg,Chars name = Chars()) { 
00194     int tmpI;
00195     is >> tmpI;
00196     defaultValue = tmpI; 
00197   }
00198 
00199   const ViewContent* contentOf( const Chars& n ) const{
00200     if (name() == n ){
00201       return this;
00202     }
00203     return NULL;
00204   }
00205 
00206   void submit(ostream& ostr)const;
00207 
00208 private:
00209   int changeable;
00210   int defaultValue;
00211   Chars theText;
00212 };
00213 
00214 // ----------------------------- EditText  -----------------------------//
00215 
00216 class EditText : public  ViewContent
00217 {
00218 public:
00219   EditText( const Chars& name,const Chars& text,int change = 0,Chars def = ""):
00220     ViewContent(name),
00221     theText( text ),
00222     changeable( change ),
00223     defaultValue( def ) { }
00224     
00225 
00226   EditText(const EditText& c):
00227     ViewContent(c),
00228     theText( c.theText ),
00229     changeable( c.changeable ),
00230     defaultValue( c.defaultValue ) { }
00231 
00232   virtual EditText* clone() const { return new EditText(*this); }
00233 
00234   const char* type( ) const { return "text"; }
00235 
00236   virtual PValue getValue(Chars name = Chars() ) const { 
00237     return PValue( defaultValue ); 
00238   }
00239  
00240   virtual void setValue( istream& is, Chars& errMsg, Chars name = Chars());
00241 
00242   const ViewContent* contentOf( const Chars& n ) const{
00243     if (name() == n ){
00244       return this;
00245     }
00246     return NULL;
00247   }
00248 
00249   void submit(ostream& ostr)const;
00250 protected:
00251 
00252    Chars defaultValue;
00253    Chars theText;
00254 
00255 private:
00256   int changeable;
00257 };
00258 
00259 // ----------------------------- EditWord  -----------------------------//
00260 
00261 class EditWord : public  EditText
00262 {
00263 public:
00264   
00265   //@db 2.91 : temporary put default instantiation for 'f' and 'w' below,
00266   //           we likely need to remove instantiation for 'change' instead 
00267   
00268   EditWord( const Chars& name,const Chars& text,int change = 0,
00269             const FreeGroup& f = FreeGroup(), const Word& w = Word() ):
00270     EditText( name, text, change),
00271       theGroup( f ),
00272       theWord( w )
00273     {
00274       ostrstream os;
00275       theGroup.printWord(os,theWord);
00276       os << '\0';
00277       defaultValue = os.str();
00278     }
00279   
00280 
00281   EditWord(const EditWord& c):
00282     EditText(c),
00283     theGroup( c.theGroup ),
00284     theWord( c.theWord ) { }
00285 
00286   EditWord* clone() const { return new EditWord(*this); }
00287 
00288   PValue getValue(Chars name = Chars() ) const { 
00289     return PValue( theWord ); 
00290   }
00291  
00292   void setValue( istream& is, Chars& errMsg, Chars name = Chars());
00293 
00294 private:
00295  
00296 
00297   Word theWord;
00298   FreeGroup theGroup;
00299   
00300 };
00301 
00302 // ----------------------------- GroupWindow  -----------------------------//
00303 
00304 class GroupWindow : public  ViewContent
00305 {
00306 public:
00307   GroupWindow(const Chars& name):
00308     ViewContent(name),
00309     children(NULL),
00310     last(NULL) { }
00311     
00312   GroupWindow(const GroupWindow& gw);
00313 
00314   ~GroupWindow();
00315 
00316   GroupWindow* clone() const { return new GroupWindow( *this ); }
00317 
00318   virtual const char* type( ) const { return "GroupWindow"; }
00319 
00320   virtual Chars properties() const { return ""; }
00321 
00322   void submit(ostream& ostr) const;
00323 
00324   PValue getValue(Chars name) const { 
00325     const ViewContent* tmp = contentOf( name ); 
00326     if ( !tmp )
00327       error("PValue getValue(Chars name) const : couldn't find a parameter ");
00328     if ( tmp == this )
00329       error("PValue getValue(Chars name) const :"
00330             " GroupWindow doesn't have value ");
00331     return tmp->getValue( name ); 
00332   }
00333 
00334   void setValue(istream& is, Chars& errMsg,Chars name) {
00335     const ViewContent* consttmp = contentOf( name ); 
00336     if ( ! consttmp )
00337       error(" void setValue( PValue p) : couldn't find a parameter ");
00338     if ( consttmp == this )
00339       error("PValue getValue(Chars name) const : "
00340             "GroupWindow doesn't have value ");
00341     
00342      ViewContent* tmp = (ViewContent* )consttmp;
00343      tmp->setValue( is , errMsg, name );     
00344   }
00345 
00346   void add(const ViewContent& c);
00347 
00348   const ViewContent* contentOf( const Chars& name ) const;
00349 
00350 protected:
00351   
00352   ViewContentCell* children;
00353   ViewContentCell* last;
00354 };
00355 
00356 // ----------------------------- RadioButtonGroup  --------------------------//
00357 
00358 class RadioButtonGroup :  public GroupWindow
00359 {
00360 public:
00361   RadioButtonGroup(const Chars& name): GroupWindow( name ) { }
00362      
00363   RadioButtonGroup(const RadioButtonGroup& bg): 
00364     GroupWindow( bg ), 
00365     selButton( bg.selButton){ }
00366 
00367   RadioButtonGroup* clone() const { return new RadioButtonGroup( *this ); }
00368  
00369   const char* type( ) const { return "RadioButtonGroup"; }
00370 
00371   void add(const ViewContent& c);
00372 
00373   PValue getValue(Chars name) const { 
00374     const ViewContent* tmp = contentOf( name ); 
00375     if ( !tmp )
00376       error("PValue getValue(Chars name) const : couldn't find a parameter ");
00377     
00378     if ( tmp == this )
00379       return selButton;
00380     
00381     return tmp->getValue( name ); 
00382   }
00383   
00384   
00385   void setValue( istream& is, Chars& errMsg, Chars name) {
00386     const ViewContent* consttmp = contentOf( name ); 
00387     if ( ! consttmp )
00388       error(" void setValue( PValue p) : couldn't find a parameter ");
00389     if ( consttmp == this ){
00390       is >> selButton;
00391     } else {
00392       ViewContent* tmp = (ViewContent* )consttmp;
00393       tmp->setValue(  is, errMsg, name );
00394     }     
00395   }
00396 
00397 private:
00398   Chars selButton;
00399 
00400 };
00401 
00402 // ----------------------------- RadioButton  --------------------------//
00403 
00404 class RadioButton :  public GroupWindow
00405 {
00406 public:
00407   RadioButton(const Chars& name, const Chars& text, int change = 0)
00408     : GroupWindow( name ), theText(text),changeable( change ) { }
00409      
00410   RadioButton(const RadioButton& bg): 
00411     GroupWindow( bg ), 
00412     theText(bg.theText),
00413     changeable( bg.changeable ){ }
00414 
00415   RadioButton* clone() const { return new RadioButton( *this ); }
00416  
00417   const char* type( ) const { return "RadioButton"; }
00418 
00419   Chars properties() const { 
00420     return  Chars(" \"") + theText + Chars("\" ") + Chars(changeable) + Chars(" "); 
00421   }
00422   
00423 private:
00424   int changeable;
00425   Chars theText;
00426 };
00427 
00428 // ----------------------------- Subproblem  -----------------------------//
00429 
00430 class Subproblem : public ViewContent, public FEData
00431 {
00432 public:
00433 
00434   Subproblem(const Chars& name, ARCSlotID asi, const Text& d, int value = 0)
00435     : ViewContent( name ),
00436       numOfARCs( value ),
00437       description( d ),
00438       theASI( asi ){ }
00439 
00440   Subproblem(const Subproblem& s)
00441     : ViewContent(s),
00442       numOfARCs( s.numOfARCs),
00443       description( s.description ),
00444       theASI( s.theASI ){ }
00445 
00446   
00447   const char* type( ) const { return "Subproblem"; }
00448   
00449   Subproblem* clone( ) const { return new Subproblem(*this);}
00450   
00451   PValue getValue(class Chars) const { }
00452   void setValue(istream& is, Chars& errMsg, class Chars) { }
00453 
00454   void submit(ostream& ostr)const;
00455 
00456   const ViewContent* contentOf(const class Chars & )const { }
00457 
00458 private:
00459   
00460   ARCSlotID theASI;
00461   int numOfARCs;
00462   Chars description;
00463 };
00464 // ----------------------------- ParameterStructure -------------------------//
00465 
00466 
00467 class ParameterStructure
00468 {
00469 public:
00470   ParameterStructure(OID o,const GroupWindow& p)
00471     : theParameters( p ), bossOID( o ) { }
00472   
00473   ParameterStructure(const ParameterStructure& p): 
00474     theParameters( p.theParameters ), bossOID( p.bossOID ) { }
00475 
00476   void read( istream& istr );
00477 
00478   PValue getValue(const Chars& name)const {
00479     return theParameters.getValue( name );
00480   }
00481 
00482 private:
00483   GroupWindow theParameters;
00484   OID bossOID;
00485 };
00486 
00487 
00488 
00489 #endif

Generated at Tue Jun 19 09:49:39 2001 for Magnus Classes by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001