initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / db / IOobjectList / IOobjectList.C
bloba55f68a42518df908f7cfd1ec746027b92188e39
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
28 #include "Time.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,
44     const fileName& local
47     HashPtrTable<IOobject>()
49     word newInstance = instance;
51     if (!isDir(db.path(instance)))
52     {
53         newInstance = db.time().findInstancePath(instant(instance));
55         if (newInstance.empty())
56         {
57             return;
58         }
59     }
61     // Create list file names in directory
62     fileNameList ObjectNames =
63         readDir(db.path(newInstance, db.dbDir()/local), fileName::FILE);
65     forAll(ObjectNames, i)
66     {
67         IOobject* objectPtr = new IOobject
68         (
69             ObjectNames[i],
70             newInstance,
71             local,
72             db,
73             IOobject::MUST_READ,
74             IOobject::NO_WRITE
75         );
77         if (objectPtr->headerOk())
78         {
79             insert(ObjectNames[i], objectPtr);
80         }
81         else
82         {
83             delete objectPtr;
84         }
85     }
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());
114     if (iter != end())
115     {
116         return erase(iter);
117     }
118     else
119     {
120         return false;
121     }
125 Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const
127     HashPtrTable<IOobject>::const_iterator iter = find(name);
129     if (iter != end())
130     {
131         if (IOobject::debug)
132         {
133             Info<< "IOobjectList::lookup : found " << name
134                 << endl;
135         }
137         return const_cast<IOobject*>(*iter);
138     }
139     else
140     {
141         if (IOobject::debug)
142         {
143             Info<< "IOobjectList::lookup : could not find " << name
144                 << endl;
145         }
147         return NULL;
148     }
152 Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& ClassName) const
154     IOobjectList IOobjectsOfClass(size());
156     for
157     (
158         HashPtrTable<IOobject>::const_iterator iter = begin();
159         iter != end();
160         ++iter
161     )
162     {
163         if (iter()->headerClassName() == ClassName)
164         {
165             if (IOobject::debug)
166             {
167                 Info<< "IOobjectList::lookupClass : found "
168                     << iter()->name()
169                     << endl;
170             }
172             IOobjectsOfClass.insert(iter()->name(), new IOobject(*iter()));
173         }
174     }
176     return IOobjectsOfClass;
180 Foam::wordList Foam::IOobjectList::names() const
182     wordList objectNames(size());
184     label count = 0;
185     for
186     (
187         HashPtrTable<IOobject>::const_iterator iter = begin();
188         iter != end();
189         ++iter
190     )
191     {
192         objectNames[count++] = iter()->name();
193     }
195     return objectNames;
199 Foam::wordList Foam::IOobjectList::names(const word& ClassName) const
201     wordList objectNames(size());
203     label count = 0;
204     for
205     (
206         HashPtrTable<IOobject>::const_iterator iter = begin();
207         iter != end();
208         ++iter
209     )
210     {
211         if (iter()->headerClassName() == ClassName)
212         {
213             objectNames[count++] = iter()->name();
214         }
215     }
217     objectNames.setSize(count);
219     return objectNames;
223 // ************************************************************************* //