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-2019 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 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class objectRegistry Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 class objectRegistry
52 :
53  public regIOobject,
54  public HashTable<regIOobject*>
55 {
56  // Private Data
57 
58  //- Master time objectRegistry
59  const Time& time_;
60 
61  //- Parent objectRegistry
62  const objectRegistry& parent_;
63 
64  //- Local directory path of this objectRegistry relative to time
65  fileName dbDir_;
66 
67  //- Current event
68  mutable label event_;
69 
70 
71  // Private Member Functions
72 
73  //- Is the objectRegistry parent_ different from time_
74  // Used to terminate searching within the ancestors
75  bool parentNotTime() const;
76 
77 
78 public:
79 
80  //- Declare type name for this IOobject
81  TypeName("objectRegistry");
82 
83 
84  // Constructors
85 
86  //- Construct the time objectRegistry given an initial estimate
87  // for the number of entries
88  explicit objectRegistry
89  (
90  const Time& db,
91  const label nIoObjects = 128
92  );
93 
94  //- Construct a sub-registry given an IObject to describe the registry
95  // and an initial estimate for the number of entries
96  explicit objectRegistry
97  (
98  const IOobject& io,
99  const label nIoObjects = 128
100  );
101 
102  //- Disallow default bitwise copy construction
104 
105 
106  //- Destructor
107  virtual ~objectRegistry();
108 
109 
110  // Member Functions
111 
112  // Access
113 
114  //- Return time
115  const Time& time() const
116  {
117  return time_;
118  }
119 
120  //- Return the parent objectRegistry
121  const objectRegistry& parent() const
122  {
123  return parent_;
124  }
125 
126  //- Local directory path of this objectRegistry relative to the time
127  virtual const fileName& dbDir() const
128  {
129  return dbDir_;
130  }
131 
132  //- Return the list of names of the IOobjects
133  wordList names() const;
134 
135  //- Return the sorted list of names of the IOobjects
136  wordList sortedNames() const;
137 
138  //- Return the list of names of IOobjects of given class name
139  wordList names(const word& className) const;
140 
141  //- Return the sorted list of names of IOobjects of given class name
142  wordList sortedNames(const word& className) const;
143 
144  //- Return the list of names of the IOobjects of given type
145  template<class Type>
146  wordList names() const;
147 
148  //- Return the list of objects whose name matches the input regExp
149  template<class Type>
150  wordList names(const wordRe& name) const;
151 
152  //- Return the list of objects whose name matches the input regExp
153  template<class Type>
154  wordList names(const wordReList& name) const;
155 
156  //- Lookup and return a const sub-objectRegistry. Optionally create
157  // it if it does not exist.
159  (
160  const word& name,
161  const bool forceCreate = false
162  ) const;
163 
164  //- Lookup and return all objects of the given Type
165  template<class Type>
166  HashTable<const Type*> lookupClass(const bool strict = false) const;
167 
168  //- Lookup and return all objects of the given Type
169  template<class Type>
170  HashTable<Type*> lookupClass(const bool strict = false);
171 
172  //- Is the named Type found?
173  template<class Type>
174  bool foundObject(const word& name) const;
175 
176  //- Lookup and return the object of the given Type
177  template<class Type>
178  const Type& lookupObject(const word& name) const;
179 
180  //- Lookup and return the object reference of the given Type
181  template<class Type>
182  Type& lookupObjectRef(const word& name) const;
183 
184  //- Return new event number.
185  label getEvent() const;
186 
187 
188  // Edit
189 
190  //- Rename
191  virtual void rename(const word& newName);
192 
193  //- Add an regIOobject to registry
194  bool checkIn(regIOobject&) const;
195 
196  //- Remove an regIOobject from registry
197  bool checkOut(regIOobject&) const;
198 
199  //- Remove all regIOobject owned by the registry
200  void clear();
201 
202 
203  // Reading
204 
205  //- Return true if any of the object's files have been modified
206  virtual bool modified() const;
207 
208  //- Read the objects that have been modified
209  void readModifiedObjects();
210 
211  //- Read object if modified
212  virtual bool readIfModified();
213 
214 
215  // Writing
216 
217  //- writeData function required by regIOobject but not used
218  // for this class, write is used instead
219  virtual bool writeData(Ostream&) const
220  {
222 
223  return false;
224  }
225 
226  //- Write the objects
227  virtual bool writeObject
228  (
232  const bool write
233  ) const;
234 
235 
236  // Member Operators
237 
238  //- Disallow default bitwise assignment
239  void operator=(const objectRegistry&) = delete;
240 };
241 
242 
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 
245 } // End namespace Foam
246 
247 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
248 
249 #ifdef NoRepository
250  #include "objectRegistryTemplates.C"
251 #endif
252 
253 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 
255 #endif
256 
257 // ************************************************************************* //
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:295
A class for handling file names.
Definition: fileName.H:79
void readModifiedObjects()
Read the objects that have been modified.
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
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:53
bool checkOut()
Remove object from registry.
Definition: regIOobject.C:211
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:55
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:354
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:366
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:175
virtual void rename(const word &newName)
Rename.
Namespace for OpenFOAM.