OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "regIOobject.H"
00028 #include "Time.H"
00029 #include "polyMesh.H"
00030 
00031 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00032 
00033 defineTypeNameAndDebug(Foam::regIOobject, 0);
00034 
00035 int Foam::regIOobject::fileModificationSkew
00036 (
00037     Foam::debug::optimisationSwitch("fileModificationSkew", 30)
00038 );
00039 
00040 
00041 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00042 
00043 // Construct from IOobject
00044 Foam::regIOobject::regIOobject(const IOobject& io, const bool isTime)
00045 :
00046     IOobject(io),
00047     registered_(false),
00048     ownedByRegistry_(false),
00049     lastModified_(0),
00050     eventNo_                // Do not get event for top level Time database
00051     (
00052         isTime
00053       ? 0
00054       : db().getEvent()
00055     ),
00056     isPtr_(NULL)
00057 {
00058     // Register with objectRegistry if requested
00059     if (registerObject())
00060     {
00061         checkIn();
00062     }
00063 }
00064 
00065 
00066 // Construct as copy
00067 Foam::regIOobject::regIOobject(const regIOobject& rio)
00068 :
00069     IOobject(rio),
00070     registered_(false),
00071     ownedByRegistry_(false),
00072     lastModified_(rio.lastModified_),
00073     eventNo_(db().getEvent()),
00074     isPtr_(NULL)
00075 {
00076     // Do not register copy with objectRegistry
00077 }
00078 
00079 
00080 // Construct as copy, and transfering objectRegistry registration to copy
00081 // if registerCopy is true
00082 Foam::regIOobject::regIOobject(const regIOobject& rio, bool registerCopy)
00083 :
00084     IOobject(rio),
00085     registered_(false),
00086     ownedByRegistry_(false),
00087     lastModified_(rio.lastModified_),
00088     eventNo_(db().getEvent()),
00089     isPtr_(NULL)
00090 {
00091     if (registerCopy && rio.registered_)
00092     {
00093         const_cast<regIOobject&>(rio).checkOut();
00094         checkIn();
00095     }
00096 }
00097 
00098 
00099 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00100 
00101 // Delete read stream, checkout from objectRegistry and destroy
00102 Foam::regIOobject::~regIOobject()
00103 {
00104     if (objectRegistry::debug)
00105     {
00106         Info<< "Destroying regIOobject called " << name()
00107             << " of type " << type()
00108             << " in directory " << path()
00109             << endl;
00110     }
00111 
00112     if (isPtr_)
00113     {
00114         delete isPtr_;
00115         isPtr_ = NULL;
00116     }
00117 
00118     // Check out of objectRegistry if not owned by the registry
00119 
00120     if (!ownedByRegistry_)
00121     {
00122         checkOut();
00123     }
00124 }
00125 
00126 
00127 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00128 
00129 bool Foam::regIOobject::checkIn()
00130 {
00131     if (!registered_)
00132     {
00133         // multiple checkin of same object is disallowed - this would mess up
00134         // any mapping
00135         registered_ = db().checkIn(*this);
00136 
00137         // check-in on defaultRegion is allowed to fail, since subsetted meshes
00138         // are created with the same name as their originating mesh
00139         if (!registered_ && debug && name() != polyMesh::defaultRegion)
00140         {
00141             if (debug == 2)
00142             {
00143                 // for ease of finding where attempted duplicate check-in
00144                 // originated
00145                 FatalErrorIn("regIOobject::checkIn()")
00146                     << "failed to register object " << objectPath()
00147                     << " the name already exists in the objectRegistry"
00148                     << abort(FatalError);
00149             }
00150             else
00151             {
00152                 WarningIn("regIOobject::checkIn()")
00153                     << "failed to register object " << objectPath()
00154                     << " the name already exists in the objectRegistry"
00155                     << endl;
00156             }
00157         }
00158     }
00159 
00160     return registered_;
00161 }
00162 
00163 
00164 bool Foam::regIOobject::checkOut()
00165 {
00166     if (registered_)
00167     {
00168         registered_ = false;
00169         return db().checkOut(*this);
00170     }
00171 
00172     return false;
00173 }
00174 
00175 
00176 bool Foam::regIOobject::upToDate(const word& a) const
00177 {
00178     if (db().lookupObject<regIOobject>(a).eventNo() >= eventNo_)
00179     {
00180         return false;
00181     }
00182     else
00183     {
00184         return true;
00185     }
00186 }
00187 
00188 
00189 bool Foam::regIOobject::upToDate(const word& a, const word& b) const
00190 {
00191     if
00192     (
00193         db().lookupObject<regIOobject>(a).eventNo() >= eventNo_
00194      || db().lookupObject<regIOobject>(b).eventNo() >= eventNo_
00195     )
00196     {
00197         return false;
00198     }
00199     else
00200     {
00201         return true;
00202     }
00203 }
00204 
00205 
00206 bool Foam::regIOobject::upToDate
00207 (
00208     const word& a,
00209     const word& b,
00210     const word& c
00211 ) const
00212 {
00213     if
00214     (
00215         db().lookupObject<regIOobject>(a).eventNo() >= eventNo_
00216      || db().lookupObject<regIOobject>(b).eventNo() >= eventNo_
00217      || db().lookupObject<regIOobject>(c).eventNo() >= eventNo_
00218     )
00219     {
00220         return false;
00221     }
00222     else
00223     {
00224         return true;
00225     }
00226 }
00227 
00228 
00229 bool Foam::regIOobject::upToDate
00230 (
00231     const word& a,
00232     const word& b,
00233     const word& c,
00234     const word& d
00235 ) const
00236 {
00237     if
00238     (
00239         db().lookupObject<regIOobject>(a).eventNo() >= eventNo_
00240      || db().lookupObject<regIOobject>(b).eventNo() >= eventNo_
00241      || db().lookupObject<regIOobject>(c).eventNo() >= eventNo_
00242      || db().lookupObject<regIOobject>(d).eventNo() >= eventNo_
00243     )
00244     {
00245         return false;
00246     }
00247     else
00248     {
00249         return true;
00250     }
00251 }
00252 
00253 
00254 //- Flag me as up to date
00255 void Foam::regIOobject::setUpToDate()
00256 {
00257     eventNo_ = db().getEvent();
00258 }
00259 
00260 
00261 // Rename object and re-register with objectRegistry under new name
00262 void Foam::regIOobject::rename(const word& newName)
00263 {
00264     // Check out of objectRegistry
00265     checkOut();
00266 
00267     IOobject::rename(newName);
00268 
00269     if (registerObject())
00270     {
00271         // Re-register object with objectRegistry
00272         checkIn();
00273     }
00274 }
00275 
00276 
00277 // Assign to IOobject
00278 void Foam::regIOobject::operator=(const IOobject& io)
00279 {
00280     if (isPtr_)
00281     {
00282         delete isPtr_;
00283         isPtr_ = NULL;
00284     }
00285 
00286     // Check out of objectRegistry
00287     checkOut();
00288 
00289     IOobject::operator=(io);
00290 
00291     if (registerObject())
00292     {
00293         // Re-register object with objectRegistry
00294         checkIn();
00295     }
00296 }
00297 
00298 
00299 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd