printDictionary.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::printDictionary
26 
27 Description
28  Enables the printing of a dictionary
29  and subsequently looked-up defaulted entries
30 
31 SourceFiles
32  printDictionary.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef printDictionary_H
37 #define printDictionary_H
38 
39 #include "HashSet.H"
40 #include "tmpNrc.H"
41 #include "dictionary.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 class dictionary;
49 
50 /*---------------------------------------------------------------------------*\
51  Class printDictionary Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class printDictionary
55 {
56 private:
57 
58  // Private Static Member Functions
59 
60  //- Remove the default dictionary for the given dictionary
61  static void removeDefaults
62  (
63  const dictionary* dictPtr,
64  HashSet<const dictionary*, Hash<void*>>& removeDictPtrs
65  );
66 
67  //- Remove the default dictionary for the given dictionary
68  static void removeDefaults(const dictionary* dictPtr);
69 
70  //- Allocate the default dictionary for the given dictionary
71  static void setDefaults(const dictionary& dict);
72 
73  //- Set the default dictionary pointers for the sub-dictionaries
74  // of the given dictionary
75  static void setSubDefaults
76  (
77  const dictionary& dict,
79  );
80 
81  //- Print the given dictionary and its accumulated defaults
82  static void print(const dictionary& dict, const dictionary& defaults);
83 
84 
85  // Private Static Data
86 
87  //- Table from the names of dictionaries to be printed to pointers
88  // to those dictionaries and the number of times they are currently
89  // marked to be printed
90  static HashTable
91  <
93  fileName,
95  > dictNameToDictPtrAndCount_;
96 
97  //- Table from pointers to the dictionaries to be printed to
98  // dictionaries containing all entries including defaults
99  static HashTable
100  <
102  const dictionary*,
104  > dictPtrToDefaults_;
105 
106  //- The dictionaries to be printed
108 
109  //- Names of the dictionaries to be printed
110  List<fileName> dictNames_;
111 
112 
113  // Private Constructors
114 
115  //- Construct null
116  printDictionary();
117 
118 
119  // Private Member Functions
120 
121  //- Add a dictionary to the list to be printed
122  void add(const dictionary& dict);
123 
124  //- Add a dictionary name to the list to be printed
125  void add(const fileName& dictName);
126 
127 
128 public:
129 
130  // Constructors
131 
132  //- Construct adding a dictionary to the list to be printed
133  template<class ... Args>
134  printDictionary(const dictionary& dict, const Args& ... args)
135  :
136  printDictionary(args ...)
137  {
138  add(dict);
139  }
140 
141  //- Construct adding a dictionary name to the list to be printed
142  template<class ... Args>
143  printDictionary(const fileName& dictName, const Args& ... args)
144  :
145  printDictionary(args ...)
146  {
147  add(dictName);
148  }
149 
150 
151  //- Destructor
153 
154 
155  // Member Functions
156 
157  //- Set the dictionary to be printed
158  static void set(const dictionary& dict);
159 
160  //- Return if a dictionary is marked to be printed
161  static bool prints(const dictionary& dict)
162  {
163  return dictNameToDictPtrAndCount_.found(dict.name());
164  }
165 
166  //- Return if a dictionary is marked to be printed
167  static bool prints(const fileName& dictName)
168  {
169  return dictNameToDictPtrAndCount_.found(dictName);
170  }
171 
172  //- Return if a dictionary exists to add defaults to for a given
173  // dictionary
174  static bool haveDefaults(const dictionary& dict)
175  {
176  return dictPtrToDefaults_.found(&dict);
177  }
178 
179  //- Return the dictionary to add defaults to for a given dictionary
180  static dictionary& defaults(const dictionary& dict)
181  {
182  return const_cast<dictionary&>(dictPtrToDefaults_[&dict]());
183  }
184 };
185 
186 
187 template<class Type, class... Args>
188 inline Type PrintDictionary(const dictionary& dict, Args&... args)
189 {
190  printDictionary print(dict);
191  return Type(args...);
192 }
193 
194 
195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196 
197 } // End namespace Foam
198 
199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 
201 #endif
202 
203 // ************************************************************************* //
A HashTable with keys but without contents.
Definition: HashSet.H:62
An STL-conforming hash table.
Definition: HashTable.H:127
Hash specialisation for hashing pointer addresses.
Definition: Hash.H:207
Hash function class for primitives. All non-primitives used to hash entries on hash tables likely nee...
Definition: Hash.H:53
A 2-tuple for storing two objects of different types.
Definition: Tuple2.H:66
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:66
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A class for handling file names.
Definition: fileName.H:82
Enables the printing of a dictionary and subsequently looked-up defaulted entries.
static bool haveDefaults(const dictionary &dict)
Return if a dictionary exists to add defaults to for a given.
static dictionary & defaults(const dictionary &dict)
Return the dictionary to add defaults to for a given dictionary.
~printDictionary()
Destructor.
static bool prints(const dictionary &dict)
Return if a dictionary is marked to be printed.
static void set(const dictionary &dict)
Set the dictionary to be printed.
A class for managing temporary objects without reference counting.
Definition: tmpNrc.H:53
Namespace for OpenFOAM.
Type PrintDictionary(const dictionary &dict, Args &... args)
void add(GeometricField< typename typeOfSum< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
dictionary dict
Foam::argList args(argc, argv)