/* Cfour (C++ Common Console Classes)
 * Copyright (C) 2001 Jeffrey Bakker
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *
 *  Author:              Jeffrey Bakker
 *  Filename:            cffile.h
 *  File version:        1.2
 *
 *  ===========================================================================
 *
 *  Created on:  August 21st, 2001
 *
 *
 *  Modified on: September 2nd, 2001
 *
 *             - Added a new read(), rline(), and write() methods for reading
 *               and writing to and from a file.
 *
 *  ===========================================================================
 *
 *  Remark:
 *
 *  This is the definition of the CFfile class. The CFfile class contains file
 *  IO methods which automates file checking while opening I/O streams. You
 *  can now safely open and close files, error free.
 *
 *  For specific details on the methods, see the documentation at the top of
 *  the file "cffile.cpp".
 *
 *  ===========================================================================
 * _______. ..
 */



#ifndef _C4_FILE_H 
#define _C4_FILE_H 

#include <iostream> 
#include <fstream> 
#include <string> 
using namespace std;


class CFfile {

 public:

  CFfile();
  CFfile(string filename, char io);
  CFfile(string filein, string fileout);
  ~CFfile();

  bool openR(string INfile) ;  // open file for reading
  bool openW(string OUTfile);  // open file for writing
  bool open(string filename, char io); // open, specify

  bool exists(string fname);
  void backup(string fname, string bakname);

  void read(string &buffer);   // read to the string
  void rline(string &buffer);  // read a line to the string
  void write(string buffer);   // write out from the string

  void closeR();  // close the input file
  void closeW();  // close the output file
  void close();   // close all

// protected:

  ifstream ifile;  // input file
  ofstream ofile;  // output file
};

#endif  // _C4_FILE_H