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

/*---------------------------------------------------------------------------*\
53
                         Class regIOobject Declaration
54 55 56 57 58 59 60
\*---------------------------------------------------------------------------*/

class regIOobject
:
    public IOobject
{

61 62 63 64 65 66 67 68 69 70 71 72 73 74
public:

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

    static const NamedEnum<fileCheckTypes, 4> fileCheckTypesNames;


75 76 77 78 79 80 81 82 83 84
private:

    // Private data

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

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

85 86
        //- Modification watch index
        mutable label watchIndex_;
87

mattijs's avatar
mattijs committed
88 89 90
        //- eventNo of last update
        label eventNo_;

91 92 93 94
        //- Istream for reading
        Istream* isPtr_;


95
    // Private Member Functions
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

        //- Return Istream
        Istream& readStream();

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


public:

    // Static data

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

        static int fileModificationSkew;

113 114
        static fileCheckTypes fileModificationChecking;

115 116 117

    // Constructors

mattijs's avatar
mattijs committed
118 119 120
        //- Construct from IOobject. Optional flag for if IOobject is the
        //  top level regIOobject.
        regIOobject(const IOobject&, const bool isTime = false);
121 122 123 124

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

Mark Olesen's avatar
Mark Olesen committed
125
        //- Construct as copy, and transferring registry registration to copy
126 127 128 129
        //  if registerCopy is true
        regIOobject(const regIOobject&, bool registerCopy);


130 131
    //- Destructor
    virtual ~regIOobject();
132 133 134 135 136 137


    // Member functions

        // Registration

138 139
            //- Add object to registry
            bool checkIn();
140

141 142
            //- Remove object from registry
            bool checkOut();
143

144
            //- Is this object owned by the registry?
145 146 147 148 149 150 151 152
            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>
153
            inline static Type& store(Type*);
154 155 156 157

            //- Transfer ownership of the given object pointer to its registry
            //  and return reference to object.
            template<class Type>
158
            inline static Type& store(autoPtr<Type>&);
159 160 161 162 163

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


mattijs's avatar
mattijs committed
164 165 166 167 168 169 170 171
        // Dependency checking

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

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

172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
            //- 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
195 196
            bool upToDate
            (
197 198 199 200
                const regIOobject&,
                const regIOobject&,
                const regIOobject&,
                const regIOobject&
201 202
            ) const;

203
            //- Set up to date (obviously)
204 205
            void setUpToDate();

mattijs's avatar
mattijs committed
206

207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
        // 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();

229 230 231 232 233 234 235 236
            //- 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)
237 238
            virtual bool modified() const;

239
            //- Read object if modified (as set by call to modified)
240 241 242 243 244 245 246 247 248 249 250 251
            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
            (
252 253 254
                IOstream::streamFormat,
                IOstream::versionNumber,
                IOstream::compressionType
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
            ) const;

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


    // Member operators

        void operator=(const IOobject&);
};


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

} // End namespace Foam

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

#include "regIOobjectI.H"

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

#endif

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