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

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&);

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

145 146 147 148 149 150 151
        //- Construct as copy with new name, transfering registry registration
        //  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
            //- Is this object owned by the registry?
168 169 170 171 172 173 174 175
            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>
176
            inline static Type& store(Type*);
177 178 179 180

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

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


mattijs's avatar
mattijs committed
187 188 189 190 191 192 193 194
        // Dependency checking

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

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

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

226
            //- Set up to date (obviously)
227 228
            void setUpToDate();

mattijs's avatar
mattijs committed
229

230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
        // 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();

252 253 254 255 256 257 258 259
            //- 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)
260 261
            virtual bool modified() const;

262
            //- Read object if modified (as set by call to modified)
263 264 265 266 267 268 269 270 271 272 273 274
            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
            (
275 276 277
                IOstream::streamFormat,
                IOstream::versionNumber,
                IOstream::compressionType
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
            ) const;

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


    // Member operators

        void operator=(const IOobject&);
};


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

} // End namespace Foam

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

#include "regIOobjectI.H"

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

#endif

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