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-2018 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  //- Disallow Copy constructor
79 
80  //- Disallow default bitwise copy construct and assignment
81  void operator=(const objectRegistry&);
82 
83 
84 public:
85 
86  //- Declare type name for this IOobject
87  TypeName("objectRegistry");
88 
89 
90  // Constructors
91 
92  //- Construct the time objectRegistry given an initial estimate
93  // for the number of entries
94  explicit objectRegistry
95  (
96  const Time& db,
97  const label nIoObjects = 128
98  );
99 
100  //- Construct a sub-registry given an IObject to describe the registry
101  // and an initial estimate for the number of entries
102  explicit objectRegistry
103  (
104  const IOobject& io,
105  const label nIoObjects = 128
106  );
107 
108 
109  //- Destructor
110  virtual ~objectRegistry();
111 
112 
113  // Member functions
114 
115  // Access
116 
117  //- Return time
118  const Time& time() const
119  {
120  return time_;
121  }
122 
123  //- Return the parent objectRegistry
124  const objectRegistry& parent() const
125  {
126  return parent_;
127  }
128 
129  //- Local directory path of this objectRegistry relative to the time
130  virtual const fileName& dbDir() const
131  {
132  return dbDir_;
133  }
134 
135  //- Return the list of names of the IOobjects
136  wordList names() const;
137 
138  //- Return the sorted list of names of the IOobjects
139  wordList sortedNames() const;
140 
141  //- Return the list of names of IOobjects of given class name
142  wordList names(const word& className) const;
143 
144  //- Return the sorted list of names of IOobjects of given class name
145  wordList sortedNames(const word& className) const;
146 
147  //- Return the list of names of the IOobjects of given type
148  template<class Type>
149  wordList names() const;
150 
151  //- Return the list of objects whose name matches the input regExp
152  template<class Type>
153  wordList names(const wordRe& name) const;
154 
155  //- Return the list of objects whose name matches the input regExp
156  template<class Type>
157  wordList names(const wordReList& name) const;
158 
159  //- Lookup and return a const sub-objectRegistry. Optionally create
160  // it if it does not exist.
162  (
163  const word& name,
164  const bool forceCreate = false
165  ) const;
166 
167  //- Lookup and return all objects of the given Type
168  template<class Type>
169  HashTable<const Type*> lookupClass(const bool strict = false) const;
170 
171  //- Lookup and return all objects of the given Type
172  template<class Type>
173  HashTable<Type*> lookupClass(const bool strict = false);
174 
175  //- Is the named Type found?
176  template<class Type>
177  bool foundObject(const word& name) const;
178 
179  //- Lookup and return the object of the given Type
180  template<class Type>
181  const Type& lookupObject(const word& name) const;
182 
183  //- Lookup and return the object reference of the given Type
184  template<class Type>
185  Type& lookupObjectRef(const word& name) const;
186 
187  //- Return new event number.
188  label getEvent() const;
189 
190 
191  // Edit
192 
193  //- Rename
194  virtual void rename(const word& newName);
195 
196  //- Add an regIOobject to registry
197  bool checkIn(regIOobject&) const;
198 
199  //- Remove an regIOobject from registry
200  bool checkOut(regIOobject&) const;
201 
202  //- Remove all regIOobject owned by the registry
203  void clear();
204 
205 
206  // Reading
207 
208  //- Return true if any of the object's files have been modified
209  virtual bool modified() const;
210 
211  //- Read the objects that have been modified
212  void readModifiedObjects();
213 
214  //- Read object if modified
215  virtual bool readIfModified();
216 
217 
218  // Writing
219 
220  //- writeData function required by regIOobject but not used
221  // for this class, write is used instead
222  virtual bool writeData(Ostream&) const
223  {
225 
226  return false;
227  }
228 
229  //- Write the objects
230  virtual bool writeObject
231  (
235  const bool valid
236  ) const;
237 };
238 
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 } // End namespace Foam
243 
244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
245 
246 #ifdef NoRepository
247  #include "objectRegistryTemplates.C"
248 #endif
249 
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251 
252 #endif
253 
254 // ************************************************************************* //
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:297
A class for handling file names.
Definition: fileName.H:69
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool valid) const
Write the objects.
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.
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
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:62
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:210
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:65
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.
Registry of regIOobjects.
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:361
#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
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:174
virtual void rename(const word &newName)
Rename.
Namespace for OpenFOAM.