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-2015 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  Info<< "IOobjectList::lookup : found "
137  << name << endl;
138  }
139 
140  return const_cast<IOobject*>(*iter);
141  }
142  else
143  {
144  if (IOobject::debug)
145  {
146  Info<< "IOobjectList::lookup : could not find "
147  << name << endl;
148  }
149 
150  return NULL;
151  }
152 }
153 
154 
156 {
157  IOobjectList objectsOfName(size());
158 
160  {
161  if (name.match(iter()->name()))
162  {
163  if (IOobject::debug)
164  {
165  Info<< "IOobjectList::lookupRe : found " << iter.key() << endl;
166  }
167 
168  objectsOfName.insert(iter.key(), new IOobject(*iter()));
169  }
170  }
171 
172  return objectsOfName;
173 }
174 
175 
177 {
178  wordReListMatcher names(patterns);
179 
180  IOobjectList objectsOfName(size());
181 
183  {
184  if (names.match(iter()->name()))
185  {
186  if (IOobject::debug)
187  {
188  Info<< "IOobjectList::lookupRe : found " << iter.key() << endl;
189  }
190 
191  objectsOfName.insert(iter.key(), new IOobject(*iter()));
192  }
193  }
194 
195  return objectsOfName;
196 }
197 
198 
200 {
201  IOobjectList objectsOfClass(size());
202 
204  {
205  if (iter()->headerClassName() == ClassName)
206  {
207  if (IOobject::debug)
208  {
209  Info<< "IOobjectList::lookupClass : found "
210  << iter.key() << endl;
211  }
212 
213  objectsOfClass.insert(iter.key(), new IOobject(*iter()));
214  }
215  }
216 
217  return objectsOfClass;
218 }
219 
220 
222 {
224 }
225 
226 
228 {
230 }
231 
232 
234 {
235  wordList objectNames(size());
236 
237  label count = 0;
239  {
240  if (iter()->headerClassName() == ClassName)
241  {
242  objectNames[count++] = iter.key();
243  }
244  }
245 
246  objectNames.setSize(count);
247 
248  return objectNames;
249 }
250 
251 
253 {
254  wordList sortedLst = names(ClassName);
255  sort(sortedLst);
256 
257  return sortedLst;
258 }
259 
260 
261 // ************************************************************************* //
bool add(IOobject &)
Add an IOobject to the list.
Definition: IOobjectList.C:106
wordList sortedNames() const
Return the sorted list of names of the IOobjects.
Definition: IOobjectList.C:227
void sort(UList< T > &)
Definition: UList.C:107
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:50
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
IOobject * lookup(const word &name) const
Lookup a given name and return IOobject ptr if found else NULL.
Definition: IOobjectList.C:128
List< Key > sortedToc() const
Return the table of contents as a sorted list.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
bool match(const std::string &, bool literalMatch=false) const
Smart match as regular expression or as a string.
Definition: wordReI.H:202
A class for handling words, derived from string.
Definition: word.H:59
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
IOobjectList lookupClass(const word &className) const
Return the list for all IOobjects of a given class.
Definition: IOobjectList.C:199
bool remove(IOobject &)
Remove an IOobject from the list.
Definition: IOobjectList.C:112
messageStream Info
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
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
fileName path() const
Return complete path.
Definition: IOobject.C:299
void setSize(const label)
Reset size of List.
Definition: List.C:318
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
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:661
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
~IOobjectList()
Destructor.
Definition: IOobjectList.C:100
word findInstancePath(const instant &) const
Search the case for the time directory path.
Definition: Time.C:764
readOption
Enumeration defining the read options.
Definition: IOobject.H:106
#define forAll(list, i)
Definition: UList.H:421
ClassName("HashTable")
Define template name and debug.
An instant of time. Contains the time value and name.
Definition: instant.H:64
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
List< Key > toc() const
Return the table of contents.
const word & name() const
Return name.
Definition: IOobject.H:260
bool match(const string &, bool literalMatch=false) const
Return true if string matches any of the regular expressions.
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:616
A wrapper for matching a List of wordRe.
Registry of regIOobjects.
writeOption
Enumeration defining the write options.
Definition: IOobject.H:115
A class for handling file names.
Definition: fileName.H:69
IOobjectList(const label nIoObjects=128)
Construct given an initial estimate for the number of entries.
Definition: IOobjectList.C:33
bool erase(iterator &)
Erase an hashedEntry specified by given iterator.
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:106
wordList names() const
Return the list of names of the IOobjects.
Definition: IOobjectList.C:221
const Time & time() const
Return time.
bool headerOk()
Read and check header info.
Definition: IOobject.C:424
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
A wordRe is a word, but can also have a regular expression for matching words.
Definition: wordRe.H:74
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50