Simpatico  v1.10
TextFileOArchive.cpp
1 /*
2 * Util Package - C++ Utilities for Scientific Computation
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "TextFileOArchive.h"
9 
10 namespace Util
11 {
12 
13  /*
14  * Constructor.
15  */
17  : filePtr_(0),
18  version_(0),
19  createdFile_(true)
20  { filePtr_ = new std::ofstream(); }
21 
22  /*
23  * Constructor.
24  */
25  TextFileOArchive::TextFileOArchive(std::string filename)
26  : filePtr_(0),
27  version_(0),
28  createdFile_(true)
29  { filePtr_ = new std::ofstream(filename.c_str()); }
30 
31 
32  /*
33  * Constructor.
34  */
36  : filePtr_(&file),
37  version_(0),
38  createdFile_(false)
39  {
40  if (!file.is_open()) {
41  UTIL_THROW("File not open");
42  }
43  }
44 
45  /*
46  * Destructor.
47  */
49  {
50  if (filePtr_ && createdFile_) {
51  delete filePtr_;
52  }
53  }
54 
55  /*
56  * Return underlying file by reference.
57  */
58  std::ofstream& TextFileOArchive::file()
59  { return *filePtr_; }
60 
61 }
std::ofstream & file()
Get the underlying ifstream by reference.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
virtual ~TextFileOArchive()
Destructor.
Utility classes for scientific computation.
Definition: accumulators.mod:1
TextFileOArchive()
Constructor.