All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LPtrListIO.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-2023 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 "LPtrList.H"
27 #include "Istream.H"
28 #include "INew.H"
29 
30 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
31 
32 template<class LListBase, class T>
33 template<class INew>
34 void Foam::LPtrList<LListBase, T>::read(Istream& is, const INew& iNew)
35 {
36  is.fatalCheck
37  (
38  "LPtrList<LListBase, T>::read(Istream&, const INew&)"
39  );
40 
41  token firstToken(is);
42 
43  is.fatalCheck
44  (
45  "LPtrList<LListBase, T>::read(Istream&, const INew&) : "
46  "reading first token"
47  );
48 
49  if (firstToken.isLabel())
50  {
51  label s = firstToken.labelToken();
52 
53  // Read beginning of contents
54  char delimiter = is.readBeginList("LPtrList<LListBase, T>");
55 
56  if (s)
57  {
58  if (delimiter == token::BEGIN_LIST)
59  {
60  for (label i=0; i<s; ++i)
61  {
62  this->append(iNew(is).ptr());
63 
64  is.fatalCheck
65  (
66  "LPtrList<LListBase, T>::read(Istream&, const INew&) : "
67  "reading entry"
68  );
69  }
70  }
71  else
72  {
73  T* tPtr = iNew(is).ptr();
74  this->append(tPtr);
75 
76  is.fatalCheck
77  (
78  "LPtrList<LListBase, T>::read(Istream&, const INew&) : "
79  "reading entry"
80  );
81 
82  for (label i=1; i<s; ++i)
83  {
84  this->append(tPtr->clone().ptr());
85  }
86  }
87  }
88 
89  // Read end of contents
90  is.readEndList("LPtrList<LListBase, T>");
91  }
92  else if (firstToken.isPunctuation())
93  {
94  if (firstToken.pToken() != token::BEGIN_LIST)
95  {
97  (
98  is
99  ) << "incorrect first token, '(', found " << firstToken.info()
100  << exit(FatalIOError);
101  }
102 
103  token lastToken(is);
104  is.fatalCheck("LPtrList<LListBase, T>::read(Istream&, const INew&)");
105 
106  while
107  (
108  !(
109  lastToken.isPunctuation()
110  && lastToken.pToken() == token::END_LIST
111  )
112  )
113  {
114  is.putBack(lastToken);
115  this->append(iNew(is).ptr());
116 
117  is >> lastToken;
118  is.fatalCheck
119  (
120  "LPtrList<LListBase, T>::read(Istream&, const INew&)"
121  );
122  }
123  }
124  else
125  {
127  (
128  is
129  ) << "incorrect first token, expected <int> or '(', found "
130  << firstToken.info()
131  << exit(FatalIOError);
132  }
133 
134  is.fatalCheck("LPtrList<LListBase, T>::read(Istream&, const INew&)");
135 }
136 
137 
138 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
139 
140 template<class LListBase, class T>
141 template<class INew>
143 {
144  this->read(is, iNew);
145 }
146 
147 
148 template<class LListBase, class T>
150 {
151  this->read(is, INew<T>());
152 }
153 
154 
155 // * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
156 
157 template<class LListBase, class T>
159 {
160  L.clear();
161  L.read(is, INew<T>());
162 
163  return is;
164 }
165 
166 
167 // ************************************************************************* //
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:50
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
Template class for non-intrusive linked PtrLists.
Definition: LPtrList.H:65
LPtrList()
Null construct.
Definition: LPtrList.H:78
void clear()
Clear the contents of the list.
Definition: LPtrList.C:84
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
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.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
Istream & operator>>(Istream &, pistonPointEdgeData &)
IOerror FatalIOError
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)