exprResultGlobals.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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2012-2018 Bernhard Gschaider <bgschaid@hfd-research.com>
9 Copyright (C) 2019-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::expressions::exprResultGlobals
29
30Description
31 A globally available registry of expression results.
32 These are currently registered on Time (may change in the future).
33
34Note
35 The storage mechanism is similar to a MeshObject, but always stores
36 on Time and flushes stale values according to the time index.
37
38SourceFiles
39 exprResultGlobals.C
40
41\*---------------------------------------------------------------------------*/
42
43#ifndef expressions_exprResultGlobals_H
44#define expressions_exprResultGlobals_H
45
46#include "exprResult.H"
47#include "autoPtr.H"
48#include "HashPtrTable.H"
49#include "regIOobject.H"
50
51// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52
53namespace Foam
54{
55namespace expressions
56{
57
58/*---------------------------------------------------------------------------*\
59 Class exprResultGlobals Declaration
60\*---------------------------------------------------------------------------*/
63:
64 public regIOobject
65{
66public:
67
68 // Public Classes
69
70 //- The table of results
71 class Table
72 :
73 public HashPtrTable<exprResult>
74 {
75 public:
76
77 //- Default construct
78 Table() = default;
79
80 //- Copy (clone) construct
81 Table(const Table& tbl);
82
83 //- Move construct
84 Table(Table&& tbl);
85
86 //- Read construct from stream
87 explicit Table(Istream& is);
88 };
89
90
91private:
92
93 // Private Data
94
95 //- The scoped table of results
96 HashTable<Table> variables_;
97
98 //- The currently (or previously) used time-index
99 label timeIndex_;
100
101
102 // Private Member Functions
103
104 //- Construct on Time for registry
105 explicit exprResultGlobals(const objectRegistry& obr);
106
107 //- Reset all variables
108 void reset();
109
110 //- Get or create a table for the scope
111 Table& getOrCreateScope(const word& scope)
112 {
113 return variables_(scope);
114 }
115
116
117public:
118
119 //- Runtime type information
120 TypeNameNoDebug("exprResultGlobals");
121
122
123 // Selectors
124
125 //- Static constructor for singleton
126 static exprResultGlobals& New(const objectRegistry& obr);
127
128 //- Static destructor for singleton
129 static bool Delete(const objectRegistry& obr);
130
131
132 //- Destructor
133 virtual ~exprResultGlobals() = default;
134
135
136 // Member Functions
137
138 //- Get an existing table for the namespace
139 Table& getNamespace(const word& name);
140
141
142 //- Return a global variable, if it exists, or a exprResult::null
143 const exprResult& get
144 (
145 const word& name,
146 const wordUList& scopes
147 ) const;
148
149 //- Add named result to specified scope
151 (
152 const word& name,
153 const word& scope,
154 const exprResult& value,
155 const bool overwrite = true
156 );
157
158 //- Add named result to specified scope
160 (
161 const word& name,
162 const word& scope,
163 autoPtr<exprResult>&& value,
164 const bool overwrite = true
165 );
166
167 //- Extract result from dictionary and add to the scope
168 //
169 // Controlled by dictionary entries:
170 // - globalName (mandatory)
171 // - globalScope (optional)
172 // - resultType (optional)
174 (
175 const dictionary& dict,
176 const word& scope = "",
177 const bool overwrite = true
178 );
179
180 //- Remove named result from specified scope
181 // \return true if result was removed
182 bool removeValue
183 (
184 const word& name,
185 const word& scope
186 );
187
188 //- Write variables
189 virtual bool writeData(Ostream& os) const;
190
191 //- Read variables
192 virtual bool readData(Istream& os);
193};
194
195
196// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197
198} // End namespace expressions
199} // End namespace Foam
200
201// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202
203#endif
204
205// ************************************************************************* //
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers.
Definition: HashPtrTable.H:68
A HashTable similar to std::unordered_map.
Definition: HashTable.H:123
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:65
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A globally available registry of expression results. These are currently registered on Time (may chan...
const exprResult & get(const word &name, const wordUList &scopes) const
Return a global variable, if it exists, or a exprResult::null.
virtual bool writeData(Ostream &os) const
Write variables.
static exprResultGlobals & New(const objectRegistry &obr)
Static constructor for singleton.
virtual ~exprResultGlobals()=default
Destructor.
exprResult & addValue(const word &name, const word &scope, const exprResult &value, const bool overwrite=true)
Add named result to specified scope.
TypeNameNoDebug("exprResultGlobals")
Runtime type information.
virtual bool readData(Istream &os)
Read variables.
Table & getNamespace(const word &name)
Get an existing table for the namespace.
static bool Delete(const objectRegistry &obr)
Static destructor for singleton.
bool removeValue(const word &name, const word &scope)
Remove named result from specified scope.
A polymorphic field/result from evaluating an expression.
Definition: exprResult.H:127
Registry of regIOobjects.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
dictionary dict
#define TypeNameNoDebug(TypeNameString)
Declare a ClassNameNoDebug() with extra virtual type info.
Definition: typeInfo.H:68