SEclone  general classes  for input output

This chapter covers the following topics



Input and output files

Options and final print management


The corresponding files in the program are


#include "h\_00_  FE_FS.h"               // input output files

#include "h\_00a_  fsr.h"                // relay for printing only in tests

#include "h\_01y_  opsudo.h"             // storing and managing options


The input file is derived from ifstream and is quite simple


class FINPUT: private ifstream

{USHORT open, endf;


 static char * name;



 void SetName(char * nn){name=nn;}


 int OpenFI(){if(open) return 0; open=1;

              char zn[200]; strcpy_s(zn,198,name); int ll=strlen(zn);

              strcpy_s(&zn[ll],30,".txt"); // add file type


              if(is_open()) return 0 ;

              Console::WriteLine("problem in open input");

              endf=1;return 1; }


 void CloseFI(){if(endf) return; ifstream::close();endf=1;}


 int GetPuzzle(char * zp);  // get next and write on output the puzzle



char * FINPUT::name="puz";


int FINPUT::GetPuzzle(char * zp)

 {if(endf) return 0;

  char ze[400]; // big buffer to avoid problems linked to getline

  while(!eof() )

  {getline(ze,300); ze[301]=0;  int i= strlen(ze);


    {endf=1;return 0;}

   if(i<81)continue; zp[81]=0; // file truncated to 81

   // standard file  clues or "." minimum 17 clues

   int n=0;

   for(int i=0;i<81;i++)

      {char c=ze[i];

       if(c<'0' || c>'9') zp[i]='.';

          else {n++;zp[i]=ze[i];}


    if(n<17) continue;

       return 1;

    }// end while

  endf=1; return 0;}




The GetPuzzle() looks for the next line that looks like a puzzle with a minimum of 17 clues.

The name is stored as a “class” string. As that class has only one member (finput), it could as well have been stored as a classical data and initialized in a constructor.


Output  Files are derived from “ofstream “ and  have nothing special out of the name handling.




class FOUTPUT : public ofstream  // public pour les tests

{USHORT open, endf;


 static char* zpuz;


 int OpenFO1()  {char zn[200]; strcpy_s(zn,198,; int ll=strlen(zn);


                    return OpenFO(zn); }

 int OpenFO2() {char zn[200]; strcpy_s(zn,198,; int ll=strlen(zn);


                            return OpenFO(zn); }

 void CloseFO(){if(endf) return; ofstream::close();endf=1;}

 void PrintErEpEd(int er,int ep,int ed)

      {(*this)<<zpuz<<" ";

              int era=er/10,erb=er%10,epa=ep/10,epb=ep%10,eda=ed/10,edb=ed%10;

      (*this)     <<"ED="<<era<<"."<<erb<<"/"<<epa<<"."<<epb<<"/"<<eda<<"."<<edb; }

private :

 int OpenFO(char * nam)

     {if(open) return 0; open=1;


      if(is_open()) return 0 ;

      Console::WriteLine("problem in open output");

      endf=1;return 1; }



char* FOUTPUT::zpuz;  // to store the pointer to input


That class has 2 members, one for each output.

zpuz  receive the pointer to the input file prepared in finput.GetPuzzle();

Special routines are given to name output files.

Also, the final print is done here, going to the appropriate file depending on which member is called.


FSR class, relay for debugging output



That class is the entry point for all debugging prints. It has only one member, E$.



// FSR class has no use in SE rating;

// in my solver, FSR intercepts all standars outputs

//   to simulate them in specific conditions

// it must stay here for tests purposes

// WARNING aigstop is changed in that class if a table reach a limit



class FSR

{public:  USHORT pron;    

 FSR() {pron=0;}

 inline void E(char c)       {if(pron)foutput<<c; }

 inline void E(char* c)      {if(pron)foutput<<c; }

 inline void E(int x)  {if(pron)foutput<<x;}


 inline void Enl()     {if(pron)foutput<<endl;}

 inline void Esp()     {if(pron)foutput<<' '; }

 inline void Echem(){if(pron)foutput<<"[]"; }

 inline void Etir()    {if(pron)foutput<<"."; }

 inline void Esl()     {if(pron)foutput<<" = "; }

 inline void Ewl()     {if(pron)foutput<<" - "; }

 inline void Enl(char c)     {if(pron)foutput<<c<<endl; }

 inline void Enl(char* c)    {if(pron)foutput<<c<<endl; }

 inline void Enl(int x)      {if(pron)foutput<<x<<endl;}

 inline void Enl2(){if(pron)foutput<<endl<<endl;}

 void Elimite(char * lib){Enl2();E("table:"); E(lib); Estop("limite atteinte "); }

 void Estop(char * lib) {Enl2();E(lib);Enl2();   aigstop=1;   }

 inline void Econflit(USHORT * m,USHORT id);

 inline void EPointM(int ip, int m);




pron   (print on)  is set to 1 in test mode.


aigstop is a general  variable set to 1 to stop processing as soon as possible. It is set here if an internal table reach the limit


Most of these relay prints have been set “inline” to limit impact on the overall performance;