Psi4
Public Member Functions | Private Types | List of all members
psi::OutFile Class Reference

The interface to the new Psi4 ASCII outfile writer. More...

#include <ParallelPrinter.h>

Inheritance diagram for psi::OutFile:
psi::PsiOutStream psi::PsiFileImpl< std::ofstream > psi::PsiStreamBase< std::ostream > psi::BasesBase

Public Member Functions

 OutFile (const std::string &filename="", const FileMode &mode=APPEND)
 Constructor that opens a file with name "filename". More...
 
 ~OutFile ()
 Calls Close to release memory. More...
 
void Open (const std::string &filename, const FileMode &mode)
 Opens "filename" in write mode "mode". More...
 
void Close ()
 Closes file and frees Stream_ pointer. More...
 
- Public Member Functions inherited from psi::PsiOutStream
 PsiOutStream (SharedOutStream Stream=SharedOutStream())
 Makes an OutStreamBase that defaults to std::cout. More...
 
 PsiOutStream (const PsiOutStream &other)
 Creates this by copying other, via base copy constructor. More...
 
const PsiOutStreamoperator= (const PsiOutStream &other)
 Allows assignment of other to this, calls base assignment. More...
 
virtual ~PsiOutStream ()
 No memory to free up (we don't delete cout or cerr) More...
 
void Flush ()
 Flushes the Stream. More...
 
void Printf (const char *format,...)
 Allows printf (or fprintf) like syntax to this object. More...
 
template<typename T >
std::ostream & operator<< (const T &Input)
 Allows c++ like interface for most objects. More...
 
std::ostream & operator<< (StreamManips fp)
 Allows c++ like interface for things like std::endl. More...
 
void MakeBanner (const std::string &message, const char delimiter='*', const int width=80)
 Makes a banner. More...
 
- Public Member Functions inherited from psi::PsiStreamBase< std::ostream >
 PsiStreamBase (const MyType &other)
 Calls Clone for actual copy. More...
 
 PsiStreamBase ()
 Default constructor of stringstream is called. More...
 
const MyTypeoperator= (const MyType &other)
 Calls Clone for assignment iff this!=&other, returns *this. More...
 
virtual ~PsiStreamBase ()
 Memory not worried about until we get down the class tree to files. More...
 

Private Types

typedef PsiFileImpl
< std::ofstream > 
FileBase
 

Additional Inherited Members

- Protected Member Functions inherited from psi::PsiStreamBase< std::ostream >
void EmptyBuffer ()
 I always forget how to empty a stringstream. More...
 
- Protected Member Functions inherited from psi::BasesBase
 BasesBase ()
 Returns true if this is the lucky MPI process that gets to read/write. More...
 
int WhoIsSpecial () const
 Returns the integer of the Lucky MPI process. More...
 
bool ImSpecial () const
 Returns true if this is the lucky MPI process that gets to read/write. More...
 
- Protected Attributes inherited from psi::PsiStreamBase< std::ostream >
std::stringstream Buffer_
 This is where each MPI task ultimately writes from or to. More...
 
std::shared_ptr< std::ostream > Stream_
 The actual stream. More...
 
- Private Member Functions inherited from psi::PsiFileImpl< std::ofstream >
 PsiFileImpl ()
 
void Open (const std::string &filename, const FileMode &Mode, std::shared_ptr< T2 > &FileStream, const bool ImSpecial)
 
void Close (std::shared_ptr< T2 > &FileStream)
 We cheat to avoid the upcast. More...
 

Detailed Description

The interface to the new Psi4 ASCII outfile writer.

First thing to note is that copying of this class is disallowed and is enforced by making the assignment operator and copy constructor private. This is because the C++ standard does not allow copying of streams, which is surprising to most people when they first hear it, but in the long run makes a lot of sense. Streams are, as the name suggests, the mechanism through which data flows; they are not the data itself. Most likely when someone wants to copy a stream, they want to copy the data itself (this is what we do in the copy constructor of PsiStreamBase) and not the mechanism by which the data flows. In order to avoid this confusion the C++ standard makes copying prohibited. Now in reality we could allow copying because we are dealing with pointers and not the actual objects; copying of a pointer is of course not prohibited, but I'll stick to the example laid forth by the C++ standard.

The other thing to note is that this class keeps the file open until it goes out of scope or you tell it to close. With the exception of Psi4's main output file, this means you probably want to print what you gotta' print and then close it, don't keep it open any longer then you have to.

Member Typedef Documentation

typedef PsiFileImpl<std::ofstream> psi::OutFile::FileBase
private

Constructor & Destructor Documentation

psi::OutFile::OutFile ( const std::string &  filename = "",
const FileMode mode = APPEND 
)

Constructor that opens a file with name "filename".

Upon construction passes NULL to base, so that the pointer is not set to cout. This avoids free-ing cout in the Open call. By default no file is opened, but supplying a filename will open that file in APPEND mode. Supplying a mode as well as a filename opens the file in that mode instead. The mechanism of the constructor is to call Open so behavior is identical between initializing an object with a file and calling Open after calling the default constructor.

Parameters
[in]filenameName of file to open (path relative to directory Psi was called from)
[in]modeThe mode the file will be opened in
psi::OutFile::~OutFile ( )
inline

Calls Close to release memory.

Member Function Documentation

void psi::OutFile::Close ( )

Closes file and frees Stream_ pointer.

void psi::OutFile::Open ( const std::string &  filename,
const FileMode mode 
)

Opens "filename" in write mode "mode".


The documentation for this class was generated from the following files: