Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
anl_file_mngr.h
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2 of the GNU General Public License as
00007   published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if 
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU General Public License along
00021   with this program; if not, write the Free Software Foundation, Inc., 59
00022   Temple Place - Suite 330, Boston MA 02111-1307, USA.
00023 
00024   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00025   Mountain View, CA 94043, or:
00026 
00027   http://www.sgi.com
00028 
00029   For further information regarding this notice, see:
00030 
00031   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00032 
00033 */
00034 
00035 
00036 /* -*-Mode: c++;-*- (Tell emacs to use c++ mode) */
00037 #ifndef anl_file_mngr_INCLUDED
00038 #define anl_file_mngr_INCLUDED
00039 
00040 // ==============================================================
00041 // ==============================================================
00042 //
00043 //
00044 // Description:
00045 //
00046 //    A file handler, which reports error messages using an abstraction
00047 //    named DIAGNOSTICS.  The interface of DIAGNOSTICS is expected to
00048 //    include the following:
00049 //
00050 //         Warning: (char *) -> void
00051 //         Error:   (char *) -> void
00052 //         Fatal:   (char *) -> void
00053 //
00054 //    where a Fatal call is not expected to return, but is expected to
00055 //    terminate execution.  An Error or a Warning will return.  The state
00056 //    after an error may not be as expected.
00057 //
00058 //    This implementation is based on the <stdio.h> facilities and 
00059 //    exports only what we currently need.  The interface can be 
00060 //    extended and generalized to fit any future needs.  Intended 
00061 //    use for reading from a file (similar for writing to a file):
00062 //
00063 //       ANL_FILE_MNGR file_mngr(diag);
00064 //       file_mngr.Open_Read(filename);
00065 //       while (!file_mngr.Error_Status() && !file_mngr.End_Of_File())
00066 //       {
00067 //          char c = file_mngr.Read_Char();
00068 //          .... c ...
00069 //       }
00070 //       file_mngr.Close_File();
00071 //
00072 //    This abstraction does not buffer output beyond what is provided
00073 //    by default through the <stdio.h> utilities, so any such buffering
00074 //    must occur outside of this abstraction.  Such buffering may be
00075 //    desirable, since this abstraction will perform fairly extensive
00076 //    tests on all IO operations.
00077 //
00078 // ==============================================================
00079 // ==============================================================
00080 
00081 
00082 class ANL_DIAGNOSTICS;
00083 
00084 class ANL_FILE_MNGR
00085 {
00086 private:
00087 
00088    ANL_DIAGNOSTICS *_diag;
00089    const char      *_name;
00090    FILE            *_file;
00091    INT32            _next_ch;
00092 
00093    static const INT _obuf_size = 513;    // Size of output buffer
00094    INT              _next_obuf;          // Next available char in _obuf
00095    char             _obuf[_obuf_size+1]; // Output buffer
00096 
00097    static void _Concat(char       *buf,
00098                        INT         max_chars,
00099                        const char *string[],
00100                        INT         num_strings);
00101 
00102    static UINT64 _Get_Decimal_Number(INT ch);
00103    static UINT64 _Get_Hex_Number(INT ch);
00104    static BOOL   _Exists(const char *name);
00105 
00106    void _General_Check(BOOL c, const char *proc_name, const char *msg);
00107    void _Not_Open_Check(const char *proc_name, const char *to_be_opened);
00108    void _Is_Open_Check(const char *proc_name);
00109    void _Overwrite_Warning(const char *proc_name, const char *filename);
00110    void _Write_Obuf();
00111 
00112 public:
00113 
00114    ANL_FILE_MNGR(ANL_DIAGNOSTICS *diag):
00115      _diag(diag),
00116      _name(NULL),
00117      _file(NULL),
00118      _next_ch(EOF),
00119      _next_obuf(0)
00120    {}
00121 
00122    ~ANL_FILE_MNGR() { if (_file != NULL) Close_File(); }
00123 
00124    void Open_Read(const char *name);
00125    void Open_Create(const char *name);
00126    void Open_Append(const char *name);
00127    void Close_File();
00128    void Close_And_Remove_File();
00129 
00130    BOOL   File_Is_Open() {return (_file != NULL);}
00131    BOOL   End_Of_File() {return (_next_ch == EOF);}
00132    char   Peek_Char() {return _next_ch;}   // Does not alter stream ptr
00133    char   Read_Char();   // Returns current char and advances stream ptr
00134    UINT64 Read_Uint64(BOOL as_hex = FALSE);
00135    UINT64 Read_Ptr() {return Read_Uint64(TRUE);}
00136    void   Write_Char(char c);
00137    void   Write_String(const char *s);
00138    void   Flush_Write_Buffer() {if (_next_obuf > 0) _Write_Obuf();}
00139 
00140    const char *Name() const {return _name;}
00141    FILE       *File() {return _file;}
00142    
00143 }; // ANL_FILE_MNGR
00144 
00145 
00146 #endif /* anl_file_mngr_INCLUDED */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines