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-2023 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  // Label: should be int(..)
44 
45  const label len = tok.labelToken();
46 
47  // Resize to length required
48  list.resize_nocopy(len);
49 
50  // Begin of contents marker
51  const char delimiter = is.readBeginList("List");
52 
53  if (len)
54  {
55  if (delimiter == token::BEGIN_LIST)
56  {
57  for (label i=0; i<len; ++i)
58  {
59  read(is, list[i], dict);
60  }
61  }
62  }
63 
64  // End of contents marker
65  is.readEndList("List");
66  }
67  else if (tok.isPunctuation(token::BEGIN_LIST))
68  {
69  // "(...)" : read with DynamicList and transfer contents
70 
71  DynamicList<T> elements(std::move(list));
72  elements.clear(); // Reset addressing only
73 
74  is >> tok;
76 
77  while (!tok.isPunctuation(token::END_LIST))
78  {
79  is.putBack(tok);
80 
81  read(is, elements.emplace_back(), dict);
82 
83  is >> tok;
85  }
86 
87  // Transfer back to regular list
88  list = std::move(elements);
89  }
90  else
91  {
93  << "incorrect first token, expected <int> or '(', found "
94  << tok.info() << nl
95  << exit(FatalIOError);
96  }
97 }
98 
99 
100 template<class T>
102 (
103  Istream& is,
104  const dictionary& dict
105 )
106 {
107  List<T> list;
108  read(is, list, dict);
109  return list;
110 }
111 
112 
113 // ************************************************************************* //
bool isPunctuation() const noexcept
Token is PUNCTUATION.
Definition: tokenI.H:561
dictionary dict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
char readEndList(const char *funcName)
End read of list data, ends with &#39;)&#39; or &#39;}&#39;.
Definition: Istream.C:192
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
A token holds an item read from Istream.
Definition: token.H:65
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
Definition: ListI.H:175
void putBack(const token &tok)
Put back a token (copy). Only a single put back is permitted.
Definition: Istream.C:71
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
T & emplace_back(Args &&... args)
Construct an element at the end of the list, return reference to the new list element.
Definition: DynamicListI.H:538
char readBeginList(const char *funcName)
Begin read of list data, starts with &#39;(&#39; or &#39;{&#39;.
Definition: Istream.C:171
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
#define FUNCTION_NAME
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:405
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:51
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
label labelToken() const
Return label value.
Definition: tokenI.H:615
bool isLabel() const noexcept
Token is LABEL.
Definition: tokenI.H:599
InfoProxy< token > info() const noexcept
Return info proxy, for printing token information to a stream.
Definition: token.H:1078
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...