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-------------------------------------------------------------------------------
11License
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
31template<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
93 }
94}
95
96
97template<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// ************************************************************************* //
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:64
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
char readEndList(const char *funcName)
End read of list data, ends with ')' or '}'.
Definition: Istream.C:169
char readBeginList(const char *funcName)
Begin read of list data, starts with '(' or '{'.
Definition: Istream.C:148
void putBack(const token &tok)
Put back a token. Only a single put back is permitted.
Definition: Istream.C:70
Template class for non-intrusive linked lists.
Definition: LList.H:79
void append(const T &elem)
Add copy at back of list.
Definition: LList.H:245
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A token holds an item read from Istream.
Definition: token.H:69
bool isPunctuation() const noexcept
Token is PUNCTUATION.
Definition: tokenI.H:459
bool isLabel() const noexcept
Token is LABEL.
Definition: tokenI.H:497
label labelToken() const
Return label value.
Definition: tokenI.H:513
InfoProxy< token > info() const
Return info proxy for printing token information to a stream.
Definition: token.H:586
const volScalarField & T
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
#define FUNCTION_NAME
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
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
dictionary dict