Psi4
StreamBase.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 STREAMBASE_H_
28 #define STREAMBASE_H_
29 #include<iostream>
30 #include<sstream>
31 #include<map>
32 #include<memory>
33 #include "BasesBase.h"
34 //This is the signature of std::endl and other sorts of iomanip things
35 typedef std::ostream& (*StreamManips)(std::ostream&);
36 
38 typedef std::shared_ptr<std::ostream> SharedOutStream;
39 
41 typedef std::shared_ptr<std::istream> SharedInStream;
42 
43 
44 
45 namespace psi{
57 template <typename T>
58 class PsiStreamBase:public BasesBase{
59  private:
61 
63  void Clone(const MyType& other){
64  this->Buffer_.str(other.Buffer_.str());
65  this->Stream_=other.Stream_;
66  }
67 
68 
69  protected:
71  std::stringstream Buffer_;
72 
74  std::shared_ptr<T> Stream_;
75 
77  void EmptyBuffer(){
78  Buffer_.str("");
79  Buffer_.clear();
80  }
81 
82  public:
83 
85  PsiStreamBase<T>(const MyType& other){this->Clone(other);}
86 
88  const MyType& operator=(const MyType& other){
89  if(this!=&other)this->Clone(other);
90  return *this;
91  }
92 
95 
97  virtual ~PsiStreamBase<T>(){}
98 };
99 }//End psi namespace
100 #endif /* STREAMBASE_H_ */
void Clone(const MyType &other)
Makes this a copy of other, copies data in Buffer_, not &amp;Buffer.
Definition: StreamBase.h:63
std::shared_ptr< T > Stream_
The actual stream.
Definition: StreamBase.h:74
std::shared_ptr< std::istream > SharedInStream
A shared input stream.
Definition: StreamBase.h:41
std::stringstream Buffer_
This is where each MPI task ultimately writes from or to.
Definition: StreamBase.h:71
const MyType & operator=(const MyType &other)
Calls Clone for assignment iff this!=&amp;other, returns *this.
Definition: StreamBase.h:88
I needed to syphon off the calls that involve Worldcomm, hence this class.
Definition: BasesBase.h:32
The base class for Psi4&#39;s new parallel safe printing system.
Definition: StreamBase.h:58
void EmptyBuffer()
I always forget how to empty a stringstream.
Definition: StreamBase.h:77
PsiStreamBase< T > MyType
Definition: StreamBase.h:60
std::shared_ptr< std::ostream > SharedOutStream
A shared output stream.
Definition: StreamBase.h:38