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  Copyright (C) 2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
31 template<class T>
33 (
34  Istream& is,
35  List<T>& list,
36  const dictionary& dict
37 )
38 {
39  token tok(is);
40 
41  if (tok.isLabel())
42  {
43  const label len = tok.labelToken();
44 
45  // Set list length to that read
46  list.resize(len);
47 
48  // Read beginning of contents
49  const char delimiter = is.readBeginList("List");
50 
51  if (len)
52  {
53  if (delimiter == token::BEGIN_LIST)
54  {
55  for (label i=0; i<len; ++i)
56  {
57  read(is, list[i], dict);
58  }
59  }
60  }
61 
62  // Read end of contents
63  is.readEndList("List");
64  }
65  else if (tok.isPunctuation(token::BEGIN_LIST))
66  {
67  SLList<T> sll;
68 
69  is >> tok;
71 
72  while (!tok.isPunctuation(token::END_LIST))
73  {
74  is.putBack(tok);
75 
76  T elem;
77  read(is, elem, dict);
78  sll.append(elem);
79 
80  is >> tok;
82  }
83 
84  // Convert the singly-linked list to this list
85  list = std::move(sll);
86  }
87  else
88  {
90  << "incorrect first token, expected <int> or '(', found "
91  << tok.info() << nl
92  << exit(FatalIOError);
93  }
94 }
95 
96 
97 template<class T>
99 (
100  Istream& is,
101  const dictionary& dict
102 )
103 {
104  List<T> list;
105  read(is, list, dict);
106  return list;
107 }
108 
109 
110 // ************************************************************************* //
Foam::LList::append
void append(const T &item)
Add copy at tail of list.
Definition: LList.H:237
Foam::token::labelToken
label labelToken() const
Return label value.
Definition: tokenI.H:513
Foam::token::isLabel
bool isLabel() const noexcept
Token is LABEL.
Definition: tokenI.H:497
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
Foam::Istream::readBeginList
char readBeginList(const char *funcName)
Begin read of list data, starts with '(' or '{'.
Definition: Istream.C:148
Foam::IOstream::fatalCheck
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:64
Foam::Istream::readEndList
char readEndList(const char *funcName)
End read of list data, ends with ')' or '}'.
Definition: Istream.C:169
Foam::FatalIOError
IOerror FatalIOError
Foam::token
A token holds an item read from Istream.
Definition: token.H:68
Foam::LList
Template class for non-intrusive linked lists.
Definition: LList.H:54
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
Foam::token::info
InfoProxy< token > info() const
Return info proxy for printing token information to a stream.
Definition: token.H:586
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:459
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:123
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::nl
constexpr char nl
Definition: Ostream.H:404
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 a token. Only a single put back is permitted.
Definition: Istream.C:70
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473