blockMeshToolsTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
27 
28 template<class T>
30 (
31  Istream& is,
32  List<T>& L,
33  const dictionary& dict
34 )
35 {
36  token firstToken(is);
37 
38  if (firstToken.isLabel())
39  {
40  label s = firstToken.labelToken();
41 
42  // Set list length to that read
43  L.setSize(s);
44 
45  // Read list contents depending on data format
46 
47  // Read beginning of contents
48  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 // ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
char readEndList(const char *funcName)
Definition: Istream.C:148
char readBeginList(const char *funcName)
Definition: Istream.C:127
void putBack(const token &)
Put back token.
Definition: Istream.C:30
Template class for non-intrusive linked lists.
Definition: LList.H:76
void append(const T &a)
Add at tail of list.
Definition: LList.H:172
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
void setSize(const label)
Reset size of List.
Definition: List.C:281
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
A token holds items read from Istream.
Definition: token.H:73
bool isLabel() const
Definition: tokenI.H:392
bool isPunctuation() const
Definition: tokenI.H:243
punctuationToken pToken() const
Definition: tokenI.H:248
label labelToken() const
Definition: tokenI.H:397
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:391
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
IOerror FatalIOError
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
dictionary dict