NAMD
fstream_namd.C
Go to the documentation of this file.
1 
2 #include "fstream_namd.h"
3 #include "common.h"
4 
5 void ofstream_namd::open(const char *_fname, const char *_ext) {
6  if ( fd ) NAMD_bug("ofstream_namd::open() called when file is already open");
7  NAMD_backup_file(_fname, _ext);
8  open(_fname);
9 }
10 
11 void ofstream_namd::open(const char *_fname, std::ios_base::openmode _mode) {
12  if ( fd ) NAMD_bug("ofstream_namd::open() called when file is already open");
13  fname = _fname;
14  fd = NAMD_open_text(_fname, _mode & std::ios_base::app);
15 }
16 
18  if ( ! fd ) NAMD_bug("ofstream_namd::flush() called when file is not open");
19  const std::string text = str();
20  NAMD_write(fd, text.c_str(), text.size(), fname.c_str());
21  str("");
22  return *this;
23 }
24 
26  if ( ! fd ) NAMD_bug("ofstream_namd::close() called when file is not open");
27  flush();
28  NAMD_close(fd, fname.c_str());
29  fd = 0;
30 }
31 
int NAMD_open_text(const char *fname, int append)
Definition: common.C:194
ofstream_namd & flush()
Definition: fstream_namd.C:17
#define NAMD_write
Definition: dcdlib.C:24
#define NAMD_close
Definition: Output.C:52
void NAMD_bug(const char *err_msg)
Definition: common.C:123
void NAMD_backup_file(const char *filename, const char *extension)
Definition: common.C:159
void open(const char *_fname, std::ios_base::openmode _mode=std::ios_base::out)
Definition: fstream_namd.C:11