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

The parallel (pun intended) of OutFile, except it reads files in. More...

#include <ParallelScanner.h>

Inheritance diagram for psi::InFile:
psi::PsiInStream psi::PsiFileImpl< std::ifstream > psi::PsiStreamBase< std::istream > psi::BasesBase

Public Member Functions

 InFile (const std::string &filename="", const FileMode &mode=NOFILEMODE)
 Constructor that opens a file with name "filename". More...
 
 ~InFile ()
 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::PsiInStream
 PsiInStream (const PsiInStream &other)
 
const PsiInStreamoperator= (const PsiInStream &other)
 
virtual ~PsiInStream ()
 
 PsiInStream (SharedInStream Stream=SharedInStream())
 
template<typename T >
std::istream & operator>> (T &thing)
 
 operator bool ()
 Buffer is false when we have everything from it. More...
 
- Public Member Functions inherited from psi::PsiStreamBase< std::istream >
 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::ifstream > 
FileBase
 Convient typedef of the FileBase. More...
 

Additional Inherited Members

- Protected Types inherited from psi::PsiInStream
typedef PsiStreamBase
< std::istream > 
BaseType
 
- Protected Member Functions inherited from psi::PsiInStream
void ReadFromStream ()
 
- Protected Member Functions inherited from psi::PsiStreamBase< std::istream >
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::istream >
std::stringstream Buffer_
 This is where each MPI task ultimately writes from or to. More...
 
std::shared_ptr< std::istream > Stream_
 The actual stream. More...
 
- Private Member Functions inherited from psi::PsiFileImpl< std::ifstream >
 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 parallel (pun intended) of OutFile, except it reads files in.

As of right now the way to read data out of this file is via something
like:
* InFile MyFile("MyAwesomeFile.txt");
* while((bool)MyFile){
* std::string token;
* MyFile>>token;
* //Do stuff with token
* }
*

Note: Stuff comes out of MyFile as whatever type token is, so if, for example, you were reading integers declare token as an int. Of course this means you need to know the format of your file, but heck, how else did you plan on reading it?

You want something else? Code it (or buy Ryan a six-pack of Dortmunder Gold)

Member Typedef Documentation

typedef PsiFileImpl<std::ifstream> psi::InFile::FileBase
private

Convient typedef of the FileBase.

Constructor & Destructor Documentation

psi::InFile::InFile ( const std::string &  filename = "",
const FileMode mode = NOFILEMODE 
)

Constructor that opens a file with name "filename".

Upon construction passes NULL to base, so that the pointer is not set to cin. This avoids free-ing cin in the Open call. By default no file is opened, but supplying a filename will open that file at the beginning 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::InFile::~InFile ( )
inline

Calls Close to release memory.

Member Function Documentation

void psi::InFile::Close ( )
inline

Closes file and frees Stream_ pointer.

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

Opens "filename" in write mode "mode".

File contents are read from filename, and broadcast to all MPI processes and made available in Buffer_. Stream_ is then closed.


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