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);
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  virtual bool write(const token& tok)override;
79 
80  //- Write character
81  virtual iOstream& write(const char c)override;
82 
83  //- Write character string
84  virtual iOstream& write(const char* str)override;
85 
86  //- Write word
87  virtual iOstream& write(const word& str)override;
88 
89  //- Write std::string surrounded by quotes.
90  // Optional write without quotes.
91  virtual iOstream& writeQuoted ( const word& str, const bool quoted=true )override;
92 
93  //- Write int64
94  virtual iOstream& write(const int64 val) override;
95 
96  //- Write int32
97  virtual iOstream& write(const int32 val) override;
98 
99 
100  //- Write label
101  virtual iOstream& write(const label val) override;
102 
103  //- Write uint32
104  virtual iOstream& write(const uint32 val) override;
105 
106  //- Write uint16
107  virtual iOstream& write(const uint16 val) override;
108 
109  //- Write float
110  virtual iOstream& write(const float val) override;
111 
112  //- Write double
113  virtual iOstream& write(const double val) override;
114 
115  //- Add indentation characters
116  virtual void indent();
117 
118 
119  //- Set stream flags
120  virtual ios_base::fmtflags flags(const ios_base::fmtflags f);
121 
122  //- Flush stream
123  virtual void flush();
124 
125  //- Add newline and flush stream
126  virtual void endl();
127 
128  //- Get the current padding character
129  virtual char fill() const;
130 
131  //- Set padding character for formatted field up to field width
132  // \return previous padding character
133  virtual char fill(const char fillch);
134 
135  //- Get width of output field
136  virtual int width() const;
137 
138  //- Set width of output field
139  // \return previous width
140  virtual int width(const int w);
141 
142  //- Get precision of output field
143  virtual int precision() const;
144 
145  //- Set precision of output field
146  // return old precision
147  virtual int precision(const int p);
148 
149  //- Access to underlying std::ostream
150  virtual std::ostream& stdStream()
151  {
152  return os_;
153  }
154 
155  //- Const access to underlying std::ostream
156  virtual const std::ostream& stdStream() const
157  {
158  return os_;
159  }
160 
161 };
162 
163 
164 
165 } // pFlow
166 
167 
168 #endif
169 
170 
pFlow::Ostream::writeQuoted
virtual iOstream & writeQuoted(const word &str, const bool quoted=true) override
Definition: Ostream.cpp:109
pFlow::Ostream::flush
virtual void flush()
Definition: Ostream.cpp:244
pFlow::Ostream::flags
virtual ios_base::fmtflags flags() const
Definition: Ostream.cpp:257
pFlow::Ostream::operator=
void operator=(const Ostream &)=delete
pFlow::Ostream::endl
virtual void endl()
Definition: Ostream.cpp:250
pFlow::token
Definition: token.hpp:42
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:55
pFlow::Ostream::name_
word name_
Definition: Ostream.hpp:40
pFlow
Definition: demComponent.hpp:28
pFlow::Ostream::name
virtual word & name()
Definition: Ostream.hpp:67
pFlow::Ostream::precision
virtual int precision() const
Definition: Ostream.cpp:295
pFlow::Ostream::name
virtual const word & name() const
Definition: Ostream.hpp:61
pFlow::uint16
unsigned short int uint16
Definition: builtinTypes.hpp:57
pFlow::Ostream::Ostream
Ostream(std::ostream &os, const word &streamName)
Definition: Ostream.cpp:29
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::Ostream::width
virtual int width() const
Definition: Ostream.cpp:283
pFlow::Ostream::stdStream
virtual std::ostream & stdStream()
Definition: Ostream.hpp:150
pFlow::Ostream::fill
virtual char fill() const
Definition: Ostream.cpp:271
pFlow::Ostream::os_
std::ostream & os_
Definition: Ostream.hpp:42
pFlow::Ostream::indent
virtual void indent()
Definition: Ostream.cpp:235
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
iOstream.hpp
pFlow::Ostream::write
virtual bool write(const token &tok) override
Definition: Ostream.cpp:52
pFlow::Ostream::stdStream
virtual const std::ostream & stdStream() const
Definition: Ostream.hpp:156
pFlow::Ostream
Definition: Ostream.hpp:35
pFlow::iOstream
Definition: iOstream.hpp:53