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-2018 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 #include "IOList.H"
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;
52  fileNameList ObjectNames = fileHandler().readObjects
53  (
54  db,
55  instance,
56  local,
57  newInstance
58  );
59 
60 
61  forAll(ObjectNames, i)
62  {
63  IOobject* objectPtr = new IOobject
64  (
65  ObjectNames[i],
66  newInstance,
67  local,
68  db,
69  r,
70  w,
71  registerObject
72  );
73 
74  // Use object with local scope
75  if (objectPtr->typeHeaderOk<IOList<label>>(false))
76  {
77  insert(ObjectNames[i], objectPtr);
78  }
79  else
80  {
81  delete objectPtr;
82  }
83  }
84 }
85 
86 
88 :
89  HashPtrTable<IOobject>(ioOL)
90 {}
91 
92 
93 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
94 
96 {}
97 
98 
99 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
100 
102 {
103  return insert(io.name(), &io);
104 }
105 
106 
108 {
111 
112  if (iter != end())
113  {
114  return erase(iter);
115  }
116  else
117  {
118  return false;
119  }
120 }
121 
122 
124 {
126 
127  if (iter != end())
128  {
129  if (IOobject::debug)
130  {
131  InfoInFunction << "Found " << name << endl;
132  }
133 
134  return const_cast<IOobject*>(*iter);
135  }
136  else
137  {
138  if (IOobject::debug)
139  {
140  InfoInFunction << "Could not find " << name << endl;
141  }
142 
143  return nullptr;
144  }
145 }
146 
147 
149 {
150  IOobjectList objectsOfName(size());
151 
153  {
154  if (name.match(iter()->name()))
155  {
156  if (IOobject::debug)
157  {
158  InfoInFunction << "Found " << iter.key() << endl;
159  }
160 
161  objectsOfName.insert(iter.key(), new IOobject(*iter()));
162  }
163  }
164 
165  return objectsOfName;
166 }
167 
168 
170 {
171  wordReListMatcher names(patterns);
172 
173  IOobjectList objectsOfName(size());
174 
176  {
177  if (names.match(iter()->name()))
178  {
179  if (IOobject::debug)
180  {
181  InfoInFunction << "Found " << iter.key() << endl;
182  }
183 
184  objectsOfName.insert(iter.key(), new IOobject(*iter()));
185  }
186  }
187 
188  return objectsOfName;
189 }
190 
191 
193 {
194  IOobjectList objectsOfClass(size());
195 
197  {
198  if (iter()->headerClassName() == ClassName)
199  {
200  if (IOobject::debug)
201  {
202  InfoInFunction << "Found " << iter.key() << endl;
203  }
204 
205  objectsOfClass.insert(iter.key(), new IOobject(*iter()));
206  }
207  }
208 
209  return objectsOfClass;
210 }
211 
212 
214 {
216 }
217 
218 
220 {
222 }
223 
224 
226 {
227  wordList objectNames(size());
228 
229  label count = 0;
231  {
232  if (iter()->headerClassName() == ClassName)
233  {
234  objectNames[count++] = iter.key();
235  }
236  }
237 
238  objectNames.setSize(count);
239 
240  return objectNames;
241 }
242 
243 
245 {
246  wordList sortedLst = names(ClassName);
247  sort(sortedLst);
248 
249  return sortedLst;
250 }
251 
252 
253 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
writeOption
Enumeration defining the write options.
Definition: IOobject.H:119
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
const word & name() const
Return name.
Definition: IOobject.H:303
bool typeHeaderOk(const bool checkType=true)
Read header (uses typeFilePath to find file) and check header.
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
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:219
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:107
wordList names() const
Return the list of names of the IOobjects.
Definition: IOobjectList.C:213
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:110
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:101
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.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
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:192
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 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:95
Registry of regIOobjects.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
IOobjectList(const label nIoObjects=128)
Construct given an initial estimate for the number of entries.
Definition: IOobjectList.C:33
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:123
#define InfoInFunction
Report an information message using Foam::Info.