objectRegistryFunctionObject.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) 2016-2025 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::functionObjects::objectRegistryFunctionObject
26 
27 Description
28  Specialisation of Foam::functionObject which holds a reference to an object
29  registry. Provides a number of functions for caching and accessing objects
30  from the registry.
31 
32 See also
33  Foam::functionObject
34 
35 SourceFiles
36  objectRegistryFunctionObject.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef objectRegistryFunctionObject_functionObject_H
41 #define objectRegistryFunctionObject_functionObject_H
42 
43 #include "functionObject.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // Forward declaration of classes
51 class objectRegistry;
52 
53 namespace functionObjects
54 {
55 
56 /*---------------------------------------------------------------------------*\
57  Class objectRegistryFunctionObject Declaration
58 \*---------------------------------------------------------------------------*/
59 
61 :
62  public functionObject
63 {
64 
65 protected:
66 
67  // Protected member data
68 
69  //- Reference to the objectRegistry
70  const objectRegistry& obr_;
71 
72 
73  // Protected member functions
74 
75  //- Find field in the objectRegistry
76  template<class ObjectType>
77  bool foundObject(const word& fieldName) const;
78 
79  //- Prints a warning message that fieldName cannot be found
80  template<class ObjectType>
81  void cannotFindObject(const word& fieldName);
82 
83  //- Prints a warning message that fieldName cannot be found
84  void cannotFindObject(const word& fieldName);
85 
86  //- Prints a warning message that fieldNames cannot be found
88 
89  //- Lookup object from the objectRegistry
90  template<class ObjectType>
91  const ObjectType& lookupObject(const word& fieldName) const;
92 
93  //- Lookup non-const object reference from the objectRegistry
94  template<class ObjectType>
95  ObjectType& lookupObjectRef(const word& fieldName);
96 
97  //- Store the given field in the objectRegistry
98  template<class ObjectType>
99  ObjectType& store(const tmp<ObjectType>& tfield);
100 
101  //- Store the given field in the objectRegistry under the given name
102  template<class ObjectType>
103  ObjectType& store
104  (
105  const word& fieldName,
106  const tmp<ObjectType>& tfield,
107  bool cacheable = false
108  );
109 
110  //- Write field if present in objectRegistry
111  bool writeObject(const word& fieldName);
112 
113  //- Clear field from the objectRegistry if present
114  bool clearObject(const word& fieldName);
115 
116 
117 public:
118 
119  //- Runtime type information
120  TypeName("objectRegistryFunctionObject");
121 
122 
123  // Constructors
124 
125  //- Construct from an objectRegistry and dictionary
127  (
128  const word& name,
129  const objectRegistry& obr,
130  const dictionary& dict
131  );
132 
133  //- Construct from an objectRegistry
135  (
136  const word& name,
137  const objectRegistry& obr
138  );
139 
140  //- Disallow default bitwise copy construction
142  (
144  ) = delete;
145 
146 
147  //- Destructor
149 
150 
151  // Member Functions
152 
153  //- Read optional controls
154  virtual bool read(const dictionary&);
155 
156 
157  // Member Operators
158 
159  //- Disallow default bitwise assignment
160  void operator=(const objectRegistryFunctionObject&) = delete;
161 };
162 
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 } // End namespace functionObjects
167 } // End namespace Foam
168 
169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
170 
171 #ifdef NoRepository
173 #endif
174 
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 
177 #endif
178 
179 // ************************************************************************* //
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Abstract base-class for Time/database functionObjects.
const word & name() const
Return the name of this functionObject.
Specialisation of Foam::functionObject which holds a reference to an object registry....
const ObjectType & lookupObject(const word &fieldName) const
Lookup object from the objectRegistry.
objectRegistryFunctionObject(const word &name, const objectRegistry &obr, const dictionary &dict)
Construct from an objectRegistry and dictionary.
void operator=(const objectRegistryFunctionObject &)=delete
Disallow default bitwise assignment.
bool foundObject(const word &fieldName) const
Find field in the objectRegistry.
const objectRegistry & obr_
Reference to the objectRegistry.
void cannotFindObjects(const wordList &fieldNames)
Prints a warning message that fieldNames cannot be found.
ObjectType & lookupObjectRef(const word &fieldName)
Lookup non-const object reference from the objectRegistry.
ObjectType & store(const tmp< ObjectType > &tfield)
Store the given field in the objectRegistry.
bool writeObject(const word &fieldName)
Write field if present in objectRegistry.
bool clearObject(const word &fieldName)
Clear field from the objectRegistry if present.
TypeName("objectRegistryFunctionObject")
Runtime type information.
void cannotFindObject(const word &fieldName)
Prints a warning message that fieldName cannot be found.
virtual bool read(const dictionary &)
Read optional controls.
Registry of regIOobjects.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
static List< word > fieldNames
Definition: globalFoam.H:46
Namespace for OpenFOAM.
dictionary dict