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

/magnus/back_end/SessionManager/include/SMEnumerator.h

Go to the documentation of this file.
00001 /*
00002  *   $Id: SMEnumerator.h,v 1.7 2000/03/03 01:35:15 bormotov 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: Declaration of class SMEnumerator
00009 //
00010 // Principal Author: Alexei Myasnikov
00011 //
00012 // Status: in progress
00013 //
00014 // Revision History:
00015 //
00016 
00017 #ifndef _SMENUMERATOR_H_
00018 #define _SMENUMERATOR_H_
00019 
00020 #include "AlgebraicObject.h"
00021 #include "SMFPGroup.h"
00022 #include "Word.h"
00023 #include "Associations.h"
00024 #include "Subgroup.h"
00025 
00026 template <class T> class EnumeratorProblem;
00027 
00028 
00029 // ---------------------------- NoType -------------------------- //
00030 
00031 class NoType {
00032  public:
00033   static Type type( ) { return theNoType; }
00034  private:
00035   static const Type theNoType;
00036 
00037 };
00038 
00039 // -----------------------------------------------------------------------//
00040 // ------------------------ SMListData -----------------------------------//
00041 // -----------------------------------------------------------------------//
00042 
00043 class SMListData
00044 {
00045 public:
00046 
00047   // Default constructor
00048   SMListData( );
00049 
00050   SMListData( const SMListData& sd );
00051 
00052   void doHardCopy( const SMListData& );
00053 
00054   ~SMListData() {
00055     closeCurrentMode();
00056   }
00057 
00058   /////////////////////////////////////////////////////////////////////////
00059   //                                                                     //
00060   //          :                                                          //
00061   //                                                                     //
00062   /////////////////////////////////////////////////////////////////////////
00063 
00064   // operator for adding elements
00065   SMListData& operator << (const class WriteEnumeratorElement& e);
00066 
00067   // operator for all other information
00068   SMListData& operator << (const Chars& c);
00069   
00070   // appends a list to the end 
00071   void append( SMListData& sd );
00072   
00073   void setWriteMode();
00074   void setReadMode();
00075   void closeCurrentMode();
00076 
00077   /////////////////////////////////////////////////////////////////////////
00078   //                                                                     //
00079   // Access functions :                                                  //
00080   //                                                                     //
00081   /////////////////////////////////////////////////////////////////////////
00082 
00083 
00084   // returns i-th element as a character. 
00085   // Iterator must parse it to the corresponding data type
00086   Chars getElementOf( int i );
00087   
00088   // number of elements in the list
00089   int numberOfElements() const { return number_of_elements; }
00090 
00091   //  for front end only
00092   Chars getDataFileName() const { return dataFileName; }
00093 
00094   // returns current mode: ios::out, ios::in or -1 if 
00095   // no one of those was set
00096   int getMode() const { return mode; }
00097 
00098   /////////////////////////////////////////////////////////////////////////
00099   //                                                                     //
00100   // IPC tools:                                                          //
00101   //                                                                     //
00102   /////////////////////////////////////////////////////////////////////////
00103 
00104   // IPC tools needed to obtain the number of elements in the list
00105   friend ostream& operator < ( ostream& ostr, const SMListData& s )
00106   {
00107     ostr < s.dataFileName < s.refFileName;
00108     ostr < s.number_of_elements;
00109     return ostr;
00110   }
00111   
00112   friend istream& operator > ( istream& istr, SMListData& s )
00113   {
00114     Chars dF, rF;
00115     istr > dF > rF;
00116 
00117     if ( dF != s.dataFileName || rF != s.refFileName )
00118       error("friend istream& operator > ( istream& istr, SMListData& s ) :"
00119             " data files are seem to be different");
00120     istr >  s.number_of_elements;
00121     return istr;
00122   }
00123 
00124 private:
00125   
00126   void openFiles( int );
00127   
00128   // gives offset of the i-th element 
00129   int getBegPosOf( int i);
00130 
00131   // returns the length of an i-th element
00132   int getLengthOf( int i);
00133 
00134   ////////////////////////////////////////////////////////////////
00135   // Data members:                                              //
00136   ////////////////////////////////////////////////////////////////
00137   
00138   fstream dataFile;
00139   // file with elements
00140 
00141   fstream refFile;
00142   // file with offsets of lements in dataFile 
00143   
00144   Chars dataFileName;
00145   Chars refFileName;
00146   // file names
00147 
00148   int number_of_elements;
00149   // number of elements
00150   int mode;
00151   // current mode
00152 };
00153 
00154 //--------------------------------------------------------------------//
00155 //------------------------ EnumeratorARCer ---------------------------//
00156 //--------------------------------------------------------------------//
00157 
00158 
00159 
00160 class EnumeratorARCer : public ARCer
00161 {
00162 public:
00163 
00164   /////////////////////////////////////////////////////////////////////////
00165   //                                                                     //
00166   // Constructors:                                                       //
00167   //                                                                     //
00168   /////////////////////////////////////////////////////////////////////////
00169  
00170   EnumeratorARCer( ComputationManager& boss, SMListData& d ) 
00171     : ARCer( boss ), theData( d ) { } 
00172   
00173 
00174   /////////////////////////////////////////////////////////////////////////
00175   //                                                                     //
00176   // Accessors:                                                          //
00177   //                                                                     //
00178   /////////////////////////////////////////////////////////////////////////
00179 
00180   // Inherited from ARCer:
00181   // bool takeControl( );
00182   
00183   void submitSignal( );
00184 
00185 //  Chars getFileName() const { return file.getFileName(); }
00186  
00187   /////////////////////////////////////////////////////////////////////////
00188   //                                                                     //
00189   // IPC interaction members:                                            //
00190   //                                                                     //
00191   /////////////////////////////////////////////////////////////////////////
00192 
00193   void runComputation( );
00194   
00195  protected:
00196 
00197   virtual void enumerate() = 0;
00198 
00199   bool submitSignalRecieved()const;
00200 
00201   SMListData& theData;
00202 
00203  private:
00204 
00205  
00206 };
00207 
00208 //--------------------------------------------------------------------------//
00209 //-------------------------- EnumeratorProblem -----------------------------//
00210 //--------------------------------------------------------------------------//
00211 template <class T> class EnumeratorProblem;
00212 
00213 template <class T>  class EnProbType {
00214 public:
00215   EnProbType() {
00216     ostrstream ostr;
00217     ostr << "EnumeratorProblem" << T::type() << '\0' << flush;
00218     strcpy(s, ostr.str());
00219     ostr.freeze(0);
00220   }
00221 private:
00222   friend class EnumeratorProblem<T>;
00223   char s[100];
00224 };
00225 
00226 // ---------------------------------------------------------------------  //
00227 
00228 template <class T> class EnumeratorProblem  : public Supervisor
00229 {
00230 public:
00231 
00232   EnumeratorProblem( AlgebraicObject& b ): 
00233     Supervisor(true),
00234     theParent(b) 
00235    {
00236       theData.setWriteMode();
00237     }
00238   
00239   ~EnumeratorProblem() {
00240    theData.closeCurrentMode();
00241   }
00242   
00243   AlgebraicObject& getParentObject() const { return theParent; }
00244   
00245   const IconID iconID( ) const {
00246     return IconID::enumerator_problem;
00247   }
00248 
00249   const char* typeID( ) const {
00250     return type( );
00251   }
00252   
00253   static const char* type( )  { return theType.s; }
00254 
00255   // Access functions
00256   
00257   SMListData& getData() { return theData;}
00258 
00259 protected:
00260   SMListData theData;
00261 
00262   Chars theDataFile;
00263   static EnProbType<T> theType;
00264   AlgebraicObject& theParent;                                                       
00265 };
00266 
00267 #endif

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