www.cemf.ir
iOstream.cpp
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 
21 
22 #include "iOstream.hpp"
23 #include "token.hpp"
24 #include "error.hpp"
25 
26 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
27 
29 {
31  return *this;
32 }
33 
35 {
36  if (!indentLevel_)
37  {
38  std::cerr
39  << "iOstream::decrIndent() : attempt to decrement 0 indent level\n";
40  }
41  else
42  {
43  --indentLevel_;
44  }
45 }
46 
47 
49 {
50 
51  indent();
52  writeQuoted(kw, false);
53 
54  if (indentSize_ <= 1)
55  {
56  write(char(token::SPACE));
57  return *this;
58  }
59 
60  int32 nSpaces = entryIndentation_ - int32(kw.size());
61 
62  // Could also increment by indentSize_ ...
63  if (nSpaces < 1)
64  {
65  nSpaces = 1;
66  }
67 
68  while (nSpaces--)
69  {
70  write(char(token::SPACE));
71  }
72 
73  return *this;
74 }
75 
76 
78 {
79  indent(); write(kw); newLine();
80  beginBlock();
81 
82  return *this;
83 }
84 
85 
87 {
88  indent(); write(char(token::BEGIN_BLOCK)); newLine();
89  incrIndent();
90 
91  return *this;
92 }
93 
94 
96 {
97  decrIndent();
98  indent(); write(char(token::END_BLOCK)); newLine();
99 
100  return *this;
101 }
102 
103 
105 {
106  write(char(token::END_STATEMENT)); newLine();
107 
108  return *this;
109 }
110 
111 //- Write a newLine to stream
113 {
114  write(char(token::NL));
115  return *this;
116 }
117 
119 (
120  int32 n
121 )
122 {
123  for(int32 i=0; i<n; i++)
124  {
125  write(char(token::SPACE));
126  }
127  return *this;
128 }
129 
130 
132 (
133 )
134 {
135  write(char(token::BEGIN_LIST));
136  return *this;
137 }
138 
139 
141 (
142  const word& kw
143 )
144 {
145  writeWordKeyword(kw); beginList();
146  return *this;
147 }
148 
149 
151 (
152 )
153 {
154  write(char(token::END_LIST));
155  return *this;
156 }
157 
158 
160 (
161 )
162 {
163  write(char(token::BEGIN_SQR));
164  return *this;
165 }
166 
167 
169 (
170  const word& kw
171 )
172 {
173  writeWordKeyword(kw); beginSquare();
174  return *this;
175 }
176 
177 
179 (
180 )
181 {
182  write(char(token::END_SQR));
183  return *this;
184 }
185 
186 
187 // ************************************************************************* //
notImplementedFunction
#define notImplementedFunction
Report that a function is yet not implemented.
Definition: error.hpp:84
pFlow::iOstream::endBlock
virtual iOstream & endBlock()
Write end block group Decrements indentation, adds newline.
Definition: iOstream.cpp:95
pFlow::iOstream::newLine
virtual iOstream & newLine()
Write a newLine to stream.
Definition: iOstream.cpp:112
pFlow::token::END_BLOCK
@ END_BLOCK
Begin block [isseparator].
Definition: token.hpp:96
token.hpp
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::token::NL
@ NL
Tab [isspace].
Definition: token.hpp:88
pFlow::decrIndent
iOstream & decrIndent(iOstream &os)
Decrement the indent level.
Definition: iOstream.hpp:325
pFlow::token::BEGIN_BLOCK
@ BEGIN_BLOCK
End dimensions [isseparator].
Definition: token.hpp:95
pFlow::token::SPACE
@ SPACE
Nul character.
Definition: token.hpp:86
pFlow::indent
iOstream & indent(iOstream &os)
Indent stream.
Definition: iOstream.hpp:311
pFlow::iOstream::decrIndent
void decrIndent()
Decrement the indent level.
Definition: iOstream.cpp:34
pFlow::incrIndent
iOstream & incrIndent(iOstream &os)
Increment the indent level.
Definition: iOstream.hpp:318
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::iOstream::beginSquare
virtual iOstream & beginSquare()
Write begin list "[".
Definition: iOstream.cpp:160
pFlow::iOstream::endEntry
virtual iOstream & endEntry()
Write end entry (';') followed by newline.
Definition: iOstream.cpp:104
pFlow::token::END_LIST
@ END_LIST
Begin list [isseparator].
Definition: token.hpp:92
pFlow::token::END_STATEMENT
@ END_STATEMENT
Newline [isspace].
Definition: token.hpp:90
n
uint32 n
Definition: NBSLoop.hpp:24
pFlow::token::BEGIN_LIST
@ BEGIN_LIST
End entry [isseparator].
Definition: token.hpp:91
pFlow::iOstream::endSquare
virtual iOstream & endSquare()
Write end list "]".
Definition: iOstream.cpp:179
pFlow::token::BEGIN_SQR
@ BEGIN_SQR
End list [isseparator].
Definition: token.hpp:93
pFlow::iOstream::endList
virtual iOstream & endList()
Write end list ")".
Definition: iOstream.cpp:151
pFlow::beginBlock
iOstream & beginBlock(iOstream &os)
Write begin block group without a name.
Definition: iOstream.hpp:350
pFlow::iOstream::beginList
virtual iOstream & beginList()
Write begin list "(".
Definition: iOstream.cpp:132
pFlow::iOstream::writeBinaryBlockFlag
virtual iOstream & writeBinaryBlockFlag()
Write the flag to indicate the start of a binary block.
Definition: iOstream.cpp:28
iOstream.hpp
pFlow::iOstream::space
virtual iOstream & space(int32 n=1)
Write space to stream.
Definition: iOstream.cpp:119
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::token::END_SQR
@ END_SQR
Begin dimensions [isseparator].
Definition: token.hpp:94
pFlow::iOstream::writeWordKeyword
virtual iOstream & writeWordKeyword(const word &kw)
Write the keyword followed by an appropriate indentation.
Definition: iOstream.cpp:48
pFlow::iOstream::beginBlock
virtual iOstream & beginBlock()
Write begin block group without a name Increments indentation, adds newline.
Definition: iOstream.cpp:86
error.hpp