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-2015 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
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  template<class Type>
184  Type& lookupObjectRef
185  (
186  const word& name
187  ) const;
188  //- Return new event number.
189  label getEvent() const;
190 
191 
192  // Edit
193 
194  //- Rename
195  virtual void rename(const word& newName);
196 
197  //- Add an regIOobject to registry
198  bool checkIn(regIOobject&) const;
199 
200  //- Remove an regIOobject from registry
201  bool checkOut(regIOobject&) const;
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;
233 };
234 
235 
236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 
238 } // End namespace Foam
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 #ifdef NoRepository
243 # include "objectRegistryTemplates.C"
244 #endif
245 
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247 
248 #endif
249 
250 // ************************************************************************* //
regIOobject.H
Foam::objectRegistry::readIfModified
virtual bool readIfModified()
Read object if modified.
Definition: objectRegistry.C:323
Foam::objectRegistry::sortedNames
wordList sortedNames() const
Return the sorted list of names of the IOobjects.
Definition: objectRegistry.C:121
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::objectRegistry::~objectRegistry
virtual ~objectRegistry()
Destructor.
Definition: objectRegistry.C:93
Foam::objectRegistry::writeData
virtual bool writeData(Ostream &) const
writeData function required by regIOobject but not used
Definition: objectRegistry.H:218
Foam::objectRegistry::getEvent
label getEvent() const
Return new event number.
Definition: objectRegistry.C:180
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
HashTable.H
Foam::IOstream::compressionType
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
Foam::objectRegistry::TypeName
TypeName("objectRegistry")
Declare type name for this IOobject.
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:117
Foam::regIOobject::checkIn
bool checkIn()
Add object to registry.
Definition: regIOobject.C:247
Foam::objectRegistry::parent_
const objectRegistry & parent_
Parent objectRegistry.
Definition: objectRegistry.H:61
Foam::wordRe
A wordRe is a word, but can also have a regular expression for matching words.
Definition: wordRe.H:74
Foam::objectRegistry::operator=
void operator=(const objectRegistry &)
Disallow default bitwise copy construct and assignment.
Foam::objectRegistry::parentNotTime
bool parentNotTime() const
Is the objectRegistry parent_ different from time_.
Definition: objectRegistry.C:39
Foam::IOobject::db
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:239
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::objectRegistry::lookupClass
HashTable< const Type * > lookupClass(const bool strict=false) const
Lookup and return all objects of the given Type.
Foam::IOstream::versionNumber
Version number type.
Definition: IOstream.H:96
Foam::objectRegistry::subRegistry
const objectRegistry & subRegistry(const word &name, const bool forceCreate=false) const
Lookup and return a const sub-objectRegistry. Optionally create.
Definition: objectRegistry.C:156
Foam::objectRegistry::event_
label event_
Current event.
Definition: objectRegistry.H:67
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:365
Foam::objectRegistry::dbDir
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
Definition: objectRegistry.H:129
Foam::objectRegistry::objectRegistry
objectRegistry(const objectRegistry &)
Disallow Copy constructor.
Foam::objectRegistry::rename
virtual void rename(const word &newName)
Rename.
Definition: objectRegistry.C:275
Foam::label
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
Foam::objectRegistry::time_
const Time & time_
Master time objectRegistry.
Definition: objectRegistry.H:58
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobject.H:273
Foam::objectRegistry::dbDir_
fileName dbDir_
Local directory path of this objectRegistry relative to time.
Definition: objectRegistry.H:64
objectRegistryTemplates.C
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::objectRegistry::lookupObjectRef
Type & lookupObjectRef(const word &name) const
Definition: objectRegistryTemplates.C:208
Foam::HashTable
An STL-conforming hash table.
Definition: HashTable.H:61
Foam::objectRegistry::modified
virtual bool modified() const
Return true if any of the object's files have been modified.
Definition: objectRegistry.C:293
Foam::objectRegistry::readModifiedObjects
void readModifiedObjects()
Read the objects that have been modified.
Definition: objectRegistry.C:307
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
Foam::objectRegistry::foundObject
bool foundObject(const word &name) const
Is the named Type found?
Definition: objectRegistryTemplates.C:142
Foam::regIOobject::checkOut
bool checkOut()
Remove object from registry.
Definition: regIOobject.C:308
Foam::objectRegistry::parent
const objectRegistry & parent() const
Return the parent objectRegistry.
Definition: objectRegistry.H:123
Foam::objectRegistry::names
wordList names() const
Return the list of names of the IOobjects.
Definition: objectRegistry.C:115
Foam::objectRegistry::writeObject
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp) const
Write the objects.
Definition: objectRegistry.C:331
wordReList.H
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Definition: objectRegistryTemplates.C:165
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::IOstream::streamFormat
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86