FreeFOAM The Cross-Platform CFD Toolkit
IOobjectList.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "IOobjectList.H"
27 #include <OpenFOAM/Time.H>
28 #include <OpenFOAM/OSspecific.H>
29 
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 Foam::IOobjectList::IOobjectList(const label nIoObjects)
34 :
35  HashPtrTable<IOobject>(nIoObjects)
36 {}
37 
38 
40 (
41  const objectRegistry& db,
42  const fileName& instance,
43  const fileName& local
44 )
45 :
47 {
48  word newInstance = instance;
49 
50  if (!isDir(db.path(instance)))
51  {
52  newInstance = db.time().findInstancePath(instant(instance));
53 
54  if (newInstance.empty())
55  {
56  return;
57  }
58  }
59 
60  // Create list file names in directory
61  fileNameList ObjectNames =
62  readDir(db.path(newInstance, db.dbDir()/local), fileName::FILE);
63 
64  forAll(ObjectNames, i)
65  {
66  IOobject* objectPtr = new IOobject
67  (
68  ObjectNames[i],
69  newInstance,
70  local,
71  db,
74  );
75 
76  if (objectPtr->headerOk())
77  {
78  insert(ObjectNames[i], objectPtr);
79  }
80  else
81  {
82  delete objectPtr;
83  }
84  }
85 }
86 
87 
89 :
90  HashPtrTable<IOobject>(ioOL)
91 {}
92 
93 
94 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
95 
97 {}
98 
99 
100 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
101 
103 {
104  return insert(io.name(), &io);
105 }
106 
107 
109 {
112 
113  if (iter != end())
114  {
115  return erase(iter);
116  }
117  else
118  {
119  return false;
120  }
121 }
122 
123 
125 {
126  HashPtrTable<IOobject>::const_iterator iter = find(name);
127 
128  if (iter != end())
129  {
130  if (IOobject::debug)
131  {
132  Info<< "IOobjectList::lookup : found " << name
133  << endl;
134  }
135 
136  return const_cast<IOobject*>(*iter);
137  }
138  else
139  {
140  if (IOobject::debug)
141  {
142  Info<< "IOobjectList::lookup : could not find " << name
143  << endl;
144  }
145 
146  return NULL;
147  }
148 }
149 
150 
152 {
153  IOobjectList IOobjectsOfClass(size());
154 
155  for
156  (
158  iter != end();
159  ++iter
160  )
161  {
162  if (iter()->headerClassName() == ClassName)
163  {
164  if (IOobject::debug)
165  {
166  Info<< "IOobjectList::lookupClass : found "
167  << iter()->name()
168  << endl;
169  }
170 
171  IOobjectsOfClass.insert(iter()->name(), new IOobject(*iter()));
172  }
173  }
174 
175  return IOobjectsOfClass;
176 }
177 
178 
180 {
181  wordList objectNames(size());
182 
183  label count = 0;
184  for
185  (
187  iter != end();
188  ++iter
189  )
190  {
191  objectNames[count++] = iter()->name();
192  }
193 
194  return objectNames;
195 }
196 
197 
199 {
200  wordList objectNames(size());
201 
202  label count = 0;
203  for
204  (
206  iter != end();
207  ++iter
208  )
209  {
210  if (iter()->headerClassName() == ClassName)
211  {
212  objectNames[count++] = iter()->name();
213  }
214  }
215 
216  objectNames.setSize(count);
217 
218  return objectNames;
219 }
220 
221 
222 // ************************ vim: set sw=4 sts=4 et: ************************ //