#ifndef CSAFEFILE_H
#define CSAFEFILE_H

//////////////////////////////////////////////////////
//                                                  //
//  CSafeFile                                       //
//                                                  //
//  This class is almost the same as the class it   //
//  inherits from, but it adds the "Save" function  //
//  that closes the file and open it again to save  //
//  the modifications made.                         //
//                                                  //
//////////////////////////////////////////////////////


class CSafeFile : public std::ofstream
{
  std::string FileName;
  int TheFlags;

 public:
  CSafeFile(const char* Name) : ofstream(Name) {}
  void open(const char * Name, int Flags = ios::out)
    {
      TheFlags = Flags;
      FileName = Name;
      ofstream::open(Name, Flags);
    }
  void Save(void)
    {
      close();
      open(FileName.c_str(), TheFlags | ios::app);
    }
};

#endif
