Psi4
PsiOutStream.h
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Psi4: an open-source quantum chemistry software package
5  *
6  * Copyright (c) 2007-2017 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This file is part of Psi4.
12  *
13  * Psi4 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation, version 3.
16  *
17  * Psi4 is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License along
23  * with Psi4; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * @END LICENSE
27  */
28 #ifndef PSIOUTSTREAM_H_
29 #define PSIOUTSTREAM_H_
30 
31 #include "StreamBase.h"
32 
33 namespace psi{
34 
36 class PsiOutStream:public PsiStreamBase<std::ostream>{
37  private:
39 
41  void Buffer2Stream();
42 
48  template<typename T>
49  std::ostream& Write2Buffer(const T& Input);
50 
56  std::ostream& Write2Buffer(StreamManips fp);
57 
58  public:
59 
62 
64  PsiOutStream(const PsiOutStream& other):BaseType(other){}
65 
67  const PsiOutStream& operator=(const PsiOutStream& other){
68  BaseType::operator=(other);
69  return *this;
70  }
71 
73  virtual ~PsiOutStream(){}
74 
76  void Flush(){
77  if(this->ImSpecial()){
78  Stream_->flush();
79  }
80  }
81 
117  void Printf(const char* format,...);
118 
120  template<typename T>
121  std::ostream& operator<<(const T& Input){return Write2Buffer(Input);}
122 
124  std::ostream& operator<<(StreamManips fp){return Write2Buffer(fp);}
125 
156  void MakeBanner(const std::string& message, const char delimiter='*', const
157  int width=80);
158 };
159 
160 
161 template<typename T>
162 std::ostream& PsiOutStream::Write2Buffer(const T& Input){
163  Buffer_<<Input;
164  this->Buffer2Stream();
165  return Buffer_;
166 }
167 
168 }//End namespace
169 
170 
171 
172 #endif /* PSIOUTSTREAM_H_ */
bool ImSpecial() const
Returns true if this is the lucky MPI process that gets to read/write.
Definition: BasesBase.cc:45
std::shared_ptr< std::ostream > Stream_
The actual stream.
Definition: StreamBase.h:75
std::ostream & operator<<(const T &Input)
Allows c++ like interface for most objects.
Definition: PsiOutStream.h:121
PsiOutStream(SharedOutStream Stream=SharedOutStream())
Makes an OutStreamBase that defaults to std::cout.
Definition: PsiOutStream.cc:68
std::ostream &(* StreamManips)(std::ostream &)
Definition: StreamBase.h:36
virtual ~PsiOutStream()
No memory to free up (we don&#39;t delete cout or cerr)
Definition: PsiOutStream.h:73
PsiStreamBase< std::ostream > BaseType
Definition: PsiOutStream.h:38
std::ostream & operator<<(StreamManips fp)
Allows c++ like interface for things like std::endl.
Definition: PsiOutStream.h:124
std::stringstream Buffer_
This is where each MPI task ultimately writes from or to.
Definition: StreamBase.h:72
PsiOutStream(const PsiOutStream &other)
Creates this by copying other, via base copy constructor.
Definition: PsiOutStream.h:64
const PsiOutStream & operator=(const PsiOutStream &other)
Allows assignment of other to this, calls base assignment.
Definition: PsiOutStream.h:67
void Buffer2Stream()
Dumps Buffer to Stream_.
Definition: PsiOutStream.cc:37
Specialization of PsiStream to output streams.
Definition: PsiOutStream.h:36
const MyType & operator=(const MyType &other)
Calls Clone for assignment iff this!=&amp;other, returns *this.
Definition: StreamBase.h:89
void Printf(const char *format,...)
Allows printf (or fprintf) like syntax to this object.
Definition: PsiOutStream.cc:75
The base class for Psi4&#39;s new parallel safe printing system.
Definition: StreamBase.h:59
void MakeBanner(const std::string &message, const char delimiter='*', const int width=80)
Makes a banner.
Definition: PsiOutStream.cc:46
std::ostream & Write2Buffer(const T &Input)
This is the interface for Printf and &lt;&lt; operator to Buffer_ for most writable objects.
Definition: PsiOutStream.h:162
void Flush()
Flushes the Stream.
Definition: PsiOutStream.h:76
Definition: PsiFileImpl.h:40
std::shared_ptr< std::ostream > SharedOutStream
A shared output stream.
Definition: StreamBase.h:39