dictionaryValue.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::substitutionModels::dictionaryValue
28 
29 Description
30  The \c dictionaryValue substitution model. Dictionaries can be retrieved
31  from an object registry, e.g. time, mesh, or from file.
32 
33  The example below shows how the keywords \c p_solver and \c u_solver are set
34  by retrieving values from the \c fvSolution dictionary.
35 
36  \verbatim
37  dictionaryValues1
38  {
39  // Mandatory entries
40  type dictionaryValue;
41 
42  entries
43  {
44  p_solver "solvers/p/solver";
45  u_solver "solvers/u/solver";
46  }
47 
48  // Conditional entries
49 
50  // Option-1
51  object "fvSolution"; // registry-based retrieval
52  // region "fluidMesh";
53 
54  // Option-2
55  // path "<system>/fvSolution"; // file-based retrieval
56 
57 
58  // Optional entries
59  separator <word>;
60 
61  // Inherited entries
62  ...
63  }
64  \endverbatim
65 
66  The entries mean:
67  \table
68  Property | Description | Type | Reqd | Deflt
69  type | Type name: dictionaryValue | word | yes | -
70  entries | keyword lookup pairs | dictionary | yes | -
71  object | Name of registered dictionary | string | no | -
72  region | Name of mesh region | word | no | region0
73  path | Path to dictionary file | string | no | -
74  separator | Sep. when lookup value has multiple tokens | word | no | -
75  \endtable
76 
77  The inherited entries are elaborated in:
78  - \link substitutionModel.H \endlink
79 
80 SourceFiles
81  dictionaryValue.C
82 
83 ---------------------------------------------------------------------------*/
84 
85 #ifndef Foam_substitutionModels_dictionaryValue_H
86 #define Foam_substitutionModels_dictionaryValue_H
87 
88 #include "substitutionModel.H"
89 
90 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
91 
92 namespace Foam
93 {
94 
95 namespace substitutionModels
96 {
97 
98 /*---------------------------------------------------------------------------*\
99  Class dictionaryValue Declaration
100 \*---------------------------------------------------------------------------*/
101 
102 class dictionaryValue
103 :
104  public substitutionModel
105 {
106  // Private Data
107 
108  //- Dictionary name for registry-based lookup
109  word object_;
110 
111  //- Region name for registry-based lookup
112  word region_;
113 
114  //- Path to dictionary for file-based lookup
115  fileName path_;
116 
117  //- Separator when lookup value has multiple tokens
118  const word separator_;
119 
120  //- Hash table for key and entry-lookup pairs
121  HashTable<string> entries_;
122 
123 
124  // Private Functions
125 
126  //- No copy construct
127  dictionaryValue(const dictionaryValue&) = delete;
128 
129  //- No copy assignment
130  void operator=(const dictionaryValue&) = delete;
131 
132 
133 protected:
134 
135  // Protected Member Functions
136 
137  //- Main function to process the dictionary
138  bool processDict
139  (
140  const dictionary& dict,
141  const word& key,
142  string& buffer
143  ) const;
144 
145 
146 public:
147 
148  //- Runtime type information
149  TypeName("dictionaryValue");
150 
151 
152  //- Constructor
153  dictionaryValue(const dictionary& dict, const Time& time);
154 
155 
156  //- Destructor
157  virtual ~dictionaryValue() = default;
158 
159 
160  // Member Functions
161 
162  //- Return true of model applies to this keyName
163  virtual bool valid(const word& keyName) const;
164 
165  //- Apply substitutions to this string buffer
166  virtual bool apply(const word& key, string& buffer) const;
167 
168  //- Return a word list of the keys
169  virtual wordList keys() const;
170 };
171 
172 
173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 
175 } // End namespace substitutionModels
176 } // End namespace Foam
177 
178 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 
180 #endif
181 
182 // ************************************************************************* //
dictionary dict
virtual ~dictionaryValue()=default
Destructor.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
bool processDict(const dictionary &dict, const word &key, string &buffer) const
Main function to process the dictionary.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
A class for handling words, derived from Foam::string.
Definition: word.H:63
TypeName("dictionaryValue")
Runtime type information.
virtual bool valid(const word &keyName) const
Return true of model applies to this keyName.
virtual wordList keys() const
Return a word list of the keys.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103
The dictionaryValue substitution model. Dictionaries can be retrieved from an object registry...
virtual bool apply(const word &key, string &buffer) const
Apply substitutions to this string buffer.
Namespace for OpenFOAM.