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 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  (
41  )
43  )
44  {
45  PtrList<T>::read(readStream(typeName), inewt);
46  close();
47  }
48 }
49 
50 
51 template<class T>
53 :
54  regIOobject(io)
55 {
56  if
57  (
58  (
61  )
63  )
64  {
65  PtrList<T>::read(readStream(typeName), INew<T>());
66  close();
67  }
68 }
69 
70 
71 template<class T>
73 :
74  regIOobject(io),
75  PtrList<T>(s)
76 {
77  if (io.readOpt() != IOobject::NO_READ)
78  {
79  FatalErrorIn("IOPtrList<T>::IOPtrList(const IOobject&, const label)")
80  << "NO_READ must be set if specifying size" << nl
81  << exit(FatalError);
82  }
83 }
84 
85 
86 template<class T>
88 :
89  regIOobject(io)
90 {
91  if
92  (
93  (
96  )
98  )
99  {
100  PtrList<T>::read(readStream(typeName), INew<T>());
101  close();
102  }
103  else
104  {
105  PtrList<T>::operator=(list);
106  }
107 }
108 
109 
110 template<class T>
112 :
113  regIOobject(io)
114 {
115  PtrList<T>::transfer(list());
116 
117  if
118  (
119  (
122  )
123  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
124  )
125  {
126  PtrList<T>::read(readStream(typeName), INew<T>());
127  close();
128  }
129 }
130 
131 
132 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
133 
134 template<class T>
136 {}
137 
138 
139 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
140 
141 template<class T>
143 {
144  return (os << *this).good();
145 }
146 
147 
148 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
149 
150 template<class T>
152 {
154 }
155 
156 // ************************************************************************* //
void transfer(PtrList< T > &)
Transfer the contents of the argument PtrList into this PtrList.
Definition: PtrList.C:200
bool writeData(Ostream &) const
Pure virtual writaData function.
Definition: IOPtrList.C:142
readOption readOpt() const
Definition: IOobject.H:304
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 ))
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
IOPtrList(const IOobject &, const INew &)
Construct from IOobject using given Istream constructor class.
Definition: IOPtrList.C:32
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
A PtrList of objects of type <T> with automated input and output.
Definition: IOPtrList.H:50
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:49
static const char nl
Definition: Ostream.H:260
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
void read(Istream &, const INew &inewt)
Read from Istream using given Istream constructor class.
Definition: PtrListIO.C:36
void operator=(const IOPtrList< T > &)
Definition: IOPtrList.C:151
void close()
Close Istream.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
error FatalError
virtual ~IOPtrList()
Destructor.
Definition: IOPtrList.C:135
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
PtrList< T > & operator=(const PtrList< T > &)
Assignment.
Definition: PtrList.C:261
bool headerOk()
Read and check header info.
Definition: IOobject.C:424
Istream & readStream(const word &)
Return Istream and check object type against that given.