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

Specialization of PsiStream to output streams. More...

#include <PsiOutStream.h>

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

Public Member Functions

 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 PsiStreamBase
< std::ostream > 
BaseType
 

Private Member Functions

void Buffer2Stream ()
 Dumps Buffer to Stream_. More...
 
template<typename T >
std::ostream & Write2Buffer (const T &Input)
 This is the interface for Printf and << operator to Buffer_ for most writable objects. More...
 
std::ostream & Write2Buffer (StreamManips fp)
 This is the interface for Printf and << operator to Buffer_ for special iostream functions. More...
 

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...
 

Detailed Description

Specialization of PsiStream to output streams.

Member Typedef Documentation

typedef PsiStreamBase<std::ostream> psi::PsiOutStream::BaseType
private

Constructor & Destructor Documentation

psi::PsiOutStream::PsiOutStream ( SharedOutStream  Stream = SharedOutStream())

Makes an OutStreamBase that defaults to std::cout.

psi::PsiOutStream::PsiOutStream ( const PsiOutStream other)
inline

Creates this by copying other, via base copy constructor.

virtual psi::PsiOutStream::~PsiOutStream ( )
inlinevirtual

No memory to free up (we don't delete cout or cerr)

Member Function Documentation

void psi::PsiOutStream::Buffer2Stream ( )
private

Dumps Buffer to Stream_.

void psi::PsiOutStream::Flush ( )
inline

Flushes the Stream.

void psi::PsiOutStream::MakeBanner ( const std::string &  message,
const char  delimiter = '*',
const int  width = 80 
)

Makes a banner.

Parameters
[in]messageThe message that will go in the banner
[in]delimiterThe character that will comprise the banner
[in]widthThe number of characters wide the banner will be

Let's say you want to print "Hello World!" in a banner comprised of '*' characters, and for simplicity (your banner should be 80 chars long) you only wanted a 16 character long banner. If you passed message="Hello World!",delimiter='*', and width=16, you would get (hopefully you are viewing this in a monospaced font):

0123456789ABCDEF


  • Hello World! *

where if you didn't guess the columns are labeled in hexadecimal, so that they are all single characters. For the time being your message must be width-6 characters or shorter because I have mandated that at least one delimiter is printed on each side plus two spaces between that delimiter and the actual message. The remaining space will be filled by delimiters. Consequentially, this means your message must fit on one line. This could of course be remedied by splitting the message across multiple lines, but I'm lazy.

template<typename T >
std::ostream& psi::PsiOutStream::operator<< ( const T Input)
inline

Allows c++ like interface for most objects.

std::ostream& psi::PsiOutStream::operator<< ( StreamManips  fp)
inline

Allows c++ like interface for things like std::endl.

const PsiOutStream& psi::PsiOutStream::operator= ( const PsiOutStream other)
inline

Allows assignment of other to this, calls base assignment.

void psi::PsiOutStream::Printf ( const char *  format,
  ... 
)

Allows printf (or fprintf) like syntax to this object.

This function takes your format stream and converts it to a 1,000 character MAXIMUM char* array. That array is then passed to Buffer_. If the current MPI process is rank 0 on MPI_COMM_WORLD, Buffer_ is then written to Stream_. No locks should be used around your Printf statements, nor is flushing needed. For reference the accepted format flags are (stolen from cplusplus.com):

%[flags][width][.precision][length]specifier

specifier Output d or i Signed decimal integer u Unsigned decimal integer o Unsigned octal integer x Unsigned hexadecimal integer X Unsigned hexadecimal integer (uppercase) f Decimal floating point, lowercase F Decimal floating point, uppercase e Scientific notation (mantissa/exponent), lowercase E Scientific notation (mantissa/exponent), uppercase g Use the shortest representation: e or f G Use the shortest representation: E or F a Hexadecimal floating point, lowercase A Hexadecimal floating point, uppercase c Character s String of characters p Pointer address n Nothing printed

Parameters
[in]formatThe message plus format codes you want to pass
[in]...The arguments for each format code given in "format"
template<typename T >
std::ostream & psi::PsiOutStream::Write2Buffer ( const T Input)
private

This is the interface for Printf and << operator to Buffer_ for most writable objects.

Parameters
[in]InputAn object that can be passed to an ostream
std::ostream & psi::PsiOutStream::Write2Buffer ( StreamManips  fp)
private

This is the interface for Printf and << operator to Buffer_ for special iostream functions.

Parameters
[in]fpiostream functions like std::endl

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