regIOobject.H 9.46 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
     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
7 8 9 10
-------------------------------------------------------------------------------
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
        //- No copy assignment
        void operator=(const regIOobject&) = delete;
113 114 115 116


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* p);
180 181

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

            //- Transfer ownership of the given object pointer to its registry
            //- and return reference to object.
188
            template<class Type>
189
            inline static Type& store(autoPtr<Type>&& aptr);
190 191 192 193 194

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


mattijs's avatar
mattijs committed
195 196 197 198 199 200 201 202
        // Dependency checking

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

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

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

234
            //- Set up to date (obviously)
235 236
            void setUpToDate();

mattijs's avatar
mattijs committed
237

238 239 240 241 242 243 244 245
        // Edit

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


        // Reading

246 247 248 249 250 251 252 253 254
            //- 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();

255
            //- Return Istream and check object type against that given
256
            Istream& readStream(const word&, const bool valid = true);
257 258 259 260 261 262 263 264 265 266 267 268

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

269 270 271 272 273 274
            //- 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;
275

276 277
            //- Return file-monitoring handles
            inline labelList& watchIndices();
278 279 280

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

283
            //- Read object if modified (as set by call to modified)
284 285 286 287 288
            virtual bool readIfModified();


        // Writing

Andrew Heather's avatar
Andrew Heather committed
289
            //- Pure virtual writeData function.
290 291 292 293 294 295
            //  Must be defined in derived types
            virtual bool writeData(Ostream&) const = 0;

            //- Write using given format, version and compression
            virtual bool writeObject
            (
296 297
                IOstream::streamFormat,
                IOstream::versionNumber,
298 299
                IOstream::compressionType,
                const bool valid
300 301 302
            ) const;

            //- Write using setting from DB
303
            virtual bool write(const bool valid = true) const;
304 305


306 307 308 309 310 311 312 313 314
        // Other

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


315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
    // Member operators

        void operator=(const IOobject&);
};


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

} // End namespace Foam

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

#include "regIOobjectI.H"

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

#endif

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