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 // ************************************************************************* //
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
w
volScalarField w(IOobject("w", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE), mesh, dimensionedScalar("w", dimensionSet(0, 0, 0, 0, 0, 0, 0), 0.0))
Foam::fileName::FILE
@ FILE
Definition: fileName.H:85
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::Time::findInstancePath
word findInstancePath(const instant &) const
Search the case for the time directory path.
Definition: Time.C:764
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:117
Foam::wordReListMatcher
A wrapper for matching a List of wordRe.
Definition: wordReListMatcher.H:53
Foam::IOobjectList::sortedNames
wordList sortedNames() const
Return the sorted list of names of the IOobjects.
Definition: IOobjectList.C:227
IOobjectList.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::IOobjectList::names
wordList names() const
Return the list of names of the IOobjects.
Definition: IOobjectList.C:221
erase
srcOptions erase("case")
Foam::wordRe
A wordRe is a word, but can also have a regular expression for matching words.
Definition: wordRe.H:74
Foam::string::match
bool match(const std::string &) const
True when strings match literally.
Definition: stringI.H:179
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::IOobject::headerOk
bool headerOk()
Read and check header info.
Definition: IOobject.C:439
Foam::objectRegistry::dbDir
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
Definition: objectRegistry.H:129
Foam::label
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
Foam::Info
messageStream Info
Foam::IOobject::writeOption
writeOption
Enumeration defining the write options.
Definition: IOobject.H:115
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobject.H:273
Foam::IOobjectList::add
bool add(IOobject &)
Add an IOobject to the list.
Definition: IOobjectList.C:106
Foam::IOobjectList::lookup
IOobject * lookup(const word &name) const
Lookup a given name and return IOobject ptr if found else NULL.
Definition: IOobjectList.C:128
Foam::isDir
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:615
Foam::IOobjectList::lookupClass
IOobjectList lookupClass(const word &className) const
Return the list for all IOobjects of a given class.
Definition: IOobjectList.C:199
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:50
Foam::IOobjectList::remove
bool remove(IOobject &)
Remove an IOobject from the list.
Definition: IOobjectList.C:112
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::IOobjectList::IOobjectList
IOobjectList(const label nIoObjects=128)
Construct given an initial estimate for the number of entries.
Definition: IOobjectList.C:33
ClassName
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition: className.H:69
Foam::HashPtrTable
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
Foam::List
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
Foam::wordReListMatcher::match
bool match(const string &, bool literalMatch=false) const
Return true if string matches any of the regular expressions.
Definition: wordReListMatcherI.H:60
Foam::instant
An instant of time. Contains the time value and name.
Definition: instant.H:64
Foam::IOobject::readOption
readOption
Enumeration defining the read options.
Definition: IOobject.H:106
Foam::sort
void sort(UList< T > &)
Definition: UList.C:107
Foam::readDir
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:660
Foam::IOobjectList::~IOobjectList
~IOobjectList()
Destructor.
Definition: IOobjectList.C:100
Foam::IOobject::path
fileName path() const
Return complete path.
Definition: IOobject.C:293
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
insert
timeIndices insert(timeIndex, timeDirs[timeI].value())