IOPtrList.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-2017 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 "IOPtrList.H"
27 
28 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
29 
30 template<class T>
31 template<class INew>
33 :
34  regIOobject(io)
35 {
36  if
37  (
38  (
39  io.readOpt() == IOobject::MUST_READ
40  || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
41  )
42  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
43  )
44  {
45  // For if MUST_READ_IF_MODIFIED
46  addWatch();
47 
48  PtrList<T>::read(readStream(typeName), inewt);
49  close();
50  }
51 }
52 
53 
54 template<class T>
56 :
57  regIOobject(io)
58 {
59  if
60  (
61  (
62  io.readOpt() == IOobject::MUST_READ
63  || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
64  )
65  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
66  )
67  {
68  // For if MUST_READ_IF_MODIFIED
69  addWatch();
70 
71  PtrList<T>::read(readStream(typeName), INew<T>());
72  close();
73  }
74 }
75 
76 
77 template<class T>
79 :
80  regIOobject(io),
81  PtrList<T>(s)
82 {
83  if (io.readOpt() != IOobject::NO_READ)
84  {
86  << "NO_READ must be set if specifying size" << nl
87  << exit(FatalError);
88  }
89 }
90 
91 
92 template<class T>
94 :
95  regIOobject(io)
96 {
97  if
98  (
99  (
100  io.readOpt() == IOobject::MUST_READ
101  || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
102  )
103  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
104  )
105  {
106  // For if MUST_READ_IF_MODIFIED
107  addWatch();
108 
109  PtrList<T>::read(readStream(typeName), INew<T>());
110  close();
111  }
112  else
113  {
114  PtrList<T>::operator=(list);
115  }
116 }
117 
118 
119 template<class T>
121 :
122  regIOobject(io)
123 {
124  PtrList<T>::transfer(list());
125 
126  if
127  (
128  (
129  io.readOpt() == IOobject::MUST_READ
130  || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
131  )
132  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
133  )
134  {
135  // For if MUST_READ_IF_MODIFIED
136  addWatch();
137 
138  PtrList<T>::read(readStream(typeName), INew<T>());
139  close();
140  }
141 }
142 
143 
144 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
145 
146 template<class T>
148 {}
149 
150 
151 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
152 
153 template<class T>
155 {
156  return (os << *this).good();
157 }
158 
159 
160 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
161 
162 template<class T>
164 {
166 }
167 
168 // ************************************************************************* //
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
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
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
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))
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:262
const volScalarField & T
A PtrList of objects of type <T> with automated input and output.
Definition: IOPtrList.H:50
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:63
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:49
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:65
void operator=(const IOPtrList< T > &)
Definition: IOPtrList.C:163
virtual ~IOPtrList()
Destructor.
Definition: IOPtrList.C:147
bool writeData(Ostream &) const
Pure virtual writaData function.
Definition: IOPtrList.C:154
readOption readOpt() const
Definition: IOobject.H:353
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
IOPtrList(const IOobject &, const INew &)
Construct from IOobject using given Istream constructor class.
Definition: IOPtrList.C:32