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

IOobjectList.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 "IOobjectList.H"
00027 #include <OpenFOAM/Time.H>
00028 #include <OpenFOAM/OSspecific.H>
00029 
00030 
00031 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00032 
00033 Foam::IOobjectList::IOobjectList(const label nIoObjects)
00034 :
00035     HashPtrTable<IOobject>(nIoObjects)
00036 {}
00037 
00038 
00039 Foam::IOobjectList::IOobjectList
00040 (
00041     const objectRegistry& db,
00042     const fileName& instance,
00043     const fileName& local
00044 )
00045 :
00046     HashPtrTable<IOobject>()
00047 {
00048     word newInstance = instance;
00049 
00050     if (!isDir(db.path(instance)))
00051     {
00052         newInstance = db.time().findInstancePath(instant(instance));
00053 
00054         if (newInstance.empty())
00055         {
00056             return;
00057         }
00058     }
00059 
00060     // Create list file names in directory
00061     fileNameList ObjectNames =
00062         readDir(db.path(newInstance, db.dbDir()/local), fileName::FILE);
00063 
00064     forAll(ObjectNames, i)
00065     {
00066         IOobject* objectPtr = new IOobject
00067         (
00068             ObjectNames[i],
00069             newInstance,
00070             local,
00071             db,
00072             IOobject::MUST_READ,
00073             IOobject::NO_WRITE
00074         );
00075 
00076         if (objectPtr->headerOk())
00077         {
00078             insert(ObjectNames[i], objectPtr);
00079         }
00080         else
00081         {
00082             delete objectPtr;
00083         }
00084     }
00085 }
00086 
00087 
00088 Foam::IOobjectList::IOobjectList(const IOobjectList& ioOL)
00089 :
00090     HashPtrTable<IOobject>(ioOL)
00091 {}
00092 
00093 
00094 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
00095 
00096 Foam::IOobjectList::~IOobjectList()
00097 {}
00098 
00099 
00100 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00101 
00102 bool Foam::IOobjectList::add(IOobject& io)
00103 {
00104     return insert(io.name(), &io);
00105 }
00106 
00107 
00108 bool Foam::IOobjectList::remove(IOobject& io)
00109 {
00110     HashPtrTable<IOobject>::iterator iter =
00111         HashPtrTable<IOobject>::find(io.name());
00112 
00113     if (iter != end())
00114     {
00115         return erase(iter);
00116     }
00117     else
00118     {
00119         return false;
00120     }
00121 }
00122 
00123 
00124 Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const
00125 {
00126     HashPtrTable<IOobject>::const_iterator iter = find(name);
00127 
00128     if (iter != end())
00129     {
00130         if (IOobject::debug)
00131         {
00132             Info<< "IOobjectList::lookup : found " << name
00133                 << endl;
00134         }
00135 
00136         return const_cast<IOobject*>(*iter);
00137     }
00138     else
00139     {
00140         if (IOobject::debug)
00141         {
00142             Info<< "IOobjectList::lookup : could not find " << name
00143                 << endl;
00144         }
00145 
00146         return NULL;
00147     }
00148 }
00149 
00150 
00151 Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& ClassName) const
00152 {
00153     IOobjectList IOobjectsOfClass(size());
00154 
00155     for
00156     (
00157         HashPtrTable<IOobject>::const_iterator iter = begin();
00158         iter != end();
00159         ++iter
00160     )
00161     {
00162         if (iter()->headerClassName() == ClassName)
00163         {
00164             if (IOobject::debug)
00165             {
00166                 Info<< "IOobjectList::lookupClass : found "
00167                     << iter()->name()
00168                     << endl;
00169             }
00170 
00171             IOobjectsOfClass.insert(iter()->name(), new IOobject(*iter()));
00172         }
00173     }
00174 
00175     return IOobjectsOfClass;
00176 }
00177 
00178 
00179 Foam::wordList Foam::IOobjectList::names() const
00180 {
00181     wordList objectNames(size());
00182 
00183     label count = 0;
00184     for
00185     (
00186         HashPtrTable<IOobject>::const_iterator iter = begin();
00187         iter != end();
00188         ++iter
00189     )
00190     {
00191         objectNames[count++] = iter()->name();
00192     }
00193 
00194     return objectNames;
00195 }
00196 
00197 
00198 Foam::wordList Foam::IOobjectList::names(const word& ClassName) const
00199 {
00200     wordList objectNames(size());
00201 
00202     label count = 0;
00203     for
00204     (
00205         HashPtrTable<IOobject>::const_iterator iter = begin();
00206         iter != end();
00207         ++iter
00208     )
00209     {
00210         if (iter()->headerClassName() == ClassName)
00211         {
00212             objectNames[count++] = iter()->name();
00213         }
00214     }
00215 
00216     objectNames.setSize(count);
00217 
00218     return objectNames;
00219 }
00220 
00221 
00222 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines