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 -------------------------------------------------------------------------------
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 #include "ILList.H"
30 #include "Istream.H"
31 #include "INew.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
35 template<class LListBase, class T>
36 template<class INew>
37 void 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 
121 template<class LListBase, class T>
122 template<class INew>
124 {
125  this->readIstream(is, inew);
126 }
127 
128 
129 template<class LListBase, class T>
131 {
132  this->readIstream(is, INew<T>());
133 }
134 
135 
136 // * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
137 
138 template<class LListBase, class T>
140 {
141  list.clear();
142  list.readIstream(is, INew<T>());
143 
144  return is;
145 }
146 
147 
148 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
INew.H
ILList.H
Foam::FatalIOError
IOerror FatalIOError
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
append
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
Foam::INew
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:51
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Istream.H
Foam::ILList::clear
void clear()
Clear the contents of the list.
Definition: ILList.C:112
Foam::ILList
Template class for intrusive linked lists.
Definition: ILList.H:52
T
const volScalarField & T
Definition: createFieldRefs.H:2
Foam::ILList::ILList
ILList()=default
Default construct.
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
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473