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 | Copyright (C) 2011-2016 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  //- Return new event number.
184  label getEvent() const;
185 
186 
187  // Edit
188 
189  //- Rename
190  virtual void rename(const word& newName);
191 
192  //- Add an regIOobject to registry
193  bool checkIn(regIOobject&) const;
194 
195  //- Remove an regIOobject from registry
196  bool checkOut(regIOobject&) const;
197 
198  // Reading
199 
200  //- Return true if any of the object's files have been modified
201  virtual bool modified() const;
202 
203  //- Read the objects that have been modified
204  void readModifiedObjects();
205 
206  //- Read object if modified
207  virtual bool readIfModified();
208 
209 
210  // Writing
211 
212  //- writeData function required by regIOobject but not used
213  // for this class, write is used instead
214  virtual bool writeData(Ostream&) const
215  {
217 
218  return false;
219  }
220 
221  //- Write the objects
222  virtual bool writeObject
223  (
227  ) const;
228 };
229 
230 
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 
233 } // End namespace Foam
234 
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 
237 #ifdef NoRepository
238  #include "objectRegistryTemplates.C"
239 #endif
240 
241 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 
243 #endif
244 
245 // ************************************************************************* //
const Time & time() const
Return time.
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
A class for handling file names.
Definition: fileName.H:69
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:221
void readModifiedObjects()
Read the objects that have been modified.
bool foundObject(const word &name) const
Is the named Type found?
const objectRegistry & parent() const
Return the parent objectRegistry.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
virtual bool modified() const
Return true if any of the object&#39;s files have been modified.
const objectRegistry & subRegistry(const word &name, const bool forceCreate=false) const
Lookup and return a const sub-objectRegistry. Optionally create.
A class for handling words, derived from string.
Definition: word.H:59
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp) const
Write the objects.
virtual ~objectRegistry()
Destructor.
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
virtual bool readIfModified()
Read object if modified.
wordList names() const
Return the list of names of the IOobjects.
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:302
label getEvent() const
Return new event number.
TypeName("objectRegistry")
Declare type name for this IOobject.
wordList sortedNames() const
Return the sorted list of names of the IOobjects.
virtual bool writeData(Ostream &) const
writeData function required by regIOobject but not used
Version number type.
Definition: IOstream.H:96
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
Registry of regIOobjects.
#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:91
bool checkIn()
Add object to registry.
Definition: regIOobject.C:241
HashTable< const Type * > lookupClass(const bool strict=false) const
Lookup and return all objects of the given Type.
const word & name() const
Return name.
Definition: IOobject.H:260
virtual void rename(const word &newName)
Rename.
Namespace for OpenFOAM.