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->push_back(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->push_back(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->push_back(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->push_back(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  }
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>
139 Foam::Istream& Foam::operator>>(Istream& is, ILList<LListBase, T>& list)
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:45
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Istream & operator>>(Istream &, directionInfo &)
#define FUNCTION_NAME
const volScalarField & T
ILList()=default
Default construct.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:46
volScalarField & p
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...