FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

regIOobject.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "regIOobject.H"
00027 #include <OpenFOAM/Time.H>
00028 #include <OpenFOAM/polyMesh.H>
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 defineTypeNameAndDebug(Foam::regIOobject, 0);
00033 
00034 int Foam::regIOobject::fileModificationSkew
00035 (
00036     Foam::debug::optimisationSwitch("fileModificationSkew", 30)
00037 );
00038 
00039 
00040 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00041 
00042 // Construct from IOobject
00043 Foam::regIOobject::regIOobject(const IOobject& io, const bool isTime)
00044 :
00045     IOobject(io),
00046     registered_(false),
00047     ownedByRegistry_(false),
00048     lastModified_(0),
00049     eventNo_                // Do not get event for top level Time database
00050     (
00051         isTime
00052       ? 0
00053       : db().getEvent()
00054     ),
00055     isPtr_(NULL)
00056 {
00057     // Register with objectRegistry if requested
00058     if (registerObject())
00059     {
00060         checkIn();
00061     }
00062 }
00063 
00064 
00065 // Construct as copy
00066 Foam::regIOobject::regIOobject(const regIOobject& rio)
00067 :
00068     IOobject(rio),
00069     registered_(false),
00070     ownedByRegistry_(false),
00071     lastModified_(rio.lastModified_),
00072     eventNo_(db().getEvent()),
00073     isPtr_(NULL)
00074 {
00075     // Do not register copy with objectRegistry
00076 }
00077 
00078 
00079 // Construct as copy, and transfering objectRegistry registration to copy
00080 // if registerCopy is true
00081 Foam::regIOobject::regIOobject(const regIOobject& rio, bool registerCopy)
00082 :
00083     IOobject(rio),
00084     registered_(false),
00085     ownedByRegistry_(false),
00086     lastModified_(rio.lastModified_),
00087     eventNo_(db().getEvent()),
00088     isPtr_(NULL)
00089 {
00090     if (registerCopy && rio.registered_)
00091     {
00092         const_cast<regIOobject&>(rio).checkOut();
00093         checkIn();
00094     }
00095 }
00096 
00097 
00098 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00099 
00100 // Delete read stream, checkout from objectRegistry and destroy
00101 Foam::regIOobject::~regIOobject()
00102 {
00103     if (objectRegistry::debug)
00104     {
00105         Info<< "Destroying regIOobject called " << name()
00106             << " of type " << type()
00107             << " in directory " << path()
00108             << endl;
00109     }
00110 
00111     if (isPtr_)
00112     {
00113         delete isPtr_;
00114         isPtr_ = NULL;
00115     }
00116 
00117     // Check out of objectRegistry if not owned by the registry
00118 
00119     if (!ownedByRegistry_)
00120     {
00121         checkOut();
00122     }
00123 }
00124 
00125 
00126 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00127 
00128 bool Foam::regIOobject::checkIn()
00129 {
00130     if (!registered_)
00131     {
00132         // multiple checkin of same object is disallowed - this would mess up
00133         // any mapping
00134         registered_ = db().checkIn(*this);
00135 
00136         // check-in on defaultRegion is allowed to fail, since subsetted meshes
00137         // are created with the same name as their originating mesh
00138         if (!registered_ && debug && name() != polyMesh::defaultRegion)
00139         {
00140             if (debug == 2)
00141             {
00142                 // for ease of finding where attempted duplicate check-in
00143                 // originated
00144                 FatalErrorIn("regIOobject::checkIn()")
00145                     << "failed to register object " << objectPath()
00146                     << " the name already exists in the objectRegistry"
00147                     << abort(FatalError);
00148             }
00149             else
00150             {
00151                 WarningIn("regIOobject::checkIn()")
00152                     << "failed to register object " << objectPath()
00153                     << " the name already exists in the objectRegistry"
00154                     << endl;
00155             }
00156         }
00157     }
00158 
00159     return registered_;
00160 }
00161 
00162 
00163 bool Foam::regIOobject::checkOut()
00164 {
00165     if (registered_)
00166     {
00167         registered_ = false;
00168         return db().checkOut(*this);
00169     }
00170 
00171     return false;
00172 }
00173 
00174 
00175 bool Foam::regIOobject::upToDate(const word& a) const
00176 {
00177     if (db().lookupObject<regIOobject>(a).eventNo() >= eventNo_)
00178     {
00179         return false;
00180     }
00181     else
00182     {
00183         return true;
00184     }
00185 }
00186 
00187 
00188 bool Foam::regIOobject::upToDate(const word& a, const word& b) const
00189 {
00190     if
00191     (
00192         db().lookupObject<regIOobject>(a).eventNo() >= eventNo_
00193      || db().lookupObject<regIOobject>(b).eventNo() >= eventNo_
00194     )
00195     {
00196         return false;
00197     }
00198     else
00199     {
00200         return true;
00201     }
00202 }
00203 
00204 
00205 bool Foam::regIOobject::upToDate
00206 (
00207     const word& a,
00208     const word& b,
00209     const word& c
00210 ) const
00211 {
00212     if
00213     (
00214         db().lookupObject<regIOobject>(a).eventNo() >= eventNo_
00215      || db().lookupObject<regIOobject>(b).eventNo() >= eventNo_
00216      || db().lookupObject<regIOobject>(c).eventNo() >= eventNo_
00217     )
00218     {
00219         return false;
00220     }
00221     else
00222     {
00223         return true;
00224     }
00225 }
00226 
00227 
00228 bool Foam::regIOobject::upToDate
00229 (
00230     const word& a,
00231     const word& b,
00232     const word& c,
00233     const word& d
00234 ) const
00235 {
00236     if
00237     (
00238         db().lookupObject<regIOobject>(a).eventNo() >= eventNo_
00239      || db().lookupObject<regIOobject>(b).eventNo() >= eventNo_
00240      || db().lookupObject<regIOobject>(c).eventNo() >= eventNo_
00241      || db().lookupObject<regIOobject>(d).eventNo() >= eventNo_
00242     )
00243     {
00244         return false;
00245     }
00246     else
00247     {
00248         return true;
00249     }
00250 }
00251 
00252 
00253 //- Flag me as up to date
00254 void Foam::regIOobject::setUpToDate()
00255 {
00256     eventNo_ = db().getEvent();
00257 }
00258 
00259 
00260 // Rename object and re-register with objectRegistry under new name
00261 void Foam::regIOobject::rename(const word& newName)
00262 {
00263     // Check out of objectRegistry
00264     checkOut();
00265 
00266     IOobject::rename(newName);
00267 
00268     if (registerObject())
00269     {
00270         // Re-register object with objectRegistry
00271         checkIn();
00272     }
00273 }
00274 
00275 
00276 // Assign to IOobject
00277 void Foam::regIOobject::operator=(const IOobject& io)
00278 {
00279     if (isPtr_)
00280     {
00281         delete isPtr_;
00282         isPtr_ = NULL;
00283     }
00284 
00285     // Check out of objectRegistry
00286     checkOut();
00287 
00288     IOobject::operator=(io);
00289 
00290     if (registerObject())
00291     {
00292         // Re-register object with objectRegistry
00293         checkIn();
00294     }
00295 }
00296 
00297 
00298 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines