Home
Downloads
Documentation
Installation
User Guide
man-pages
API Documentation
README
Release Notes
Changes
License
Support
SourceForge Project
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
OpenFOAM
db
IOobject
IOobject.H
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) 1991-2010 OpenCFD Ltd.
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
Class
25
Foam::IOobject
26
27
Description
28
IOobject defines the attributes of an object for which implicit
29
objectRegistry management is supported, and provides the infrastructure
30
for performing stream I/O.
31
32
An IOobject is constructed with an object name, a class name, an instance
33
path, a reference to a objectRegistry, and parameters determining its
34
storage status.
35
36
@par Read options
37
38
Define what is done on object construction and explicit reads:
39
@param MUST_READ
40
Object must be read from Istream on construction. \n
41
Error if Istream does not exist or can't be read.
42
@param READ_IF_PRESENT
43
Read object from Istream if Istream exists, otherwise don't. \n
44
Error only if Istream exists but can't be read.
45
@param NO_READ
46
Don't read
47
48
@par Write options
49
50
Define what is done on object destruction and explicit writes:
51
@param AUTO_WRITE
52
Object is written automatically when requested to by the
53
objectRegistry.
54
@param NO_WRITE
55
No automatic write on destruction but can be written explicitly
56
57
SourceFiles
58
IOobject.C
59
IOobjectReadHeader.C
60
IOobjectWriteHeader.C
61
IOobjectPrint.C
62
63
\*---------------------------------------------------------------------------*/
64
65
#ifndef IOobject_H
66
#define IOobject_H
67
68
#include <
OpenFOAM/fileName.H
>
69
#include <
OpenFOAM/typeInfo.H
>
70
#include <
OpenFOAM/autoPtr.H
>
71
#include <
OpenFOAM/InfoProxy.H
>
72
73
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
74
75
namespace
Foam
76
{
77
78
class
Time;
79
class
objectRegistry;
80
81
/*---------------------------------------------------------------------------*\
82
Class IOobject Declaration
83
\*---------------------------------------------------------------------------*/
84
85
class
IOobject
86
{
87
88
public
:
89
90
// Public data types
91
92
//- Enumeration defining the valid states of an IOobject
93
enum
objectState
94
{
95
GOOD
,
96
BAD
97
};
98
99
//- Enumeration defining the read options
100
enum
readOption
101
{
102
MUST_READ
,
103
READ_IF_PRESENT
,
104
NO_READ
105
};
106
107
//- Enumeration defining the write options
108
enum
writeOption
109
{
110
AUTO_WRITE
= 0,
111
NO_WRITE
= 1
112
};
113
114
115
private
:
116
117
// Private data
118
119
//- Name
120
word
name_;
121
122
//- Class name read from header
123
word
headerClassName_;
124
125
//- Optional note
126
string
note_;
127
128
//- Instance path component
129
fileName
instance_;
130
131
//- Local path component
132
fileName
local_;
133
134
//- objectRegistry reference
135
const
objectRegistry
& db_;
136
137
//- Read option
138
readOption
rOpt_;
139
140
//- Write option
141
writeOption
wOpt_;
142
143
//- Register object created from this IOobject with registry if true
144
bool
registerObject_;
145
146
//- IOobject state
147
objectState
objState_;
148
149
protected
:
150
151
// Protected member functions
152
153
//- Construct and return an IFstream for the object.
154
// The results is NULL if the stream construction failed
155
Istream
*
objectStream
();
156
157
//- Set the object state to bad
158
void
setBad
(
const
string
&);
159
160
static
const
char
*
getBannerString
(
bool
noHint);
161
162
163
public
:
164
165
//- Runtime type information
166
TypeName
(
"IOobject"
);
167
168
169
// Static Member Functions
170
171
//- Split path into instance, local, name components
172
static
bool
fileNameComponents
173
(
174
const
fileName
&
path
,
175
fileName
&
instance
,
176
fileName
&
local
,
177
word
&
name
178
);
179
180
181
// Constructors
182
183
//- Construct from name, instance, registry, io options
184
IOobject
185
(
186
const
word
&
name
,
187
const
fileName
&
instance
,
188
const
objectRegistry
& registry,
189
readOption
r=
NO_READ
,
190
writeOption
w=
NO_WRITE
,
191
bool
registerObject
=
true
192
);
193
194
//- Construct from name, instance, local, registry, io options
195
IOobject
196
(
197
const
word
&
name
,
198
const
fileName
&
instance
,
199
const
fileName
&
local
,
200
const
objectRegistry
& registry,
201
readOption
r=
NO_READ
,
202
writeOption
w=
NO_WRITE
,
203
bool
registerObject
=
true
204
);
205
206
//- Construct from path, registry, io options
207
// Uses fileNameComponents() to split path into components.
208
IOobject
209
(
210
const
fileName
&
path
,
211
const
objectRegistry
& registry,
212
readOption
r=
NO_READ
,
213
writeOption
w=
NO_WRITE
,
214
bool
registerObject
=
true
215
);
216
217
//- Clone
218
Foam::autoPtr<IOobject>
clone
()
const
219
{
220
return
autoPtr<IOobject>
(
new
IOobject
(*
this
));
221
}
222
223
224
// Destructor
225
226
virtual
~IOobject
();
227
228
229
// Member Functions
230
231
// General access
232
233
//- Return time
234
const
Time
&
time
()
const
;
235
236
//- Return the local objectRegistry
237
const
objectRegistry
&
db
()
const
;
238
239
//- Return name
240
const
word
&
name
()
const
241
{
242
return
name_;
243
}
244
245
//- Return name of the class name read from header
246
const
word
&
headerClassName
()
const
247
{
248
return
headerClassName_;
249
}
250
251
//- Return non-constant access to the optional note
252
string
&
note
()
253
{
254
return
note_;
255
}
256
257
//- Return the optional note
258
const
string
&
note
()
const
259
{
260
return
note_;
261
}
262
263
//- Rename
264
virtual
void
rename
(
const
word
& newName)
265
{
266
name_ = newName;
267
}
268
269
//- Register object created from this IOobject with registry if true
270
bool
registerObject
()
const
271
{
272
return
registerObject_;
273
}
274
275
276
// Read/write options
277
278
readOption
readOpt
()
const
279
{
280
return
rOpt_;
281
}
282
283
readOption
&
readOpt
()
284
{
285
return
rOpt_;
286
}
287
288
writeOption
writeOpt
()
const
289
{
290
return
wOpt_;
291
}
292
293
writeOption
&
writeOpt
()
294
{
295
return
wOpt_;
296
}
297
298
299
// Path components
300
301
const
fileName
&
rootPath
()
const
;
302
303
const
fileName
&
caseName
()
const
;
304
305
const
fileName
&
instance
()
const
306
{
307
return
instance_;
308
}
309
310
fileName
&
instance
()
311
{
312
return
instance_;
313
}
314
315
const
fileName
&
local
()
const
316
{
317
return
local_;
318
}
319
320
//- Return complete path
321
fileName
path
()
const
;
322
323
//- Return complete path with alternative instance and local
324
fileName
path
325
(
326
const
word
&
instance
,
327
const
fileName
&
local
=
""
328
)
const
;
329
330
//- Return complete path + object name
331
fileName
objectPath
()
const
332
{
333
return
path
()/
name
();
334
}
335
336
//- Return complete path + object name if the file exists
337
// either in the case/processor or case otherwise null
338
fileName
filePath
()
const
;
339
340
341
// Reading
342
343
//- Read header
344
bool
readHeader
(
Istream
&);
345
346
//- Read and check header info
347
bool
headerOk
();
348
349
350
// Writing
351
352
//- Write the standard OpenFOAM file/dictionary banner
353
// Optionally without -*- C++ -*- editor hint (eg, for logs)
354
template
<
class
Stream>
355
static
inline
Stream&
writeBanner
(Stream& os,
bool
noHint=
false
);
356
357
//- Write the standard file section divider
358
template
<
class
Stream>
359
static
inline
Stream&
writeDivider
(Stream& os);
360
361
//- Write the standard end file divider
362
template
<
class
Stream>
363
static
inline
Stream&
writeEndDivider
(Stream& os);
364
365
//- Write header
366
bool
writeHeader
(
Ostream
&)
const
;
367
368
369
// Error Handling
370
371
bool
good
()
const
372
{
373
return
objState_ ==
GOOD
;
374
}
375
376
bool
bad
()
const
377
{
378
return
objState_ ==
BAD
;
379
}
380
381
382
// Info
383
384
//- Return info proxy.
385
// Used to print token information to a stream
386
InfoProxy<IOobject>
info
()
const
387
{
388
return
*
this
;
389
}
390
391
392
// Member operators
393
394
void
operator=
(
const
IOobject
&);
395
};
396
397
398
#if defined (__GNUC__)
399
template
<>
400
#endif
401
Ostream& operator<<(Ostream& os, const InfoProxy<IOobject>& ip);
402
403
404
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
405
406
}
// End namespace Foam
407
408
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
409
410
# include <
OpenFOAM/IOobjectI.H
>
411
412
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
413
414
#endif
415
416
// ************************ vim: set sw=4 sts=4 et: ************************ //