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