genericRagelLemonDriver.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2019 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
29#include "string.H"
30#include "error.H"
31
32// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33
35:
36 content_(std::cref<std::string>(Foam::string::null)),
37 start_(0),
38 length_(0),
39 position_(0)
40{}
41
42
43// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
44
46{
47 content_ = std::cref<std::string>(Foam::string::null);
48 start_ = 0;
49 length_ = 0;
50 position_ = 0;
51}
52
53
55(
56 const std::string& s,
57 size_t pos,
58 size_t len
59)
60{
61 content_ = std::cref<std::string>(s);
62 start_ = pos;
63 length_ = len;
64 position_ = 0;
65}
66
67
68std::string::const_iterator
70{
71 const std::string& s = content_.get();
72
73 if (start_ >= s.length())
74 {
75 return s.cend();
76 }
77
78 return s.cbegin() + start_;
79}
80
81
82std::string::const_iterator
84{
85 const std::string& s = content_.get();
86
87 if (length_ == std::string::npos || start_ >= s.length())
88 {
89 return s.cend();
90 }
91
92 const size_t strEnd = start_ + length_;
93
94 if (strEnd >= s.length())
95 {
96 return s.cend();
97 }
98
99 return s.cbegin() + strEnd;
100}
101
102
104(
105 Ostream& os
106) const
107{
108 const auto endIter = cend();
109
110 for (auto iter = cbegin(); iter != endIter; ++iter)
111 {
112 char c(*iter);
113
114 // if (!c) break;
115
116 if (c == '\t')
117 {
118 // Flatten tab to single space for better alignment
119 os << ' ';
120 }
121 else
122 {
123 os << c;
124 }
125 }
126
127 return os;
128}
129
130
132(
133 const std::string& msg
134) const
135{
136 if (position_)
137 {
138 reportFatal(msg, position_);
139 }
140 else
141 {
142 auto& os = FatalIOError
143 (
145 __FILE__,
146 __LINE__,
147 ""
148 );
149
150 os << nl << msg.c_str() << " in expression\n"
151 << "<<<<\n";
152
153 printBuffer(os)
154 << "\n>>>>\n"
156 }
157}
158
159
161(
162 const std::string& msg,
163 size_t pos
164) const
165{
166 auto& os = Foam::FatalIOError
167 (
169 __FILE__,
170 __LINE__,
171 ""
172 );
173
174 os << nl << msg.c_str()
175 << " in expression at position:" << long(pos) << nl
176 << "<<<<\n";
177
178 const auto begIter = cbegin();
179 const auto endIter = cend();
180
181 // Position of newline(s)
182 size_t newline0 = 0, newline1 = 0;
183
184 auto iter = begIter;
185
186 for (/*nil*/; iter != endIter; ++iter)
187 {
188 char c(*iter);
189
190 if ('\t' == c)
191 {
192 // Flatten tab to single space for better alignment
193 os << ' ';
194 }
195 else if ('\n' == c)
196 {
197 os << c;
198
199 newline1 = (iter-begIter);
200
201 if (newline1 < pos)
202 {
203 newline0 = newline1;
204 }
205 else
206 {
207 ++iter;
208 break;
209 }
210 }
211 else
212 {
213 os << c;
214 }
215 }
216
217 if (newline0 == newline1 || newline1 == pos)
218 {
219 os << '\n';
220 }
221
222 size_t col = std::min(newline0, newline1);
223 if (col < pos)
224 {
225 // This still isn't quite right
226 col = pos - col;
227 if (col) --col;
228
229 for (/*nil*/; col; --col)
230 {
231 os << ' ';
232 }
233 }
234
235 os << "^^^^ near here\n";
236
237 // Finish output
238 for (/*nil*/; iter != endIter; ++iter)
239 {
240 char c(*iter);
241
242 if ('\t' == c)
243 {
244 // Flatten tab to single space for better alignment
245 os << ' ';
246 }
247 else
248 {
249 os << c;
250 }
251 }
252
253 os << "\n>>>>\n"
255}
256
257
258// ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
std::string::const_iterator cend() const
Iterator to end of content (sub)string.
std::string::const_iterator cbegin() const
Iterator to begin of content (sub)string.
const std::string & content() const
Get reference to the input buffer content.
void reportFatal(const std::string &msg) const
Report FatalError.
Ostream & printBuffer(Ostream &os) const
Output the input buffer string content.
A class for handling character strings derived from std::string.
Definition: string.H:79
OBJstream os(runTime.globalPath()/outputName)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
#define FUNCTION_NAME
Namespace for OpenFOAM.
dimensionedScalar pos(const dimensionedScalar &ds)
IOerror FatalIOError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53