blockMeshToolsTemplates.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) 2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
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 
28 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
30 template<class T>
32 (
33  Istream& is,
34  List<T>& L,
35  const dictionary& dict
36 )
37 {
38  token firstToken(is);
39 
40  if (firstToken.isLabel())
41  {
42  const label s = firstToken.labelToken();
43 
44  // Set list length to that read
45  L.setSize(s);
46 
47  // Read beginning of contents
48  const char delimiter = is.readBeginList("List");
49 
50  if (s)
51  {
52  if (delimiter == token::BEGIN_LIST)
53  {
54  for (label i=0; i<s; ++i)
55  {
56  read(is, L[i], dict);
57  }
58  }
59  }
60 
61  // Read end of contents
62  is.readEndList("List");
63  }
64  else if (firstToken.isPunctuation())
65  {
66  if (firstToken.pToken() != token::BEGIN_LIST)
67  {
69  << "incorrect first token, expected '(', found "
70  << firstToken.info()
71  << exit(FatalIOError);
72  }
73 
74  SLList<T> sll;
75 
76  while (true)
77  {
78  token t(is);
79  if (t.isPunctuation() && t.pToken() == token::END_LIST)
80  {
81  break;
82  }
83  is.putBack(t);
84  T elem;
85  read(is, elem, dict);
86  sll.append(elem);
87  }
88 
89  // Convert the singly-linked list to this list
90  L = sll;
91  }
92  else
93  {
95  << "incorrect first token, expected <int> or '(', found "
96  << firstToken.info()
97  << exit(FatalIOError);
98  }
99 }
100 
101 
102 template<class T>
104 (
105  Istream& is,
106  const dictionary& dict
107 )
108 {
109  List<T> L;
110  read(is, L, dict);
111  return L;
112 }
113 
114 
115 // ************************************************************************* //
Foam::LList::append
void append(const T &item)
Add copy at tail of list.
Definition: LList.H:237
L
const vector L(dict.get< vector >("L"))
Foam::token::labelToken
label labelToken() const
Return label value.
Definition: tokenI.H:487
Foam::token::isLabel
bool isLabel() const noexcept
Token is LABEL.
Definition: tokenI.H:481
s
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))
Definition: gmvOutputSpray.H:25
Foam::Istream::readBeginList
char readBeginList(const char *funcName)
Begin read of list data, starts with '(' or '{'.
Definition: Istream.C:146
Foam::Istream::readEndList
char readEndList(const char *funcName)
End read of list data, ends with ')' or '}'.
Definition: Istream.C:167
Foam::FatalIOError
IOerror FatalIOError
Foam::token
A token holds an item read from Istream.
Definition: token.H:68
Foam::token::pToken
punctuationToken pToken() const
Return punctuation character.
Definition: tokenI.H:459
Foam::LList
Template class for non-intrusive linked lists.
Definition: LList.H:54
Foam::token::info
InfoProxy< token > info() const
Return info proxy for printing token information to a stream.
Definition: token.H:551
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::token::isPunctuation
bool isPunctuation() const noexcept
Token is PUNCTUATION.
Definition: tokenI.H:453
Foam::blockMeshTools::read
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:33
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
T
const volScalarField & T
Definition: createFieldRefs.H:2
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::Istream::putBack
void putBack(const token &tok)
Put back token.
Definition: Istream.C:53
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401