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 | Copyright (C) 2011 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  "operator>>(Istream&, ILList<LListBase, T>&)",
95  is
96  ) << "incorrect first token, '(', found " << firstToken.info()
97  << exit(FatalIOError);
98  }
99 
100  token lastToken(is);
101  is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
102 
103  while
104  (
105  !(
106  lastToken.isPunctuation()
107  && lastToken.pToken() == token::END_LIST
108  )
109  )
110  {
111  is.putBack(lastToken);
112  this->append(iNew(is).ptr());
113 
114  is >> lastToken;
115  is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
116  }
117  }
118  else
119  {
120  FatalIOErrorIn("operator>>(Istream&, ILList<LListBase, T>&)", is)
121  << "incorrect first token, expected <int> or '(', found "
122  << firstToken.info()
123  << exit(FatalIOError);
124  }
125 
126  is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
127 }
128 
129 
130 template<class LListBase, class T>
131 template<class INew>
133 {
134  this->read(is, iNew);
135 }
136 
137 
138 template<class LListBase, class T>
140 {
141  this->read(is, INew<T>());
142 }
143 
144 
145 // * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
146 
147 template<class LListBase, class T>
149 {
150  L.clear();
151  L.read(is, INew<T>());
152 
153  return is;
154 }
155 
156 
157 // ************************************************************************* //
ILList()
Null construct.
Definition: ILList.H:80
void clear()
Clear the contents of the list.
Definition: ILList.C:112
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 ))
Template class for intrusive linked lists.
Definition: ILList.H:50
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
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
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:49
const volScalarField & T
Definition: createFields.H:25
IOerror FatalIOError
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:144
bool read(const char *, int32_t &)
Definition: int32IO.C:87
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:325