1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "IOobjectList.H"
29 #include "OSspecific.H"
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 Foam::IOobjectList::IOobjectList(const label nIoObjects)
36 HashPtrTable<IOobject>(nIoObjects)
40 Foam::IOobjectList::IOobjectList
42 const objectRegistry& db,
43 const fileName& instance,
47 HashPtrTable<IOobject>()
49 word newInstance = instance;
51 if (!isDir(db.path(instance)))
53 newInstance = db.time().findInstancePath(instant(instance));
55 if (newInstance.empty())
61 // Create list file names in directory
62 fileNameList ObjectNames =
63 readDir(db.path(newInstance, db.dbDir()/local), fileName::FILE);
65 forAll(ObjectNames, i)
67 IOobject* objectPtr = new IOobject
77 if (objectPtr->headerOk())
79 insert(ObjectNames[i], objectPtr);
89 Foam::IOobjectList::IOobjectList(const IOobjectList& ioOL)
91 HashPtrTable<IOobject>(ioOL)
95 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
97 Foam::IOobjectList::~IOobjectList()
101 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
103 bool Foam::IOobjectList::add(IOobject& io)
105 return insert(io.name(), &io);
109 bool Foam::IOobjectList::remove(IOobject& io)
111 HashPtrTable<IOobject>::iterator iter =
112 HashPtrTable<IOobject>::find(io.name());
125 Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const
127 HashPtrTable<IOobject>::const_iterator iter = find(name);
133 Info<< "IOobjectList::lookup : found " << name
137 return const_cast<IOobject*>(*iter);
143 Info<< "IOobjectList::lookup : could not find " << name
152 Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& ClassName) const
154 IOobjectList IOobjectsOfClass(size());
158 HashPtrTable<IOobject>::const_iterator iter = begin();
163 if (iter()->headerClassName() == ClassName)
167 Info<< "IOobjectList::lookupClass : found "
172 IOobjectsOfClass.insert(iter()->name(), new IOobject(*iter()));
176 return IOobjectsOfClass;
180 Foam::wordList Foam::IOobjectList::names() const
182 wordList objectNames(size());
187 HashPtrTable<IOobject>::const_iterator iter = begin();
192 objectNames[count++] = iter()->name();
199 Foam::wordList Foam::IOobjectList::names(const word& ClassName) const
201 wordList objectNames(size());
206 HashPtrTable<IOobject>::const_iterator iter = begin();
211 if (iter()->headerClassName() == ClassName)
213 objectNames[count++] = iter()->name();
217 objectNames.setSize(count);
223 // ************************************************************************* //