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 -------------------------------------------------------------------------------
10 License
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 
26 Class
27  Foam::substitutionModel
28 
29 Description
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 
35 SourceFiles
36  substitutionModel.C
37  substitutionModelNew.C
38 
39 ---------------------------------------------------------------------------*/
40 
41 #ifndef Foam_substitutionModel_H
42 #define Foam_substitutionModel_H
43 
44 #include "runTimeSelectionTables.H"
45 #include "dictionary.H"
46 #include "Time.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class substitutionModel Declaration
55 \*---------------------------------------------------------------------------*/
56 
58 {
59 public:
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
71 
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 
112 private:
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 
123 protected:
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 
134 public:
135 
136  //- Runtime type information
137  TypeName("substitutionModel");
138 
139  // Declare run-time constructor selection table
140 
142  (
143  autoPtr,
145  dictionary,
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
158  (
159  const dictionary& dict,
160  const Time& time
161  );
162 
164  //- Constructor
166  (
167  const dictionary& dict,
168  const Time& time
169  );
170 
171 
172  //- Destructor
173  virtual ~substitutionModel() = default;
174 
175 
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 // ************************************************************************* //
static bool replaceBuiltin(const word &key, string &str)
Replace key in string.
dictionary dict
virtual bool valid(const word &keyName) const =0
Return true of model applies to this keyName.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
static autoPtr< substitutionModel > New(const dictionary &dict, const Time &time)
Return a reference to the selected substitution model.
Base class for substitution models.
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.
const Time & time_
Reference to the time database.
TypeName("substitutionModel")
Runtime type information.
static void setBuiltinStr(const word &key, const string &value)
Set a builtin to the hash table.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
static void addBuiltinStr(const word &key, const string &value)
Add a builtin to the hash table - does not overwrite.
A class for handling words, derived from Foam::string.
Definition: word.H:63
declareRunTimeSelectionTable(autoPtr, substitutionModel, dictionary,(const dictionary &dict, const Time &time),(dict, time))
auto key(const Type &t) -> std::enable_if_t< std::is_enum_v< Type >, std::underlying_type_t< Type > >
Definition: foamGltfBase.H:103
A HashTable similar to std::unordered_map.
Definition: HashTable.H:108
static const word KEY_BEGIN
Keyword starting characters.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
static HashTable< string > builtin_
Built-in substitutions.
static bool containsBuiltin(const word &key)
Return true if key is builtin.
const dictionary dict_
Construction dictionary.
virtual ~substitutionModel()=default
Destructor.
static void writeBuiltins(Ostream &os)
Write all builtins to stream.
static wordList getKeys(string &buffer)
Return all keys from a string buffer.
static const word KEY_END
Keyword ending characters.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Macros to ease declaration of run-time selection tables.
static void addBuiltin(const word &key, const Type &value)
Add a builtin to the hash table - does not overwrite.
virtual wordList keys() const =0
Return a word list of the keys.
static word cleanKey(const string &str)
Clean the key text.
static string keyify(const word &w)
Return a key representation from a word.
Namespace for OpenFOAM.
virtual bool update()
Update model local data.