www.cemf.ir
processorOstream.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 #ifndef __processorOstream_hpp__
21 #define __processorOstream_hpp__
22 
23 #include "Ostream.hpp"
24 
25 namespace pFlow
26 {
27 
37 :
38  public Ostream
39 {
40 protected:
41 
43  bool printPrefix_ = false;
44 
46  word prefix_ = "";
47 
49  inline
51  {
52  if(printPrefix_ && prefix_.size())
53  {
54  Ostream::write(prefix_.c_str());
55  printPrefix_ = false;
56  }
57  }
58 
59 public:
60 
62 
64  processorOstream(std::ostream& os, const word& streamName);
65 
67  processorOstream(const processorOstream&) = delete;
68 
70  void operator=(const processorOstream&) = delete;
71 
72 
74 
76  word setPrefixNum(int procNum)
77  {
78  prefix_ = word("[")+int322Word(procNum)+word("] ");
79  return prefix_;
80  }
81 
84  {
85  printPrefix_ = true;
86  }
87 
90  bool write(const token& tok)
91  // to prevent compiler warning, this method is overriden agian
92  {
93  return Ostream::write(tok);
94  }
95 
97  iOstream& write(const char c)override;
98 
100  iOstream& write(const char* str)override;
101 
103  iOstream& write(const word& str)override;
104 
106  // Optional write without quotes.
107  iOstream& writeQuoted ( const word& str, const bool quoted=true ) override;
108 
110  iOstream& write(const int64 val) override;
111 
113  iOstream& write(const int32 val) override;
114 
116  iOstream& write(const int8 val) override;
117 
119  iOstream& write(const uint64 val) override;
120 
122  iOstream& write(const uint32 val) override;
123 
125  iOstream& write(const uint8 val) override;
126 
128  iOstream& write(const float val) override;
129 
131  iOstream& write(const double val) override;
132 
134  iOstream& write(const size_t val) override;
135 
137  iOstream& write(const char* binaryData, std::streamsize count) override;
138 
140  void indent() override;
141 
142  processorOstream& setColor(const char* colorCode);
143 
144 
145 }; // processorOstream
146 
147 
148 
149 } // pFlow
150 
151 
152 #endif // __processorOstream_hpp__
Ostream.hpp
pFlow::processorOstream::activatePrefix
void activatePrefix()
Activate prefix for this stream.
Definition: processorOstream.hpp:83
pFlow::token
Token class based on OpenFOAM stream, with some modifications/simplifications to be tailored to our n...
Definition: token.hpp:44
pFlow::processorOstream::write
bool write(const token &tok)
Write token to stream or otherwise handle it.
Definition: processorOstream.hpp:90
pFlow::processorOstream::setColor
processorOstream & setColor(const char *colorCode)
Definition: processorOstream.cpp:160
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::processorOstream
Output stream for MPI parallel run, when we need to know which the processor number in the output lin...
Definition: processorOstream.hpp:36
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:52
pFlow::processorOstream::operator=
void operator=(const processorOstream &)=delete
No copy assignment.
pFlow
Definition: demGeometry.hpp:27
pFlow::processorOstream::prefix_
word prefix_
Prefix word
Definition: processorOstream.hpp:46
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::processorOstream::checkForPrefix
void checkForPrefix()
Output the prefix if required.
Definition: processorOstream.hpp:50
pFlow::processorOstream::processorOstream
processorOstream(std::ostream &os, const word &streamName)
From components.
Definition: processorOstream.cpp:28
pFlow::count
auto count(const Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:26
pFlow::processorOstream::indent
void indent() override
Add indentation characters.
Definition: processorOstream.cpp:154
pFlow::processorOstream::writeQuoted
iOstream & writeQuoted(const word &str, const bool quoted=true) override
Write std::string surrounded by quotes.
Definition: processorOstream.cpp:75
pFlow::processorOstream::setPrefixNum
word setPrefixNum(int procNum)
Set processor number to be used in the prefix.
Definition: processorOstream.hpp:76
pFlow::processorOstream::printPrefix_
bool printPrefix_
Print prefix?
Definition: processorOstream.hpp:43
pFlow::uint64
unsigned long long int uint64
Definition: builtinTypes.hpp:58
pFlow::int8
signed char int8
Definition: builtinTypes.hpp:48
pFlow::int322Word
word int322Word(const int32 &v)
Convert int32 to word.
Definition: bTypesFunctions.cpp:110
pFlow::Ostream::write
bool write(const token &tok) override
Write token to stream or otherwise handle it.
Definition: Ostream.cpp:51
pFlow::Ostream
Standard output stream for BINARY and ASCII formats.
Definition: Ostream.hpp:39
pFlow::uint8
unsigned char uint8
Definition: builtinTypes.hpp:54
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59