objectRegistry.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2019 OpenFOAM Foundation
9  Copyright (C) 2016-2024 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::objectRegistry
29 
30 Description
31  Registry of regIOobjects
32 
33 SourceFiles
34  objectRegistry.C
35  objectRegistryTemplates.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef Foam_objectRegistry_H
40 #define Foam_objectRegistry_H
41 
42 #include "HashTable.H"
43 #include "HashSet.H"
44 #include "UPtrList.H"
45 #include "regIOobject.H"
46 #include "wordRes.H"
47 #include "Pair.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 /*---------------------------------------------------------------------------*\
55  Class objectRegistry Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class objectRegistry
59 :
60  public regIOobject,
61  public HashTable<regIOobject*>
62 {
63  // Private Data
64 
65  //- Master time objectRegistry
66  const Time& time_;
67 
68  //- Parent objectRegistry
69  const objectRegistry& parent_;
70 
71  //- Local directory path of this objectRegistry relative to time
72  fileName dbDir_;
73 
74  //- Current event
75  mutable label event_;
76 
77  //- State of cacheTemporaryObjects_, set true after reading
78  mutable bool cacheTemporaryObjectsActive_;
79 
80  //- Names of temporary object with current state
81  mutable HashTable<Pair<bool>> cacheTemporaryObjects_;
82 
83  //- Accumulated list of temporary objects available to cache
84  // Used to provide diagnostics in case the requested object is not
85  // available
86  mutable wordHashSet temporaryObjects_;
87 
88 
89  // Private Member Functions
90 
91  //- Is the objectRegistry parent_ different from time_
92  // Used to terminate searching within the ancestors
93  bool parentNotTime() const noexcept;
94 
95  //- Read the cacheTemporaryObjects list from Time controlDict
96  void readCacheTemporaryObjects() const;
97 
98  //- Delete the cached object. Eg, before caching a new object
99  //- A nullptr is ignored.
100  void deleteCachedObject(regIOobject* io) const;
101 
102  //- Templated implementation for count()
103  // The number of items with a matching class
104  template<class MatchPredicate1, class MatchPredicate2>
105  static label countImpl
106  (
107  const objectRegistry& list,
108  const MatchPredicate1& matchClass,
109  const MatchPredicate2& matchName
110  );
111 
112  //- Templated implementation for count()
113  // The number of items with a matching class
114  template<class Type, class MatchPredicate>
115  static label countTypeImpl
116  (
117  const objectRegistry& list,
118  const MatchPredicate& matchName
119  );
120 
121  //- Templated implementation for classes()
122  template<class MatchPredicate>
123  static HashTable<wordHashSet> classesImpl
124  (
125  const objectRegistry& list,
126  const MatchPredicate& matchName
127  );
128 
129  //- Templated implementation for names(), sortedNames()
130  template<class MatchPredicate1, class MatchPredicate2>
131  static wordList namesImpl
132  (
133  const objectRegistry& list,
134  const MatchPredicate1& matchClass,
135  const MatchPredicate2& matchName,
136  const bool doSort
137  );
138 
139  //- Templated implementation for names(), sortedNames()
140  template<class Type, class MatchPredicate>
141  static wordList namesTypeImpl
142  (
143  const objectRegistry& list,
144  const MatchPredicate& matchName,
145  const bool doSort
146  );
147 
148  //- Templated implementation for csorted()/sorted()
149  // Called with 'Type' or 'const Type'
150  template<class Type, class MatchPredicate>
151  static UPtrList<Type> objectsTypeImpl
152  (
153  const bool strict, // Check with isType<Type>
154  const objectRegistry& list,
155  const MatchPredicate& matchName,
156  const bool doSort // Sort the list by name
157  );
158 
159  //- Templated implementation for lookupClass()
160  // Called with 'Type' or 'const Type'
161  template<class Type>
162  static HashTable<Type*> lookupClassTypeImpl
163  (
164  const bool strict, // Check with isType<Type>
165  const objectRegistry& list
166  );
167 
168 
169  //- No copy construct
170  objectRegistry(const objectRegistry&) = delete;
171 
172  //- No copy assignment
173  void operator=(const objectRegistry&) = delete;
174 
175 
176 public:
177 
178  //- Declare type name for this IOobject
179  TypeName("objectRegistry");
180 
181 
182  // Constructors
183 
184  //- Construct the time objectRegistry,
185  //- with estimated table capacity (default: 128)
186  explicit objectRegistry
187  (
188  const Time& db,
189  const label initialCapacity = 128
190  );
191 
192  //- Construct sub-registry given an IObject to describe the registry,
193  //- with estimated table capacity (default: 128)
194  explicit objectRegistry
195  (
196  const IOobject& io,
197  const label initialCapacity = 128
198  );
199 
200 
201  //- Destructor, with checkOut() for all objects that are ownedByRegistry
202  virtual ~objectRegistry();
203 
204 
205  // Member Functions
206 
207  // Access
208 
209  //- Return the object registry
210  const objectRegistry& thisDb() const noexcept
211  {
212  return *this;
213  }
214 
215  //- Return the parent objectRegistry
216  const objectRegistry& parent() const noexcept
217  {
218  return parent_;
219  }
220 
221  //- Return time registry
222  const Time& time() const noexcept
223  {
224  return time_;
225  }
226 
227  //- True if the registry is Time
228  bool isTimeDb() const noexcept;
229 
230  //- Local directory path of this objectRegistry relative to the time
231  virtual const fileName& dbDir() const
232  {
233  return dbDir_;
234  }
235 
236 
237  // Helper Functions
238 
239  //- Create an IOobject at the current time instance (timeName)
240  //- with the specified options
242  (
243  const word& name,
244  IOobjectOption ioOpt
245  ) const;
246 
247  //- Create an IOobject at the current time instance (timeName).
248  // By default the object is NO_READ/NO_WRITE/NO_REGISTER
250  (
252  const word& name,
259  ) const;
260 
261 
262  // Summary of classes
263 
264  //- A summary hash of classes used and their associated object names.
265  // Behaviour and usage as per IOobjectList::classes
268  //- A summary hash of classes used and their associated object names,
269  //- restricted to objects that have a matching object name.
270  template<class MatchPredicate>
271  HashTable<wordHashSet> classes(const MatchPredicate& matchName) const;
272 
273 
274  // List-wise access (unsorted)
276  //- Return unsorted list of objects with a class satisfying
277  //- \c isA<Type> or \c isType<Type> (with Strict)
278  // The lifetime of the returned content cannot exceed the parent!
279  template<class Type, bool Strict=false>
281 
282  //- Return unsorted list of objects with a class satisfying
283  //- \c isA<Type> or \c isType<Type> (with Strict)
284  // The lifetime of the returned content cannot exceed the parent!
285  template<class Type, bool Strict=false>
287 
288  //- Return unsorted list of objects with a class satisfying
289  //- \c isA<Type> that also have a matching object name.
290  // The lifetime of the returned content cannot exceed the parent!
291  template<class Type, class MatchPredicate>
292  UPtrList<const Type> cobjects(const MatchPredicate& matchName) const;
293 
294  //- Return sorted list of objects with a class satisfying \c isA<Type>
295  //- that also have a matching object name.
296  // The lifetime of the returned content cannot exceed the parent!
297  template<class Type, class MatchPredicate>
298  UPtrList<Type> objects(const MatchPredicate& matchName);
299 
300 
301  // List-wise access (sorted)
302 
303  //- Return sorted list of objects with a class satisfying
304  //- \c isA<Type> or \c isType<Type> (with Strict)
305  // The lifetime of the returned content cannot exceed the parent!
306  template<class Type, bool Strict=false>
308 
309  //- Return sorted list of objects with a class satisfying
310  //- \c isA<Type> or \c isType<Type> (with Strict)
311  // The lifetime of the returned content cannot exceed the parent!
312  template<class Type, bool Strict=false>
314 
315  //- Return sorted list of objects
316  // The lifetime of the returned content cannot exceed the parent!
318  {
319  return csorted<regIOobject>();
320  }
321 
322  //- Return sorted list of objects
323  // The lifetime of the returned content cannot exceed the parent!
325  {
326  return sorted<regIOobject>();
327  }
328 
329  //- Return sorted list of objects with a class satisfying
330  //- \c isA<Type> that also have a matching object name.
331  // The lifetime of the returned content cannot exceed the parent!
332  template<class Type, class MatchPredicate>
333  UPtrList<const Type> csorted(const MatchPredicate& matchName) const;
334 
335  //- Return sorted list of objects with a class satisfying
336  //- \c isA<Type> that also have a matching object name.
337  // The lifetime of the returned content cannot exceed the parent!
338  template<class Type, class MatchPredicate>
339  UPtrList<Type> sorted(const MatchPredicate& matchName);
340 
341 
342  // Number of items
343 
344  //- The number of objects of the given class name
345  // \note uses the class type() method
346  label count(const char* clsName) const;
347 
348  //- The number of objects of the given class name
349  // \note uses the class type() method
350  template<class MatchPredicate>
351  label count(const MatchPredicate& matchClass) const;
352 
353  //- The number of objects of the given class name
354  // \note uses the class type() method
355  template<class MatchPredicate1, class MatchPredicate2>
356  label count
357  (
358  const MatchPredicate1& matchClass,
359  const MatchPredicate2& matchName
360  ) const;
361 
362  //- The names of objects with a class satisfying \c isA<Type>
363  //
364  // \param strict use \c isType<Type> instead of \c isA<Type>
365  //
366  // \note The values of \c count<Type>() and \c count(Type::typeName)
367  // may be inconsistent, since they use different mechanisms for
368  // testing the class type.
369  // \note If \a Type is \c void, no isA check is used (always true).
370  template<class Type>
371  label count(const bool strict = false) const;
372 
373  //- The names of objects with a class satisfying \c isA<Type>
374  //- that also have a matching object name.
375  //
376  // \note If \a Type is \c void, no isA check is used (always true).
377  template<class Type, class MatchPredicate>
378  label count(const MatchPredicate& matchName) const;
379 
380 
381  // Summary of names
382 
383  //- The unsorted names of all objects
384  wordList names() const;
385 
386  //- The unsorted names of objects with the given class name.
387  // \note uses the class type() method
388  wordList names(const char* clsName) const;
389 
390  //- The unsorted names of objects with a matching class name
391  // \note uses the class type() method
392  template<class MatchPredicate>
393  wordList names(const MatchPredicate& matchClass) const;
394 
395  //- The unsorted names of objects with a matching class name
396  //- that also have a matching object name.
397  // \note uses the class type() method
398  template<class MatchPredicate1, class MatchPredicate2>
400  (
401  const MatchPredicate1& matchClass,
402  const MatchPredicate2& matchName
403  ) const;
404 
405  //- The unsorted names of objects with a class satisfying \c isA<Type>
406  //
407  // \note If \a Type is \c void, no isA check is used (always true).
408  template<class Type>
409  wordList names() const;
410 
411  //- The unsorted names of objects with a class satisfying \c isA<Type>
412  //- that also have a matching object name.
413  //
414  // \note If \a Type is \c void, no isA check is used (always true).
415  template<class Type, class MatchPredicate>
416  wordList names(const MatchPredicate& matchName) const;
417 
418 
419  // Summary of names (sorted)
420 
421  //- The sorted names of all objects
422  wordList sortedNames() const;
423 
424  //- The sorted names of objects with the given class name.
425  // \note uses the class type() method
426  wordList sortedNames(const char* clsName) const;
427 
428  //- The sorted names objects with a matching class name
429  // \note uses the class type() method
430  template<class MatchPredicate>
431  wordList sortedNames(const MatchPredicate& matchClass) const;
432 
433  //- The sorted names of objects with a matching class name
434  //- that also have a matching object name.
435  // \note uses the class type() method
436  template<class MatchPredicate1, class MatchPredicate2>
438  (
439  const MatchPredicate1& matchClass,
440  const MatchPredicate2& matchName
441  ) const;
442 
443  //- The sorted names of objects with a class satisfying \c isA<Type>
444  //
445  // \note If \a Type is \c void, no isA check is used (always true).
446  template<class Type>
447  wordList sortedNames() const;
448 
449  //- The sorted names of objects with a class satisfying \c isA<Type>
450  //- that also have a matching object name.
451  //
452  // \note If \a Type is \c void, no isA check is used (always true).
453  template<class Type, class MatchPredicate>
454  wordList sortedNames(const MatchPredicate& matchName) const;
455 
456 
457  // Lookup
458 
459  //- Lookup and return a const sub-objectRegistry.
460  //
461  // \param forceCreate create it if it does not exist.
462  // \param recursive search parent registries.
464  (
465  const word& name,
466  const bool forceCreate = false,
467  const bool recursive = false
468  ) const;
469 
470 
471  //- Return all objects with a class satisfying
472  //- \c isA<Type> or \c isType<Type> (with Strict)
473  template<class Type, bool Strict=false>
475 
476  //- Return all objects with a class satisfying
477  //- \c isA<Type> or \c isType<Type> (with Strict)
478  template<class Type, bool Strict=false>
480 
481  //- Return all objects with a class satisfying \c isA<Type>
482  //
483  // \param strict use \c isType<Type> instead of \c isA<Type>
484  template<class Type>
485  HashTable<const Type*> lookupClass(const bool strict) const;
486 
487  //- Return all objects with a class satisfying \c isA<Type>
488  //
489  // \param strict use \c isType<Type> instead of \c isA<Type>
490  template<class Type>
491  HashTable<Type*> lookupClass(const bool strict);
492 
493  //- Return const pointer to the regIOobject.
494  //
495  // \param recursive search parent registries
496  //
497  // \return nullptr if the object was not found.
499  (
500  const word& name,
501  const bool recursive = false
502  ) const;
503 
504  //- Does the registry contain the regIOobject object (by name).
505  //
506  // \param name the object name
507  // \param recursive search parent registries
508  bool contains(const word& name, const bool recursive = false) const;
509 
510  //- Is the named Type found?
511  //
512  // \param recursive search parent registries
513  template<class Type>
514  bool foundObject
515  (
516  const word& name,
517  const bool recursive = false
518  ) const;
519 
520  //- Return const pointer to the object of the given Type.
521  //
522  // \param recursive search parent registries
523  //
524  // \return nullptr if the object was not found or had incorrect type.
525  template<class Type>
526  const Type* cfindObject
527  (
528  const word& name,
529  const bool recursive = false
530  ) const;
531 
532  //- Return const pointer to the object of the given Type.
533  //
534  // \param recursive search parent registries
535  //
536  // \return nullptr if the object was not found or had incorrect type.
537  template<class Type>
538  const Type* findObject
539  (
540  const word& name,
541  const bool recursive = false
542  ) const;
543 
544  //- Return non-const pointer to the object of the given Type.
545  //
546  // \param recursive search parent registries
547  //
548  // \return nullptr if the object was not found or had incorrect type.
549  template<class Type>
550  Type* findObject
551  (
552  const word& name,
553  const bool recursive = false
554  );
555 
556  //- Return non-const pointer to the object of the given Type,
557  //- using a const-cast to have it behave like a mutable.
558  // Exercise caution when using.
559  //
560  // \param recursive search parent registries.
561  //
562  // \return nullptr if the object was not found or had incorrect type.
563  template<class Type>
564  Type* getObjectPtr
565  (
566  const word& name,
567  const bool recursive = false
568  ) const;
569 
570  //- Lookup and return const reference to the object
571  //- of the given Type. Fatal if not found or the wrong type.
572  //
573  // \param recursive search parent registries.
574  template<class Type>
575  const Type& lookupObject
576  (
577  const word& name,
578  const bool recursive = false
579  ) const;
580 
581  //- Lookup and return non-const reference to the object
582  //- of the given Type. Fatal if not found or the wrong type.
583  //
584  // \param recursive search parent registries.
585  template<class Type>
586  Type& lookupObjectRef
587  (
588  const word& name,
589  const bool recursive = false
590  ) const;
591 
592 
593  // Events
594 
595  //- Return new event number.
596  label getEvent() const;
597 
598 
599  // Edit
600 
601  //- Add a regIOobject to registry. A nullptr is ignored.
602  bool checkIn(regIOobject* io) const;
603 
604  //- Add a regIOobject to registry
605  bool checkIn(regIOobject& io) const;
606 
607  //- Remove a regIOobject from registry and free memory if the
608  //- object is ownedByRegistry. A nullptr is ignored.
609  bool checkOut(regIOobject* io) const;
610 
611  //- Remove a regIOobject from registry and free memory if the
612  //- object is ownedByRegistry.
613  bool checkOut(regIOobject& io) const;
614 
615  //- Remove a regIOobject by name from registry and free memory if the
616  //- object is ownedByRegistry
617  bool checkOut(const word& key) const;
618 
619  //- Clear all entries from the registry
620  // Performs a checkOut() for all objects that are ownedByRegistry
621  void clear();
622 
623  //- Clear all entries from the registry and the table itself.
624  void clearStorage();
625 
626  //- Erase an entry specified by the given iterator.
627  // Performs a checkOut() if the object was ownedByRegistry.
628  // \return True if the entry existed and was removed
629  bool erase(const iterator& iter);
630 
631  //- Erase an entry specified by the given key
632  // Performs a checkOut() if the object was ownedByRegistry.
633  // \return True if the entry existed and was removed
634  bool erase(const word& key);
635 
636  //- Remove entries given by the listed keys
637  // Performs a checkOut() for all objects that are ownedByRegistry.
638  // \return The number of items removed
639  label erase(std::initializer_list<word> keys);
640 
641  //- Remove entries given by the listed keys
642  // Performs a checkOut() for all objects that are ownedByRegistry.
643  // \return The number of items removed
644  label erase(const UList<word>& keys);
645 
646  //- Rename
647  virtual void rename(const word& newName);
648 
649 
650  // Temporaries
651 
652  //FUTURE //- Add given name to the set of temporary objects to cache
653  //FUTURE void addTemporaryObject(const word& name) const;
654 
655  //- True if given name is in the cacheTemporaryObjects set
656  bool is_cacheTemporaryObject(const word& name) const;
657 
658  //- True if name of object is in the cacheTemporaryObjects set
659  bool is_cacheTemporaryObject(const regIOobject* io) const;
660 
661  //- True if name of object is in the cacheTemporaryObjects set
662  bool is_cacheTemporaryObject(const regIOobject& io) const;
663 
664  //- Cache the given object. Moves content and stores
665  template<class Type>
666  bool cacheTemporaryObject(Type& obj) const;
667 
668  //- Reset the cache state of the given object (nullptr is ignored)
669  void resetCacheTemporaryObject(const regIOobject* io) const;
670 
671  //- Reset the cache state of the given object
672  //- in the cacheTemporaryObjects set
673  void resetCacheTemporaryObject(const regIOobject& io) const;
674 
675  //- Check that all objects specified in the cacheTemporaryObjects
676  //- were also cached
677  bool checkCacheTemporaryObjects() const;
678 
679 
680  // Reading
681 
682  //- Return true if any of the object's files have been modified
683  virtual bool modified() const;
684 
685  //- Read the objects that have been modified
686  void readModifiedObjects();
687 
688  //- Read object if modified
689  virtual bool readIfModified();
690 
691 
692  // Writing
693 
694  //- The writeData function is required by regIOobject but not used.
695  // For this class, write is used instead
696  virtual bool writeData(Ostream&) const
697  {
699  return false;
700  }
701 
702  //- Write the objects using stream options
703  virtual bool writeObject
704  (
705  IOstreamOption streamOpt,
706  const bool writeOnProc
707  ) const;
708 
709 
710  // Housekeeping
711 
712  //- Same as contains()
713  bool found(const word& name, bool recursive = false) const
714  {
715  return this->contains(name, recursive);
716  }
717 
718  //- Deprecated(2018-10) find object
719  // \deprecated(2018-10) - use findObject() method
720  template<class Type>
721  FOAM_DEPRECATED_FOR(2018-10, "findObject / cfindObject() methods")
722  const Type* lookupObjectPtr
723  (
724  const word& name,
725  bool recursive = false
726  ) const
727  {
728  return this->cfindObject<Type>(name, recursive);
729  }
730 
731  //- Deprecated(2018-10) get object pointer, ignoring constness
732  // \deprecated(2018-10) - use getObjectPtr() method
733  template<class Type>
734  FOAM_DEPRECATED_FOR(2018-10, "getObjectPtr() method")
735  Type* lookupObjectRefPtr
736  (
737  const word& name,
738  bool recursive = false
739  ) const
740  {
741  return this->getObjectPtr<Type>(name, recursive);
742  }
743 
744  //- Deprecated(2023-07) use csorted() method
745  // \deprecated(2023-07) - use csorted() method
746  template<class Type>
747  FOAM_DEPRECATED_FOR(2023-07, "csorted() method")
748  UPtrList<const Type> sorted() const
749  {
750  return csorted<Type>();
751  }
752 
753  //- Deprecated(2023-07) use csorted() method
754  // \deprecated(2023-07) - use csorted() method
755  FOAM_DEPRECATED_FOR(2023-07, "csorted() method")
756  UPtrList<const regIOobject> sorted() const
757  {
758  return csorted<regIOobject>();
759  }
760 
761  //- Deprecated(2023-07) use csorted() method
762  // \deprecated(2023-07) - use csorted() method
763  template<class Type, class MatchPredicate>
764  FOAM_DEPRECATED_FOR(2023-07, "csorted() method")
765  UPtrList<const Type> sorted(const MatchPredicate& matchName) const
766  {
767  return csorted<Type>(matchName);
768  }
769 };
770 
771 
772 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
773 
774 } // End namespace Foam
775 
776 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
777 
778 #ifdef NoRepository
779  #include "objectRegistryTemplates.C"
780 #endif
781 
782 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
783 
784 #endif
785 
786 // ************************************************************************* //
bool cacheTemporaryObject(Type &obj) const
Cache the given object. Moves content and stores.
bool contains(const word &name, const bool recursive=false) const
Does the registry contain the regIOobject object (by name).
writeOption
Enumeration defining write preferences.
const Type & lookupObject(const word &name, const bool recursive=false) const
Lookup and return const reference to the object of the given Type. Fatal if not found or the wrong ty...
A class for handling file names.
Definition: fileName.H:72
void readModifiedObjects()
Read the objects that have been modified.
Type & lookupObjectRef(const word &name, const bool recursive=false) const
Lookup and return non-const reference to the object of the given Type. Fatal if not found or the wron...
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
bool erase(const iterator &iter)
Erase an entry specified by the given iterator.
UPtrList< const Type > csorted() const
Return sorted list of objects with a class satisfying isA<Type> or isType<Type> (with Strict) ...
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
Definition: regIOobject.C:43
wordList names() const
The unsorted names of all objects.
virtual bool modified() const
Return true if any of the object&#39;s files have been modified.
const Type * findObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
A simple container for options an IOstream can normally have.
Ignore writing from objectRegistry::writeObject()
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
const objectRegistry & subRegistry(const word &name, const bool forceCreate=false, const bool recursive=false) const
Lookup and return a const sub-objectRegistry.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
HashTable< const Type * > lookupClass() const
Return all objects with a class satisfying isA<Type> or isType<Type> (with Strict) ...
UPtrList< Type > sorted()
Return sorted list of objects with a class satisfying isA<Type> or isType<Type> (with Strict) ...
bool is_cacheTemporaryObject(const word &name) const
True if given name is in the cacheTemporaryObjects set.
class FOAM_DEPRECATED_FOR(2017-05, "Foam::Enum") NamedEnum
Definition: NamedEnum.H:65
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write the objects using stream options.
label count(const char *clsName) const
The number of objects of the given class name.
A class for handling words, derived from Foam::string.
Definition: word.H:63
Type * getObjectPtr(const word &name, const bool recursive=false) const
Return non-const pointer to the object of the given Type, using a const-cast to have it behave like a...
virtual bool writeData(Ostream &) const
The writeData function is required by regIOobject but not used.
const Time & time() const noexcept
Return time registry.
wordList sortedNames() const
The sorted names of all objects.
virtual ~objectRegistry()
Destructor, with checkOut() for all objects that are ownedByRegistry.
label getEvent() const
Return new event number.
const objectRegistry & db() const noexcept
Return the local objectRegistry.
Definition: IOobject.C:450
virtual bool readIfModified()
Read object if modified.
A HashTable similar to std::unordered_map.
Definition: HashTable.H:108
bool checkCacheTemporaryObjects() const
Check that all objects specified in the cacheTemporaryObjects were also cached.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
Type * lookupObjectRefPtr(const word &name, bool recursive=false) const
Deprecated(2018-10) get object pointer, ignoring constness.
bool isTimeDb() const noexcept
True if the registry is Time.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
void resetCacheTemporaryObject(const regIOobject *io) const
Reset the cache state of the given object (nullptr is ignored)
const direction noexcept
Definition: Scalar.H:258
bool checkOut()
Remove object from registry, and remove all file watches.
Definition: regIOobject.C:221
TypeName("objectRegistry")
Declare type name for this IOobject.
void clearStorage()
Clear all entries from the registry and the table itself.
registerOption
Enumeration for use with registerObject(). Values map to bool (false/true)
UPtrList< const Type > cobjects() const
Return unsorted list of objects with a class satisfying isA<Type> or isType<Type> (with Strict) ...
List< word > wordList
List of word.
Definition: fileName.H:59
const Type * lookupObjectPtr(const word &name, bool recursive=false) const
Deprecated(2018-10) find object.
const objectRegistry & parent() const noexcept
Return the parent objectRegistry.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103
UPtrList< Type > objects()
Return unsorted list of objects with a class satisfying isA<Type> or isType<Type> (with Strict) ...
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
Nothing to be read.
void clear()
Clear all entries from the registry.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:68
bool found(const word &name, bool recursive=false) const
Same as contains()
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
bool foundObject(const word &name, const bool recursive=false) const
Is the named Type found?
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
IOobject newIOobject(const word &name, IOobjectOption ioOpt) const
Create an IOobject at the current time instance (timeName) with the specified options.
Registry of regIOobjects.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:696
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
const objectRegistry & thisDb() const noexcept
Return the object registry.
const_iterator_pair< const_key_iterator, this_type > keys() const
A const iterator begin/end pair for iterating over keys.
Definition: HashTable.H:1295
bool checkIn()
Add object to registry, if not already registered.
Definition: regIOobject.C:184
const regIOobject * cfindIOobject(const word &name, const bool recursive=false) const
Return const pointer to the regIOobject.
Do not request registration (bool: false)
virtual void rename(const word &newName)
Rename.
Namespace for OpenFOAM.
HashTable< wordHashSet > classes() const
A summary hash of classes used and their associated object names.
readOption
Enumeration defining read preferences.