IOobjectList.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 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 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
33 :
34  HashPtrTable<IOobject>(nIoObjects)
35 {}
36 
37 
39 (
40  const objectRegistry& db,
41  const fileName& instance,
42  const fileName& local,
45  bool registerObject
46 )
47 :
49 {
50  word newInstance;
51  fileNameList ObjectNames = fileHandler().readObjects
52  (
53  db,
54  instance,
55  local,
56  newInstance
57  );
58 
59  forAll(ObjectNames, i)
60  {
61  IOobject* objectPtr = new IOobject
62  (
63  ObjectNames[i],
64  newInstance,
65  local,
66  db,
67  r,
68  w,
69  registerObject
70  );
71 
72  // Use object with local scope
73  if (objectPtr->headerOk())
74  {
75  insert(ObjectNames[i], objectPtr);
76  }
77  else
78  {
79  delete objectPtr;
80  }
81  }
82 }
83 
84 
86 :
87  HashPtrTable<IOobject>(ioOL)
88 {}
89 
90 
91 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
92 
94 {}
95 
96 
97 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 
100 {
101  return insert(io.name(), &io);
102 }
103 
104 
106 {
109 
110  if (iter != end())
111  {
112  return erase(iter);
113  }
114  else
115  {
116  return false;
117  }
118 }
119 
120 
122 {
124 
125  if (iter != end())
126  {
127  if (IOobject::debug)
128  {
129  InfoInFunction << "Found " << name << endl;
130  }
131 
132  return const_cast<IOobject*>(*iter);
133  }
134  else
135  {
136  if (IOobject::debug)
137  {
138  InfoInFunction << "Could not find " << name << endl;
139  }
140 
141  return nullptr;
142  }
143 }
144 
145 
147 {
148  IOobjectList objectsOfName(size());
149 
151  {
152  if (name.match(iter()->name()))
153  {
154  if (IOobject::debug)
155  {
156  InfoInFunction << "Found " << iter.key() << endl;
157  }
158 
159  objectsOfName.insert(iter.key(), new IOobject(*iter()));
160  }
161  }
162 
163  return objectsOfName;
164 }
165 
166 
168 {
169  wordReListMatcher names(patterns);
170 
171  IOobjectList objectsOfName(size());
172 
174  {
175  if (names.match(iter()->name()))
176  {
177  if (IOobject::debug)
178  {
179  InfoInFunction << "Found " << iter.key() << endl;
180  }
181 
182  objectsOfName.insert(iter.key(), new IOobject(*iter()));
183  }
184  }
185 
186  return objectsOfName;
187 }
188 
189 
191 {
192  IOobjectList objectsOfClass(size());
193 
195  {
196  if (iter()->headerClassName() == ClassName)
197  {
198  if (IOobject::debug)
199  {
200  InfoInFunction << "Found " << iter.key() << endl;
201  }
202 
203  objectsOfClass.insert(iter.key(), new IOobject(*iter()));
204  }
205  }
206 
207  return objectsOfClass;
208 }
209 
210 
212 {
214 }
215 
216 
218 {
220 }
221 
222 
224 {
225  wordList objectNames(size());
226 
227  label count = 0;
229  {
230  if (iter()->headerClassName() == ClassName)
231  {
232  objectNames[count++] = iter.key();
233  }
234  }
235 
236  objectNames.setSize(count);
237 
238  return objectNames;
239 }
240 
241 
243 {
244  wordList sortedLst = names(ClassName);
245  sort(sortedLst);
246 
247  return sortedLst;
248 }
249 
250 
251 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
writeOption
Enumeration defining the write options.
Definition: IOobject.H:125
const word & name() const
Return name.
Definition: IOobject.H:315
A class for handling file names.
Definition: fileName.H:79
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:112
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
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.
wordList sortedNames() const
Return the sorted list of names of the IOobjects.
Definition: IOobjectList.C:217
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
bool remove(IOobject &)
Remove an IOobject from the list.
Definition: IOobjectList.C:105
wordList names() const
Return the list of names of the IOobjects.
Definition: IOobjectList.C:211
label count(const ListType &l, typename ListType::const_reference x)
Count the number of occurrences of a value in a list.
A HashTable specialisation for hashing pointers.
Definition: HashPtrTable.H:50
readOption
Enumeration defining the read options.
Definition: IOobject.H:116
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:142
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
bool add(IOobject &)
Add an IOobject to the list.
Definition: IOobjectList.C:99
A class for handling words, derived from string.
Definition: word.H:59
void sort(UList< T > &)
Definition: UList.C:115
const fileOperation & fileHandler()
Get current file handler.
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
IOobjectList lookupClass(const word &className) const
Return the list for all IOobjects of a given class.
Definition: IOobjectList.C:190
void setSize(const label)
Reset size of List.
Definition: List.C:281
List< Key > sortedToc() const
Return the table of contents as a sorted list.
Definition: HashTable.C:217
bool match(const string &, bool literalMatch=false) const
Return true if string matches any of the regular expressions.
bool headerOk()
Read header of local object without type-checking.
bool erase(iterator &)
Erase an hashedEntry specified by given iterator.
Definition: HashPtrTable.C:84
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:202
~IOobjectList()
Destructor.
Definition: IOobjectList.C:93
Registry of regIOobjects.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
IOobjectList(const label nIoObjects=128)
Construct given an initial estimate for the number of entries.
Definition: IOobjectList.C:32
bool match(const std::string &, bool literalMatch=false) const
Smart match as regular expression or as a string.
Definition: wordReI.H:202
IOobject * lookup(const word &name) const
Lookup a given name and return IOobject ptr if found else nullptr.
Definition: IOobjectList.C:121
#define InfoInFunction
Report an information message using Foam::Info.