1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "IOobjectList.H"
28 #include "OSspecific.H"
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 Foam::IOobjectList::IOobjectList(const label nIoObjects)
35 HashPtrTable<IOobject>(nIoObjects)
39 Foam::IOobjectList::IOobjectList
41 const objectRegistry& db,
42 const fileName& instance,
46 HashPtrTable<IOobject>()
48 word newInstance = instance;
50 if (!isDir(db.path(instance)))
52 newInstance = db.time().findInstancePath(instant(instance));
54 if (newInstance.empty())
60 // Create a list of file names in this directory
61 fileNameList ObjectNames =
62 readDir(db.path(newInstance, db.dbDir()/local), fileName::FILE);
64 forAll(ObjectNames, i)
66 IOobject* objectPtr = new IOobject
76 if (objectPtr->headerOk())
78 insert(ObjectNames[i], objectPtr);
88 Foam::IOobjectList::IOobjectList(const IOobjectList& ioOL)
90 HashPtrTable<IOobject>(ioOL)
94 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
96 Foam::IOobjectList::~IOobjectList()
100 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
102 bool Foam::IOobjectList::add(IOobject& io)
104 return insert(io.name(), &io);
108 bool Foam::IOobjectList::remove(IOobject& io)
110 HashPtrTable<IOobject>::iterator iter =
111 HashPtrTable<IOobject>::find(io.name());
124 Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const
126 HashPtrTable<IOobject>::const_iterator iter = find(name);
132 Info<< "IOobjectList::lookup : found "
136 return const_cast<IOobject*>(*iter);
142 Info<< "IOobjectList::lookup : could not find "
151 Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& ClassName) const
153 IOobjectList objectsOfClass(size());
155 forAllConstIter(HashPtrTable<IOobject>, *this, iter)
157 if (iter()->headerClassName() == ClassName)
161 Info<< "IOobjectList::lookupClass : found "
162 << iter.key() << endl;
165 objectsOfClass.insert(iter.key(), new IOobject(*iter()));
169 return objectsOfClass;
173 Foam::wordList Foam::IOobjectList::names() const
175 return HashPtrTable<IOobject>::toc();
179 Foam::wordList Foam::IOobjectList::sortedNames() const
181 return HashPtrTable<IOobject>::sortedToc();
185 Foam::wordList Foam::IOobjectList::names(const word& ClassName) const
187 wordList objectNames(size());
190 forAllConstIter(HashPtrTable<IOobject>, *this, iter)
192 if (iter()->headerClassName() == ClassName)
194 objectNames[count++] = iter.key();
198 objectNames.setSize(count);
204 Foam::wordList Foam::IOobjectList::sortedNames(const word& ClassName) const
206 wordList sortedLst = names(ClassName);
213 // ************************************************************************* //