Ostream.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 // based on OpenFOAM stream, with some modifications/simplifications
21 // to be tailored to our needs
22 
23 #ifndef __Ostream_hpp__
24 #define __Ostream_hpp__
25 
26 #include "iOstream.hpp"
27 #include <iostream>
28 
29 
30 namespace pFlow
31 {
32 
33 
34 
35 class Ostream
36 :
37  public iOstream
38 {
39 
41 
42  std::ostream& os_;
43 
44 
45 public:
46 
47  // Constructors
48 
49  Ostream ( std::ostream& os, const word& streamName, writeFormat wf = ASCII);
50 
51  //- no copy construct
52  Ostream(const Ostream&) = delete;
53 
54  //- No copy assignment
55  void operator=(const Ostream&) = delete;
56 
57 
59 
60  //- Return the name of the stream
61  virtual const word& name() const
62  {
63  return name_;
64  }
65 
66  //- Return non-const access to the name of the stream
67  virtual word& name()
68  {
69  return name_;
70  }
71 
72  //- Return flags of output stream
73  virtual ios_base::fmtflags flags() const;
74 
75 
76  //- Write token to stream or otherwise handle it.
77  // return false if the token type was not handled by this method
78  bool write(const token& tok)override;
79 
80  //- Write character
81  iOstream& write(const char c)override;
82 
83  //- Write character string
84  iOstream& write(const char* str)override;
85 
86  //- Write word
87  iOstream& write(const word& str)override;
88 
89  //- Write std::string surrounded by quotes.
90  // Optional write without quotes.
91  iOstream& writeQuoted ( const word& str, const bool quoted=true ) override;
92 
93  //- Write int64
94  iOstream& write(const int64 val) override;
95 
96  //- Write int32
97  iOstream& write(const int32 val) override;
98 
99  //- Write label
100  iOstream& write(const label val) override;
101 
102  //- Write uint32
103  iOstream& write(const uint32 val) override;
104 
105  //- Write uint16
106  iOstream& write(const uint16 val) override;
107 
108  //- Write float
109  iOstream& write(const float val) override;
110 
111  //- Write double
112  iOstream& write(const double val) override;
113 
115  iOstream& write(const char* binaryData, std::streamsize count) override;
116 
117  //- Add indentation characters
118  void indent() override;
119 
120  //- Set stream flags
121  ios_base::fmtflags flags(const ios_base::fmtflags f) override;
122 
123  //- Flush stream
124  void flush() override;
125 
126  //- Add newline and flush stream
127  void endl() override;
128 
129  //- Get the current padding character
130  char fill() const override;
131 
132  //- Set padding character for formatted field up to field width
133  // \return previous padding character
134  char fill(const char fillch) override;
135 
136  //- Get width of output field
137  int width() const override;
138 
139  //- Set width of output field
140  // \return previous width
141  int width(const int w) override;
142 
143  //- Get precision of output field
144  int precision() const override;
145 
146  //- Set precision of output field
147  // return old precision
148  int precision(const int p) override;
149 
150  //- Access to underlying std::ostream
151  virtual std::ostream& stdStream()
152  {
153  return os_;
154  }
155 
156  //- Const access to underlying std::ostream
157  virtual const std::ostream& stdStream() const
158  {
159  return os_;
160  }
161 
162 };
163 
164 
165 
166 } // pFlow
167 
168 
169 #endif
170 
171 
pFlow::Ostream::writeQuoted
iOstream & writeQuoted(const word &str, const bool quoted=true) override
Write std::string surrounded by quotes.
Definition: Ostream.cpp:110
pFlow::Ostream::flags
virtual ios_base::fmtflags flags() const
Return flags of stream.
Definition: Ostream.cpp:281
pFlow::Ostream::flush
void flush() override
Flush stream.
Definition: Ostream.cpp:268
pFlow::Ostream::operator=
void operator=(const Ostream &)=delete
pFlow::token
Definition: token.hpp:42
pFlow::IOstream::ASCII
@ ASCII
Definition: IOstream.hpp:59
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::Ostream::indent
void indent() override
Add indentation characters.
Definition: Ostream.cpp:259
pFlow::Ostream::width
int width() const override
Get width of output field.
Definition: Ostream.cpp:307
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:55
pFlow::Ostream::name_
word name_
Definition: Ostream.hpp:40
pFlow::Ostream::fill
char fill() const override
Get padding character.
Definition: Ostream.cpp:295
pFlow::Ostream::precision
int precision() const override
Get precision of output field.
Definition: Ostream.cpp:319
pFlow::Ostream::endl
void endl() override
Add newline and flush stream.
Definition: Ostream.cpp:274
pFlow
Definition: demComponent.hpp:28
pFlow::Ostream::name
virtual word & name()
Return non-const access to the name of the stream.
Definition: Ostream.hpp:67
pFlow::Ostream::name
virtual const word & name() const
Return the name of the stream.
Definition: Ostream.hpp:61
pFlow::uint16
unsigned short int uint16
Definition: builtinTypes.hpp:57
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::count
auto count(const Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:26
pFlow::Ostream::Ostream
Ostream(std::ostream &os, const word &streamName, writeFormat wf=ASCII)
Definition: Ostream.cpp:29
pFlow::Ostream::stdStream
virtual std::ostream & stdStream()
Definition: Ostream.hpp:151
pFlow::Ostream::os_
std::ostream & os_
Definition: Ostream.hpp:42
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
iOstream.hpp
pFlow::IOstream::writeFormat
writeFormat
Definition: IOstream.hpp:57
pFlow::Ostream::write
bool write(const token &tok) override
Write Functions.
Definition: Ostream.cpp:53
pFlow::Ostream::stdStream
virtual const std::ostream & stdStream() const
Definition: Ostream.hpp:157
pFlow::Ostream
Definition: Ostream.hpp:35
pFlow::iOstream
Definition: iOstream.hpp:53