ILListIO.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) 2011-2015 OpenFOAM Foundation
9 Copyright (C) 2017-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#include "ILList.H"
30#include "Istream.H"
31#include "INew.H"
32
33// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34
35template<class LListBase, class T>
36template<class INew>
37void Foam::ILList<LListBase, T>::readIstream(Istream& is, const INew& inew)
38{
39 is.fatalCheck(FUNCTION_NAME);
40
41 token tok(is);
42
43 is.fatalCheck
44 (
45 "ILList::readIstream : "
46 "reading first token"
47 );
48
49 if (tok.isLabel())
50 {
51 const label len = tok.labelToken();
52
53 // Read beginning of contents
54 const char delimiter = is.readBeginList("ILList");
55
56 if (len)
57 {
58 if (delimiter == token::BEGIN_LIST)
59 {
60 for (label i=0; i<len; ++i)
61 {
62 T* p = inew(is).ptr();
63 this->append(p);
64
65 is.fatalCheck
66 (
67 "ILList::readIstream : "
68 "reading entry"
69 );
70 }
71 }
72 else // BEGIN_BLOCK
73 {
74 T* p = inew(is).ptr();
75 this->append(p);
76
77 is.fatalCheck
78 (
79 "ILList::readIstream : "
80 "reading the single entry"
81 );
82
83 for (label i=1; i<len; ++i)
84 {
85 this->append(new T(*p)); // Copy construct
86 }
87 }
88 }
89
90 // Read end of contents
91 is.readEndList("ILList");
92 }
93 else if (tok.isPunctuation(token::BEGIN_LIST))
94 {
95 is >> tok;
96 is.fatalCheck(FUNCTION_NAME);
97
98 while (!tok.isPunctuation(token::END_LIST))
99 {
100 is.putBack(tok);
101
102 T* p = inew(is).ptr();
103 this->append(p);
104
105 is >> tok;
106 is.fatalCheck(FUNCTION_NAME);
107 }
108 }
109 else
110 {
112 << "incorrect first token, expected <int> or '(', found "
113 << tok.info() << nl
114 << exit(FatalIOError);
115 }
116
117 is.fatalCheck(FUNCTION_NAME);
118}
119
120
121template<class LListBase, class T>
122template<class INew>
124{
125 this->readIstream(is, inew);
126}
127
128
129template<class LListBase, class T>
131{
132 this->readIstream(is, INew<T>());
133}
134
135
136// * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
137
138template<class LListBase, class T>
140{
141 list.clear();
142 list.readIstream(is, INew<T>());
143
144 return is;
145}
146
147
148// ************************************************************************* //
Template class for intrusive linked lists.
Definition: ILList.H:69
ILList()=default
Default construct.
void clear()
Clear the contents of the list.
Definition: ILList.C:101
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:52
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
volScalarField & p
const volScalarField & T
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
#define FUNCTION_NAME
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
Istream & operator>>(Istream &, directionInfo &)