Loading...
Searching...
No Matches
substitutionModel.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) 2024 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::substitutionModel
28
29Description
30 Base class for substitution models.
31
32 Provides a static hash table for builtin keyword-value pairs and functions
33 to manipulate/interact.
34
35SourceFiles
36 substitutionModel.C
37 substitutionModelNew.C
38
39---------------------------------------------------------------------------*/
40
41#ifndef Foam_substitutionModel_H
42#define Foam_substitutionModel_H
43
45#include "dictionary.H"
46#include "Time.H"
47
48// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49
50namespace Foam
51{
53/*---------------------------------------------------------------------------*\
54 Class substitutionModel Declaration
55\*---------------------------------------------------------------------------*/
56
57class substitutionModel
58{
59public:
60
61 // Static Data Members
62
63 //- Keyword starting characters
64 static const word KEY_BEGIN;
65
66 //- Keyword ending characters
67 static const word KEY_END;
68
69 //- Built-in substitutions
72
73 // Static Member Functions
74
75 //- Return a key representation from a word
76 static string keyify(const word& w);
77
78 //- Clean the key text
79 static word cleanKey(const string& str);
80
81 //- Return all keys from a string buffer
82 // Also cleans the key strings in the buffer
83 static wordList getKeys(string& buffer);
84
85 //- Add a builtin to the hash table - does not overwrite
86 static void addBuiltinStr(const word& key, const string& value);
87
88 //- Add a builtin to the hash table - does not overwrite
89 template<class Type>
90 static void addBuiltin(const word& key, const Type& value);
91
92 //- Return true if key is builtin
93 static bool containsBuiltin(const word& key);
94
95 //- Set a builtin to the hash table
96 static void setBuiltinStr(const word& key, const string& value);
97
98 //- Set a builtin to the hash table
99 template<class Type>
100 static void setBuiltin(const word& key, const Type& value);
101
102 //- Replace key in string
103 static bool replaceBuiltin(const word& key, string& str);
104
105 //- Replace all occurrences of key in string
106 static bool replaceBuiltin(string& str);
107
108 //- Write all builtins to stream
109 static void writeBuiltins(Ostream& os);
110
111
112private:
113
114 // Private Functions
115
116 //- No copy construct
117 substitutionModel(const substitutionModel&) = delete;
118
119 //- No copy assignment
120 void operator=(const substitutionModel&) = delete;
121
122
123protected:
124
125 // Protected Data
126
127 //- Construction dictionary
128 const dictionary dict_;
129
130 //- Reference to the time database
131 const Time& time_;
132
133
134public:
135
136 //- Runtime type information
137 TypeName("substitutionModel");
138
139 // Declare run-time constructor selection table
140
142 (
143 autoPtr,
144 substitutionModel,
146 (
147 const dictionary& dict,
148 const Time& time
149 ),
150 (dict, time)
151 );
152
153
154 // Selectors
155
156 //- Return a reference to the selected substitution model
159 const dictionary& dict,
160 const Time& time
161 );
162
164 //- Constructor
165 substitutionModel
166 (
167 const dictionary& dict,
168 const Time& time
169 );
170
172 //- Destructor
173 virtual ~substitutionModel() = default;
174
176 // Member Functions
177
178 //- Update model local data
179 virtual bool update() { return true; }
180
181 //- Return true of model applies to this keyName
182 virtual bool valid(const word& keyName) const = 0;
183
184 //- Apply substitutions to this string buffer
185 virtual bool apply(const word& key, string& buffer) const = 0;
186
187 //- Return a word list of the keys
188 virtual wordList keys() const = 0;
189};
190
191
192// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193
194} // End namespace Foam
195
196// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197
198#ifdef NoRepository
200#endif
201
202// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203
204#endif
205
206// ************************************************************************* //
A HashTable similar to std::unordered_map.
Definition HashTable.H:124
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const Time & time_
Reference to the time database.
virtual bool update()
Update model local data.
virtual bool valid(const word &keyName) const =0
Return true of model applies to this keyName.
static wordList getKeys(string &buffer)
Return all keys from a string buffer.
static bool containsBuiltin(const word &key)
Return true if key is builtin.
virtual ~substitutionModel()=default
Destructor.
static void addBuiltin(const word &key, const Type &value)
Add a builtin to the hash table - does not overwrite.
static const word KEY_END
Keyword ending characters.
static const word KEY_BEGIN
Keyword starting characters.
virtual bool apply(const word &key, string &buffer) const =0
Apply substitutions to this string buffer.
static void setBuiltin(const word &key, const Type &value)
Set a builtin to the hash table.
static void writeBuiltins(Ostream &os)
Write all builtins to stream.
static autoPtr< substitutionModel > New(const dictionary &dict, const Time &time)
Return a reference to the selected substitution model.
virtual wordList keys() const =0
Return a word list of the keys.
declareRunTimeSelectionTable(autoPtr, substitutionModel, dictionary,(const dictionary &dict, const Time &time),(dict, time))
const dictionary dict_
Construction dictionary.
static word cleanKey(const string &str)
Clean the key text.
static void setBuiltinStr(const word &key, const string &value)
Set a builtin to the hash table.
static string keyify(const word &w)
Return a key representation from a word.
static HashTable< string > builtin_
Built-in substitutions.
static bool replaceBuiltin(const word &key, string &str)
Replace key in string.
static void addBuiltinStr(const word &key, const string &value)
Add a builtin to the hash table - does not overwrite.
TypeName("substitutionModel")
Runtime type information.
A class for handling words, derived from Foam::string.
Definition word.H:66
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
Macros to ease declaration of run-time selection tables.
#define declareRunTimeSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection (variables and adder classes).
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68