Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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 // 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
96 }
97}
98
99
100template<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// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
T & emplace_back(Args &&... args)
Construct an element at the end of the list, return reference to the new list element.
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition IOstream.C:51
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)
End read of list data, ends with ')' or '}'.
Definition Istream.C:192
char readBeginList(const char *funcName)
Begin read of list data, starts with '(' or '{'.
Definition Istream.C:171
void putBack(const token &tok)
Put back a token (copy). Only a single put back is permitted.
Definition Istream.C:71
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
Definition ListI.H:171
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A token holds an item read from Istream.
Definition token.H:70
bool isPunctuation() const noexcept
Token is PUNCTUATION.
Definition tokenI.H:650
@ BEGIN_LIST
Begin list [isseparator].
Definition token.H:174
@ END_LIST
End list [isseparator].
Definition token.H:175
bool isLabel() const noexcept
Integral token is convertible to Foam::label.
Definition tokenI.H:843
label labelToken() const
Return integer type as label value or Error.
Definition tokenI.H:869
InfoProxy< token > info() const noexcept
Return info proxy, for printing token information to a stream.
Definition token.H:1253
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
#define FUNCTION_NAME
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition int32.H:127
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict