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) 2011-2016 OpenFOAM Foundation
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 "Time.H"
28 #include "OSspecific.H"
29 
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
34 :
35  HashPtrTable<IOobject>(nIoObjects)
36 {}
37 
38 
40 (
41  const objectRegistry& db,
42  const fileName& instance,
43  const fileName& local,
46  bool registerObject
47 )
48 :
50 {
51  word newInstance = instance;
52 
53  if (!isDir(db.path(instance)))
54  {
55  newInstance = db.time().findInstancePath(instant(instance));
56 
57  if (newInstance.empty())
58  {
59  return;
60  }
61  }
62 
63  // Create a list of file names in this directory
64  fileNameList ObjectNames =
65  readDir(db.path(newInstance, db.dbDir()/local), fileName::FILE);
66 
67  forAll(ObjectNames, i)
68  {
69  IOobject* objectPtr = new IOobject
70  (
71  ObjectNames[i],
72  newInstance,
73  local,
74  db,
75  r,
76  w,
77  registerObject
78  );
79 
80  if (objectPtr->headerOk())
81  {
82  insert(ObjectNames[i], objectPtr);
83  }
84  else
85  {
86  delete objectPtr;
87  }
88  }
89 }
90 
91 
93 :
94  HashPtrTable<IOobject>(ioOL)
95 {}
96 
97 
98 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
99 
101 {}
102 
103 
104 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
105 
107 {
108  return insert(io.name(), &io);
109 }
110 
111 
113 {
116 
117  if (iter != end())
118  {
119  return erase(iter);
120  }
121  else
122  {
123  return false;
124  }
125 }
126 
127 
129 {
131 
132  if (iter != end())
133  {
134  if (IOobject::debug)
135  {
136  InfoInFunction << "Found " << name << endl;
137  }
138 
139  return const_cast<IOobject*>(*iter);
140  }
141  else
142  {
143  if (IOobject::debug)
144  {
145  InfoInFunction << "Could not find " << name << endl;
146  }
147 
148  return NULL;
149  }
150 }
151 
152 
154 {
155  IOobjectList objectsOfName(size());
156 
158  {
159  if (name.match(iter()->name()))
160  {
161  if (IOobject::debug)
162  {
163  InfoInFunction << "Found " << iter.key() << endl;
164  }
165 
166  objectsOfName.insert(iter.key(), new IOobject(*iter()));
167  }
168  }
169 
170  return objectsOfName;
171 }
172 
173 
175 {
176  wordReListMatcher names(patterns);
177 
178  IOobjectList objectsOfName(size());
179 
181  {
182  if (names.match(iter()->name()))
183  {
184  if (IOobject::debug)
185  {
186  InfoInFunction << "Found " << iter.key() << endl;
187  }
188 
189  objectsOfName.insert(iter.key(), new IOobject(*iter()));
190  }
191  }
192 
193  return objectsOfName;
194 }
195 
196 
198 {
199  IOobjectList objectsOfClass(size());
200 
202  {
203  if (iter()->headerClassName() == ClassName)
204  {
205  if (IOobject::debug)
206  {
207  InfoInFunction << "Found " << iter.key() << endl;
208  }
209 
210  objectsOfClass.insert(iter.key(), new IOobject(*iter()));
211  }
212  }
213 
214  return objectsOfClass;
215 }
216 
217 
219 {
221 }
222 
223 
225 {
227 }
228 
229 
231 {
232  wordList objectNames(size());
233 
234  label count = 0;
236  {
237  if (iter()->headerClassName() == ClassName)
238  {
239  objectNames[count++] = iter.key();
240  }
241  }
242 
243  objectNames.setSize(count);
244 
245  return objectNames;
246 }
247 
248 
250 {
251  wordList sortedLst = names(ClassName);
252  sort(sortedLst);
253 
254  return sortedLst;
255 }
256 
257 
258 // ************************************************************************* //
const Time & time() const
Return time.
wordList names() const
Return the list of names of the IOobjects.
Definition: IOobjectList.C:218
IOobjectList lookupClass(const word &className) const
Return the list for all IOobjects of a given class.
Definition: IOobjectList.C:197
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
writeOption
Enumeration defining the write options.
Definition: IOobject.H:115
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A class for handling file names.
Definition: fileName.H:69
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:50
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:106
wordList sortedNames() const
Return the sorted list of names of the IOobjects.
Definition: IOobjectList.C:224
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
ClassName("HashTable")
Define template name and debug.
bool match(const std::string &, bool literalMatch=false) const
Smart match as regular expression or as a string.
Definition: wordReI.H:202
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
bool remove(IOobject &)
Remove an IOobject from the list.
Definition: IOobjectList.C:112
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:486
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
readOption
Enumeration defining the read options.
Definition: IOobject.H:106
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
fileName path() const
Return complete path.
Definition: IOobject.C:275
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
word findInstancePath(const instant &) const
Search the case for the time directory path.
Definition: Time.C:737
bool add(IOobject &)
Add an IOobject to the list.
Definition: IOobjectList.C:106
A class for handling words, derived from string.
Definition: word.H:59
void sort(UList< T > &)
Definition: UList.C:115
bool match(const string &, bool literalMatch=false) const
Return true if string matches any of the regular expressions.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
List< Key > toc() const
Return the table of contents.
A wordRe is a word, but can also have a regular expression for matching words.
Definition: wordRe.H:74
A wrapper for matching a List of wordRe.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
An instant of time. Contains the time value and name.
Definition: instant.H:64
void setSize(const label)
Reset size of List.
Definition: List.C:295
List< Key > sortedToc() const
Return the table of contents as a sorted list.
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
bool headerOk()
Read and check header info.
Definition: IOobject.C:400
bool erase(iterator &)
Erase an hashedEntry specified by given iterator.
~IOobjectList()
Destructor.
Definition: IOobjectList.C:100
IOobject * lookup(const word &name) const
Lookup a given name and return IOobject ptr if found else NULL.
Definition: IOobjectList.C:128
Registry of regIOobjects.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
IOobjectList(const label nIoObjects=128)
Construct given an initial estimate for the number of entries.
Definition: IOobjectList.C:33
fileNameList readDir(const fileName &, const fileName::Type=fileName::FILE, const bool filtergz=true)
Read a directory and return the entries as a string list.
Definition: POSIX.C:527
const word & name() const
Return name.
Definition: IOobject.H:260
#define InfoInFunction
Report an information message using Foam::Info.