All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ILListIO.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "ILList.H"
27 #include "Istream.H"
28 #include "INew.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class LListBase, class T>
33 template<class INew>
34 void Foam::ILList<LListBase, T>::read(Istream& is, const INew& iNew)
35 {
36  is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
37 
38  token firstToken(is);
39 
40  is.fatalCheck
41  (
42  "operator>>(Istream&, ILList<LListBase, T>&) : reading first token"
43  );
44 
45  if (firstToken.isLabel())
46  {
47  label s = firstToken.labelToken();
48 
49  // Read beginning of contents
50  char delimiter = is.readBeginList("ILList<LListBase, T>");
51 
52  if (s)
53  {
54  if (delimiter == token::BEGIN_LIST)
55  {
56  for (label i=0; i<s; ++i)
57  {
58  this->append(iNew(is).ptr());
59 
60  is.fatalCheck
61  (
62  "operator>>(Istream&, ILList<LListBase, T>&) : "
63  "reading entry"
64  );
65  }
66  }
67  else
68  {
69  T* tPtr = iNew(is).ptr();
70  this->append(tPtr);
71 
72  is.fatalCheck
73  (
74  "operator>>(Istream&, ILList<LListBase, T>&) : "
75  "reading entry"
76  );
77 
78  for (label i=1; i<s; ++i)
79  {
80  this->append(new T(*tPtr));
81  }
82  }
83  }
84 
85  // Read end of contents
86  is.readEndList("ILList<LListBase, T>");
87  }
88  else if (firstToken.isPunctuation())
89  {
90  if (firstToken.pToken() != token::BEGIN_LIST)
91  {
93  (
94  is
95  ) << "incorrect first token, '(', found " << firstToken.info()
96  << exit(FatalIOError);
97  }
98 
99  token lastToken(is);
100  is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
101 
102  while
103  (
104  !(
105  lastToken.isPunctuation()
106  && lastToken.pToken() == token::END_LIST
107  )
108  )
109  {
110  is.putBack(lastToken);
111  this->append(iNew(is).ptr());
112 
113  is >> lastToken;
114  is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
115  }
116  }
117  else
118  {
120  << "incorrect first token, expected <int> or '(', found "
121  << firstToken.info()
122  << exit(FatalIOError);
123  }
124 
125  is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
126 }
127 
128 
129 template<class LListBase, class T>
130 template<class INew>
132 {
133  this->read(is, iNew);
134 }
135 
136 
137 template<class LListBase, class T>
139 {
140  this->read(is, INew<T>());
141 }
142 
143 
144 // * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
145 
146 template<class LListBase, class T>
148 {
149  L.clear();
150  L.read(is, INew<T>());
151 
152  return is;
153 }
154 
155 
156 // ************************************************************************* //
Template class for intrusive linked lists.
Definition: ILList.H:50
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
ILList()
Null construct.
Definition: ILList.H:80
void clear()
Clear the contents of the list.
Definition: ILList.C:121
Istream & operator>>(Istream &, directionInfo &)
const volScalarField & T
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:49
IOerror FatalIOError