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

/magnus/back_end/general/include/File.h

Go to the documentation of this file.
00001 /*
00002  *   $Id: File.h,v 1.8 1997/11/25 20:58:07 alex Exp $
00003  */
00004 
00005 // Copyright (C) 1996 The New York Group Theory Cooperative
00006 // See magnus/doc/COPYRIGHT for the full notice.
00007 
00008 // Contents: Definition of class File.
00009 //
00010 // Principal Author: Dmitry Bormotov
00011 //
00012 // Status: Under development.
00013 //
00014 // Revision History:
00015 // * 11/18/97  @am  implemented a method to keep
00016 //   information about colors. Colors are kept in 
00017 //   <filename>.color file. This file consists of records of
00018 //   type: "#<file_pos>%<colorName>@", where file_pos - numeric
00019 //   position in the file in which colors were changed, colorName -
00020 //   string, representing color in rgb format(see below).
00021 //   
00022 //
00023 // Special Notes:
00024 //  
00025 // * This is a simple deriviation from fstream, specially designed 
00026 //   for reporting large amount of data ( f.e. details of algorithms
00027 //   work ) to Session Manager and Front End to make it available for
00028 //   the end user.
00029 //
00030 
00031 
00032 #ifndef _File_h_
00033 #define _File_h_
00034 
00035 
00036 #include <stdio.h>
00037 #include <fstream.h>
00038 #include "MagnusHome.h"
00039 
00040 // Colors have to be in form RGB,
00041 // where R,G or B represents one hexademical digit of red,
00042 // green or blue intensity, respectively.
00043 
00044 const Chars mainColor = "000";
00045 const Chars titleColor = "aaa";
00046 
00047 // -------------------------------- File ----------------------------------- //
00048 
00049 
00050 struct File : public fstream
00051 {
00052   
00053   File( )  
00054   {
00055     char s[L_tmpnam];
00056     char* tmpFileName = tempnam(MagnusTmp::magnusTmp(),NULL);
00057     theFileName = tmpFileName;
00058     free(tmpFileName);
00059     open(theFileName, ios::app);
00060     colorFile.open(theFileName+Chars(".color"),ios::app);
00061 #if SAFETY > 0
00062     if( !(*this) )
00063       error( "File::File( ) : "
00064              "Cannot open a file." );
00065 #endif
00066     setColor(mainColor);
00067   }
00068   // Creates temporary file 
00069   
00070   
00071   File( const Chars& fileName ) : 
00072     fstream( fileName, ios::app ), 
00073     theFileName(fileName)
00074   {
00075     colorFile.open(theFileName+Chars(".color"),ios::app);
00076 #if SAFETY > 0
00077     if( !(*this) )
00078       error( "File::File( Chars fileName ) : "
00079              "Cannot open a file." );
00080 #endif
00081     setColor(mainColor);
00082   }
00083   // Creates file with a specific name
00084   
00085   
00086   Chars getFileName() const { return theFileName; }
00087   // Returns name of the file.
00088   
00089   void setColor( const Chars& colorName ) 
00090   {
00091 #if SAFETY > 0
00092     if( colorName.length() !=3 )
00093       error( "void File::setColor( const Chars& colorName ) : "
00094              "Wrong color argument." );
00095 #endif
00096     
00097     char s[10];
00098     sprintf(s,"%.7d",tellp());
00099     colorFile << "#" << s << "%" <<  colorName << "@";
00100     colorFile.flush();
00101   }
00102   
00103   
00104 private:
00105   
00106   Chars theFileName; // holds name of the file
00107   fstream colorFile; // holds color mapping
00108 };
00109 
00110 
00111 inline ostream& ready(ostream& ostr) 
00112 {
00113   ostr <<  flush;
00114   return ostr;
00115 }
00116 
00117 inline ostream& end(ostream& ostr) 
00118 {
00119   ostr <<  flush;
00120   return ostr;
00121 }
00122 
00123 
00124 #endif  // _File_h_
00125 

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