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-2018 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 firstToken(is);
42 
43  is.fatalCheck
44  (
45  "ILList::readIstream : "
46  "reading first token"
47  );
48 
49  if (firstToken.isLabel())
50  {
51  const label len = firstToken.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
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 (firstToken.isPunctuation())
94  {
95  if (firstToken.pToken() != token::BEGIN_LIST)
96  {
98  << "incorrect first token, '(', found " << firstToken.info()
99  << exit(FatalIOError);
100  }
101 
102  token lastToken(is);
103  is.fatalCheck(FUNCTION_NAME);
104 
105  while
106  (
107  !(
108  lastToken.isPunctuation()
109  && lastToken.pToken() == token::END_LIST
110  )
111  )
112  {
113  is.putBack(lastToken);
114 
115  T* p = inew(is).ptr();
116  this->append(p);
117 
118  is >> lastToken;
119  is.fatalCheck(FUNCTION_NAME);
120  }
121  }
122  else
123  {
125  << "incorrect first token, expected <int> or '(', found "
126  << firstToken.info()
127  << exit(FatalIOError);
128  }
129 
130  is.fatalCheck(FUNCTION_NAME);
131 }
132 
133 
134 template<class LListBase, class T>
135 template<class INew>
137 {
138  this->readIstream(is, inew);
139 }
140 
141 
142 template<class LListBase, class T>
144 {
145  this->readIstream(is, INew<T>());
146 }
147 
148 
149 // * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
150 
151 template<class LListBase, class T>
153 {
154  list.clear();
155  list.readIstream(is, INew<T>());
156 
157  return is;
158 }
159 
160 
161 // ************************************************************************* //
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
Null construct.
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:270
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401