regIOobject.H 7.68 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2004-2011 OpenCFD Ltd.
6
7
8
9
10
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

11
12
13
14
    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
15
16
17
18
19
20
21

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

Class
    Foam::regIOobject

Description
    regIOobject is an abstract class derived from IOobject to handle
    automatic object registration with the objectRegistry.

SourceFiles
    regIOobject.C
    regIOobjectRead.C
    regIOobjectWrite.C

\*---------------------------------------------------------------------------*/

#ifndef regIOobject_H
#define regIOobject_H

#include "IOobject.H"
#include "typeInfo.H"
#include "OSspecific.H"
44
#include "NamedEnum.H"
45
46
47

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

mattijs's avatar
mattijs committed
48

49
50
51
namespace Foam
{

52
53
54
55
56
namespace functionEntries
{
    class codeStream;
}

57
/*---------------------------------------------------------------------------*\
58
                         Class regIOobject Declaration
59
60
61
62
63
64
65
\*---------------------------------------------------------------------------*/

class regIOobject
:
    public IOobject
{

66
67
68
69
70
71
72
73
74
75
76
77
78
79
public:

    //- Types of communications
    enum fileCheckTypes
    {
        timeStamp,
        timeStampMaster,
        inotify,
        inotifyMaster
    };

    static const NamedEnum<fileCheckTypes, 4> fileCheckTypesNames;


80
81
82
83
84
85
protected:

        //- To flag master-only reading of objects
        static bool masterOnlyReading;


86
87
88
89
90
91
92
93
94
95
private:

    // Private data

        //- Is this object registered with the registry
        bool registered_;

        //- Is this object owned by the registry
        bool ownedByRegistry_;

96
97
        //- Modification watch index
        mutable label watchIndex_;
98

mattijs's avatar
mattijs committed
99
100
101
        //- eventNo of last update
        label eventNo_;

102
103
104
105
        //- Istream for reading
        Istream* isPtr_;


106
    // Private Member Functions
107
108
109
110
111
112
113
114
115
116

        //- Return Istream
        Istream& readStream();

        //- Dissallow assignment
        void operator=(const regIOobject&);


public:

117
118
119
120
121
        //- Declare friendship with any classes that need access to
        //  masterOnlyReading
        friend class functionEntries::codeStream;


122
123
124
125
126
127
128
    // Static data

        //- Runtime type information
        TypeName("regIOobject");

        static int fileModificationSkew;

129
130
        static fileCheckTypes fileModificationChecking;

131
132
133

    // Constructors

mattijs's avatar
mattijs committed
134
135
136
        //- Construct from IOobject. Optional flag for if IOobject is the
        //  top level regIOobject.
        regIOobject(const IOobject&, const bool isTime = false);
137
138
139
140

        //- Construct as copy
        regIOobject(const regIOobject&);

Mark Olesen's avatar
Mark Olesen committed
141
        //- Construct as copy, and transferring registry registration to copy
142
143
144
145
        //  if registerCopy is true
        regIOobject(const regIOobject&, bool registerCopy);


146
147
    //- Destructor
    virtual ~regIOobject();
148
149
150
151
152
153


    // Member functions

        // Registration

154
155
            //- Add object to registry
            bool checkIn();
156

157
158
            //- Remove object from registry
            bool checkOut();
159

160
            //- Is this object owned by the registry?
161
162
163
164
165
166
167
168
            inline bool ownedByRegistry() const;

            //- Transfer ownership of this object to its registry
            inline void store();

            //- Transfer ownership of the given object pointer to its registry
            //  and return reference to object.
            template<class Type>
169
            inline static Type& store(Type*);
170
171
172
173

            //- Transfer ownership of the given object pointer to its registry
            //  and return reference to object.
            template<class Type>
174
            inline static Type& store(autoPtr<Type>&);
175
176
177
178
179

            //- Release ownership of this object from its registry
            inline void release();


mattijs's avatar
mattijs committed
180
181
182
183
184
185
186
187
        // Dependency checking

            //- Event number at last update.
            inline label eventNo() const;

            //- Event number at last update.
            inline label& eventNo();

188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
            //- Return true if up-to-date with respect to given object
            //  otherwise false
            bool upToDate(const regIOobject&) const;

            //- Return true if up-to-date with respect to given objects
            //  otherwise false
            bool upToDate
            (
                const regIOobject&,
                const regIOobject&
            ) const;

            //- Return true if up-to-date with respect to given objects
            //  otherwise false
            bool upToDate
            (
                const regIOobject&,
                const regIOobject&,
                const regIOobject&
            ) const;

            //- Return true if up-to-date with respect to given objects
            //  otherwise false
211
212
            bool upToDate
            (
213
214
215
216
                const regIOobject&,
                const regIOobject&,
                const regIOobject&,
                const regIOobject&
217
218
            ) const;

219
            //- Set up to date (obviously)
220
221
            void setUpToDate();

mattijs's avatar
mattijs committed
222

223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
        // Edit

            //- Rename
            virtual void rename(const word& newName);


        // Reading

            //- Return Istream and check object type against that given
            Istream& readStream(const word&);

            //- Close Istream
            void close();

            //- Virtual readData function.
            //  Must be defined in derived types for which
            //  re-reading is required
            virtual bool readData(Istream&);

            //- Read object
            virtual bool read();

245
246
247
248
249
250
251
252
            //- Return file-monitoring handle
            inline label watchIndex() const;

            //- Return file-monitoring handle
            inline label& watchIndex();

            //- Return true if the object's file (or files for objectRegistry)
            //  have been modified. (modified state is cached by Time)
253
254
            virtual bool modified() const;

255
            //- Read object if modified (as set by call to modified)
256
257
258
259
260
261
262
263
264
265
266
267
            virtual bool readIfModified();


        // Writing

            //- Pure virtual writaData function.
            //  Must be defined in derived types
            virtual bool writeData(Ostream&) const = 0;

            //- Write using given format, version and compression
            virtual bool writeObject
            (
268
269
270
                IOstream::streamFormat,
                IOstream::versionNumber,
                IOstream::compressionType
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
            ) const;

            //- Write using setting from DB
            virtual bool write() const;


    // Member operators

        void operator=(const IOobject&);
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#include "regIOobjectI.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //