objectRegistry.H
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-2020 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 Class
25  Foam::objectRegistry
26 
27 Description
28  Registry of regIOobjects
29 
30 SourceFiles
31  objectRegistry.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef objectRegistry_H
36 #define objectRegistry_H
37 
38 #include "HashTable.H"
39 #include "regIOobject.H"
40 #include "wordReList.H"
41 #include "HashSet.H"
42 #include "Pair.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 /*---------------------------------------------------------------------------*\
50  Class objectRegistry Declaration
51 \*---------------------------------------------------------------------------*/
52 
53 class objectRegistry
54 :
55  public regIOobject,
56  public HashTable<regIOobject*>
57 {
58  // Private Data
59 
60  //- Master time objectRegistry
61  const Time& time_;
62 
63  //- Parent objectRegistry
64  const objectRegistry& parent_;
65 
66  //- Local directory path of this objectRegistry relative to time
67  fileName dbDir_;
68 
69  //- Current event
70  mutable label event_;
71 
72  //- Table of temporary object names with current state
73  mutable HashTable<Pair<bool>> cacheTemporaryObjects_;
74 
75  //- State of cacheTemporaryObjects_, set true after reading
76  mutable bool cacheTemporaryObjectsSet_;
77 
78  //- Accumulated list of temporary objects available to cache
79  // Used to provide diagnostics in case the requested object is not
80  // available
81  mutable HashSet<word> temporaryObjects_;
82 
83 
84  // Private Member Functions
85 
86  //- Is the objectRegistry parent_ different from time_
87  // Used to terminate searching within the ancestors
88  bool parentNotTime() const;
89 
90  //- Read the cacheTemporaryObjects list from controlDict
91  void readCacheTemporaryObjects() const;
92 
93  //- Delete the current cached object before caching a new object
94  void deleteCachedObject(regIOobject& cachedOb) const;
95 
96 
97 public:
98 
99  //- Declare type name for this IOobject
100  TypeName("objectRegistry");
101 
102 
103  // Constructors
104 
105  //- Construct the time objectRegistry given an initial estimate
106  // for the number of entries
107  explicit objectRegistry
108  (
109  const Time& db,
110  const label nIoObjects = 128
111  );
112 
113  //- Construct a sub-registry given an IObject to describe the registry
114  // and an initial estimate for the number of entries
115  explicit objectRegistry
116  (
117  const IOobject& io,
118  const label nIoObjects = 128
119  );
120 
121  //- Disallow default bitwise copy construction
123 
124 
125  //- Destructor
126  virtual ~objectRegistry();
127 
128 
129  // Member Functions
130 
131  // Access
132 
133  //- Return time
134  const Time& time() const
135  {
136  return time_;
137  }
138 
139  //- Return the parent objectRegistry
140  const objectRegistry& parent() const
141  {
142  return parent_;
143  }
144 
145  //- Local directory path of this objectRegistry relative to the time
146  virtual const fileName& dbDir() const
147  {
148  return dbDir_;
149  }
150 
151  //- Return the list of names of the IOobjects
152  wordList names() const;
153 
154  //- Return the sorted list of names of the IOobjects
155  wordList sortedNames() const;
156 
157  //- Return the list of names of IOobjects of given class name
158  wordList names(const word& className) const;
159 
160  //- Return the sorted list of names of IOobjects of given class name
161  wordList sortedNames(const word& className) const;
162 
163  //- Return the list of names of the IOobjects of given type
164  template<class Type>
165  wordList names() const;
166 
167  //- Return the list of objects whose name matches the input regExp
168  template<class Type>
169  wordList names(const wordRe& name) const;
170 
171  //- Return the list of objects whose name matches the input regExp
172  template<class Type>
173  wordList names(const wordReList& name) const;
174 
175  //- Lookup and return a const sub-objectRegistry. Optionally create
176  // it if it does not exist.
178  (
179  const word& name,
180  const bool forceCreate = false
181  ) const;
182 
183  //- Lookup and return all objects of the given Type
184  template<class Type>
185  HashTable<const Type*> lookupClass(const bool strict = false) const;
186 
187  //- Lookup and return all objects of the given Type
188  template<class Type>
189  HashTable<Type*> lookupClass(const bool strict = false);
190 
191  //- Is the named Type found?
192  template<class Type>
193  bool foundObject(const word& name) const;
194 
195  //- Lookup and return the object of the given Type
196  template<class Type>
197  const Type& lookupObject(const word& name) const;
198 
199  //- Lookup and return the object reference of the given Type
200  template<class Type>
201  Type& lookupObjectRef(const word& name) const;
202 
203  //- Return new event number.
204  label getEvent() const;
205 
206  //- Return the object registry
207  const objectRegistry& thisDb() const
208  {
209  return *this;
210  }
211 
212 
213  // Edit
214 
215  //- Rename
216  virtual void rename(const word& newName);
217 
218  //- Add an regIOobject to registry
219  bool checkIn(regIOobject&) const;
220 
221  //- Remove an regIOobject from registry
222  bool checkOut(regIOobject&) const;
223 
224  //- Remove all regIOobject owned by the registry
225  void clear();
226 
227  //- Add the given name to the set of temporary objects to cache
228  void addTemporaryObject(const word& name) const;
229 
230  //- Return true if given name is in the cacheTemporaryObjects set
231  bool cacheTemporaryObject(const word& name) const;
232 
233  //- Cache the given object
234  template<class Object>
235  bool cacheTemporaryObject(Object& ob) const;
236 
237  //- Reset the cache state of the given object
238  // in the cacheTemporaryObjects set
239  void resetCacheTemporaryObject(const regIOobject& ob) const;
240 
241  //- Check that all objects in the cacheTemporaryObjects set
242  // were cached
243  bool checkCacheTemporaryObjects() const;
244 
245 
246  // Reading
247 
248  //- Return true if any of the object's files have been modified
249  virtual bool modified() const;
250 
251  //- Read the objects that have been modified
252  void readModifiedObjects();
253 
254  //- Read object if modified
255  virtual bool readIfModified();
256 
257 
258  // Writing
259 
260  //- writeData function required by regIOobject but not used
261  // for this class, write is used instead
262  virtual bool writeData(Ostream&) const
263  {
265 
266  return false;
267  }
268 
269  //- Write the objects
270  virtual bool writeObject
271  (
275  const bool write
276  ) const;
277 
278 
279  // Member Operators
280 
281  //- Disallow default bitwise assignment
282  void operator=(const objectRegistry&) = delete;
283 };
284 
285 
286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
287 
288 } // End namespace Foam
289 
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 
292 #ifdef NoRepository
293  #include "objectRegistryTemplates.C"
294 #endif
295 
296 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
297 
298 #endif
299 
300 // ************************************************************************* //
A HashTable with keys but without contents.
Definition: HashSet.H:59
bool cacheTemporaryObject(const word &name) const
Return true if given name is in the cacheTemporaryObjects set.
void addTemporaryObject(const word &name) const
Add the given name to the set of temporary objects to cache.
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
A class for handling file names.
Definition: fileName.H:79
void readModifiedObjects()
Read the objects that have been modified.
const objectRegistry & thisDb() const
Return the object registry.
void resetCacheTemporaryObject(const regIOobject &ob) const
Reset the cache state of the given object.
Type & lookupObjectRef(const word &name) const
Lookup and return the object reference of the given Type.
wordList names() const
Return the list of names of the IOobjects.
virtual bool modified() const
Return true if any of the object&#39;s files have been modified.
void operator=(const objectRegistry &)=delete
Disallow default bitwise assignment.
bool foundObject(const word &name) const
Is the named Type found?
const objectRegistry & parent() const
Return the parent objectRegistry.
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
objectRegistry(const Time &db, const label nIoObjects=128)
Construct the time objectRegistry given an initial estimate.
A class for handling words, derived from string.
Definition: word.H:59
virtual bool writeData(Ostream &) const
writeData function required by regIOobject but not used
wordList sortedNames() const
Return the sorted list of names of the IOobjects.
virtual ~objectRegistry()
Destructor.
label getEvent() const
Return new event number.
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
virtual bool readIfModified()
Read object if modified.
An STL-conforming hash table.
Definition: HashTable.H:61
A wordRe is a word, but can also have a regular expression for matching words.
Definition: wordRe.H:74
bool checkCacheTemporaryObjects() const
Check that all objects in the cacheTemporaryObjects set.
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
bool checkOut()
Remove object from registry.
Definition: regIOobject.C:200
TypeName("objectRegistry")
Declare type name for this IOobject.
const Time & time() const
Return time.
void clear()
Remove all regIOobject owned by the registry.
Version number type.
Definition: IOstream.H:96
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:52
const objectRegistry & subRegistry(const word &name, const bool forceCreate=false) const
Lookup and return a const sub-objectRegistry. Optionally create.
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
virtual bool write(const bool write=true) const
Write using setting from DB.
Registry of regIOobjects.
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:312
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:370
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool write) const
Write the objects.
HashTable< const Type * > lookupClass(const bool strict=false) const
Lookup and return all objects of the given Type.
bool checkIn()
Add object to registry.
Definition: regIOobject.C:164
virtual void rename(const word &newName)
Rename.
Namespace for OpenFOAM.