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 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::expressions::exprResultGlobals
29 
30 Description
31  A globally available registry of expression results
32 
33 SourceFiles
34  exprResultGlobals.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef expressions_exprResultGlobals_H
39 #define expressions_exprResultGlobals_H
40 
41 #include "exprResult.H"
42 #include "autoPtr.H"
43 #include "HashPtrTable.H"
44 #include "regIOobject.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 namespace expressions
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class exprResultGlobals Declaration
55 \*---------------------------------------------------------------------------*/
56 
58 :
59  public regIOobject
60 {
61 public:
62 
63  // Public Classes
64 
65  //- The table of results
66  class Table
67  :
68  public HashPtrTable<exprResult>
69  {
70  public:
71 
72  Table();
73  Table(const Table& tbl);
74  Table(Table&& tbl);
75  Table(Istream& is);
76  };
77 
78 
79 private:
80 
81  // Private Data
82 
83  //- The scoped table of results
84  HashTable<Table> variables_;
85 
86  //- The currently (or previously) used time-index
87  label timeIndex_;
88 
89  //- Only one instance of this repository
90  static autoPtr<exprResultGlobals> singleton_;
91 
92 
93  // Private Member Functions
94 
95  //- Construct
96  explicit exprResultGlobals(const objectRegistry& obr);
97 
98  //- Reset all variables
99  void reset();
100 
101  //- Get or create a table for the scope
102  Table& getOrCreateScope(const word& scope)
103  {
104  return variables_(scope);
105  }
106 
107 
108 public:
109 
110  //- Runtime type information
111  TypeName("exprResultGlobals");
112 
113 
114  // Constructors
115 
116  //- Get the singleton
117  static exprResultGlobals& New(const objectRegistry& obr);
118 
119 
120  //- Destructor
121  virtual ~exprResultGlobals() = default;
122 
123 
124  // Member Functions
125 
126  //- Get an existing table for the namespace
127  Table& getNamespace(const word& name);
128 
129 
130  //- Return a global variable, if it exists, or a exprResult::null
131  const exprResult& get
132  (
133  const word& name,
134  const wordUList& scopes
135  ) const;
136 
137  //- Add named result to specified scope
139  (
140  const word& name,
141  const word& scope,
142  const exprResult& value,
143  const bool overwrite = true
144  );
145 
146  //- Add named result to specified scope
148  (
149  const word& name,
150  const word& scope,
151  autoPtr<exprResult>& value,
152  const bool overwrite = true
153  );
154 
155  //- Add named result to specified scope
157  (
158  const word& name,
159  const word& scope,
160  autoPtr<exprResult>&& value,
161  const bool overwrite = true
162  );
163 
164  //- Extract result from dictionary and add to the scope
165  //
166  // Controlled by dictionary entries:
167  // - globalName (mandatory)
168  // - globalScope (optional)
169  // - resultType (optional)
171  (
172  const dictionary& dict,
173  const word& scope = "",
174  const bool overwrite = true
175  );
176 
177  //- Remove named result from specified scope
178  // \return true if result was removed
179  bool removeValue
180  (
181  const word& name,
182  const word& scope
183  );
184 
185  //- Write variables
186  virtual bool writeData(Ostream& os) const;
187 
188  //- Read variables
189  virtual bool readData(Istream& os);
190 };
191 
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 } // End namespace expressions
196 } // End namespace Foam
197 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 #endif
201 
202 // ************************************************************************* //
regIOobject.H
Foam::expressions::exprResultGlobals::writeData
virtual bool writeData(Ostream &os) const
Write variables.
Definition: exprResultGlobals.C:125
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobjectI.H:46
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::expressions::exprResultGlobals::Table::Table
Table()
Definition: exprResultGlobals.C:80
Foam::expressions::exprResultGlobals::get
const exprResult & get(const word &name, const wordUList &scopes) const
Return a global variable, if it exists, or a exprResult::null.
Definition: exprResultGlobals.C:183
Foam::expressions::exprResultGlobals::getNamespace
Table & getNamespace(const word &name)
Get an existing table for the namespace.
Definition: exprResultGlobals.C:175
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
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:62
Foam::expressions::exprResult
A polymorphic field/result from evaluating an expression.
Definition: exprResult.H:128
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::expressions::exprResultGlobals::Table
The table of results.
Definition: exprResultGlobals.H:65
Foam::expressions::exprResultGlobals
A globally available registry of expression results.
Definition: exprResultGlobals.H:56
Foam::expressions::exprResultGlobals::readData
virtual bool readData(Istream &os)
Read variables.
Definition: exprResultGlobals.C:138
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::expressions::exprResultGlobals::removeValue
bool removeValue(const word &name, const word &scope)
Remove named result from specified scope.
Definition: exprResultGlobals.C:323
Foam::expressions::exprResultGlobals::TypeName
TypeName("exprResultGlobals")
Runtime type information.
Foam::expressions::exprResultGlobals::~exprResultGlobals
virtual ~exprResultGlobals()=default
Destructor.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::HashTable
A HashTable similar to std::unordered_map.
Definition: HashTable.H:105
Foam::expressions::exprResultGlobals::addValue
exprResult & addValue(const word &name, const word &scope, const exprResult &value, const bool overwrite=true)
Add named result to specified scope.
Definition: exprResultGlobals.C:217
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:67
Foam::HashPtrTable
A HashTable of pointers to objects of type <T>.
Definition: HashPtrTable.H:54
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
HashPtrTable.H
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::expressions::exprResultGlobals::New
static exprResultGlobals & New(const objectRegistry &obr)
Get the singleton.
Definition: exprResultGlobals.C:153
exprResult.H
autoPtr.H