regIOobject.H 9.2 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
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 44 45 46

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"

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

mattijs's avatar
mattijs committed
47

48 49 50
namespace Foam
{

51 52 53 54
namespace functionEntries
{
    class codeStream;
}
55 56 57 58 59
namespace fileOperations
{
    class uncollatedFileOperation;
    class masterUncollatedFileOperation;
}
60

61
/*---------------------------------------------------------------------------*\
62
                         Class regIOobject Declaration
63 64 65 66 67 68
\*---------------------------------------------------------------------------*/

class regIOobject
:
    public IOobject
{
69
protected:
70

71
        //- Helper: check readOpt flags and read if necessary
72 73 74 75 76
        bool readHeaderOk
        (
            const IOstream::streamFormat PstreamFormat,
            const word& typeName
        );
77

78 79 80 81
        //- Construct and return an IFstream for the object.
        //  The results is NULL if the stream construction failed
        Istream* objectStream();

82 83 84 85
        //- 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
        //- List of modification watch indices
        mutable labelList watchIndices_;
98

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

102
        //- Istream for reading
103
        autoPtr<ISstream> isPtr_;
104 105


106
    // Private Member Functions
107 108

        //- Return Istream
109
        Istream& readStream(const bool valid = true);
110 111 112 113 114 115 116

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


public:

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


124 125 126 127 128
    // Static data

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

129
        static float fileModificationSkew;
130 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&);

141
        //- Construct as copy, transferring registry registration to copy
142 143 144
        //  if registerCopy is true
        regIOobject(const regIOobject&, bool registerCopy);

Andrew Heather's avatar
Andrew Heather committed
145
        //- Construct as copy with new name, transferring registry registration
146 147 148 149 150 151
        //  to copy as specified
        regIOobject(const word& newName, const regIOobject&, bool registerCopy);

        //- Construct as copy with new IO parameters
        regIOobject(const IOobject&, const regIOobject&);

152

153 154
    //- Destructor
    virtual ~regIOobject();
155 156 157 158 159 160


    // Member functions

        // Registration

161 162
            //- Add object to registry
            bool checkIn();
163

164 165
            //- Remove object from registry
            bool checkOut();
166

167 168 169
            //- Add file watch on object (if registered and READ_IF_MODIFIED)
            virtual void addWatch();

170
            //- Is this object owned by the registry?
171 172 173 174 175 176 177 178
            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>
179
            inline static Type& store(Type*);
180 181 182 183

            //- Transfer ownership of the given object pointer to its registry
            //  and return reference to object.
            template<class Type>
184
            inline static Type& store(autoPtr<Type>&);
185 186 187 188 189

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


mattijs's avatar
mattijs committed
190 191 192 193 194 195 196 197
        // Dependency checking

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

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

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
            //- 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
221 222
            bool upToDate
            (
223 224 225 226
                const regIOobject&,
                const regIOobject&,
                const regIOobject&,
                const regIOobject&
227 228
            ) const;

229
            //- Set up to date (obviously)
230 231
            void setUpToDate();

mattijs's avatar
mattijs committed
232

233 234 235 236 237 238 239 240
        // Edit

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


        // Reading

241 242 243 244 245 246 247 248 249
            //- Return complete path + object name if the file exists
            //  in the case directory otherwise null. Does not search
            //  up if parallel. Can be overridden to provide this functionality
            //  (e.g. IOdictionary)
            virtual fileName filePath() const;

            //- Read and check header info
            bool headerOk();

250
            //- Return Istream and check object type against that given
251
            Istream& readStream(const word&, const bool valid = true);
252 253 254 255 256 257 258 259 260 261 262 263

            //- 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();

264 265 266 267 268 269
            //- Add file watch for fileName on object if not yet watched. Return
            //  index of watch
            virtual label addWatch(const fileName&);

            //- Return file-monitoring handles
            inline const labelList& watchIndices() const;
270

271 272
            //- Return file-monitoring handles
            inline labelList& watchIndices();
273 274 275

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

278
            //- Read object if modified (as set by call to modified)
279 280 281 282 283
            virtual bool readIfModified();


        // Writing

Andrew Heather's avatar
Andrew Heather committed
284
            //- Pure virtual writeData function.
285 286 287 288 289 290
            //  Must be defined in derived types
            virtual bool writeData(Ostream&) const = 0;

            //- Write using given format, version and compression
            virtual bool writeObject
            (
291 292
                IOstream::streamFormat,
                IOstream::versionNumber,
293 294
                IOstream::compressionType,
                const bool valid
295 296 297
            ) const;

            //- Write using setting from DB
298
            virtual bool write(const bool valid = true) const;
299 300


301 302 303 304 305 306 307 308 309
        // Other

            //- Is object global
            virtual bool global() const
            {
                return false;
            }


310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
    // Member operators

        void operator=(const IOobject&);
};


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

} // End namespace Foam

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

#include "regIOobjectI.H"

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

#endif

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