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