DictionaryBase.C
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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2019-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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\*---------------------------------------------------------------------------*/
28
29#include "DictionaryBase.H"
30
31// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
32
33template<class IDLListType, class T>
35{
36 for (auto iter = this->begin(); iter != this->end(); ++iter)
37 {
38 this->hashedTs_.insert((*iter).keyword(), &(*iter));
39 }
40}
41
42
43// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44
45template<class IDLListType, class T>
47:
48 hashedTs_(size)
49{}
50
51
52template<class IDLListType, class T>
54(
55 const DictionaryBase& dict
56)
57:
58 IDLListType(dict)
59{
60 addEntries();
61}
62
63
64template<class IDLListType, class T>
65template<class INew>
67(
68 Istream& is,
69 const INew& iNew
70)
71:
72 IDLListType(is, iNew)
73{
74 addEntries();
75}
76
77
78template<class IDLListType, class T>
80:
81 IDLListType(is)
82{
83 addEntries();
84}
85
86
87// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
88
89template<class IDLListType, class T>
91{
92 return hashedTs_.found(keyword);
93}
94
95
96template<class IDLListType, class T>
99 const word& keyword
100) const
102 const auto iter = hashedTs_.cfind(keyword);
103
104 if (iter.found())
106 return *iter;
107 }
109 return nullptr;
110}
111
112
113template<class IDLListType, class T>
115{
116 auto iter = hashedTs_.find(keyword);
117
118 if (iter.found())
120 return *iter;
121 }
123 return nullptr;
124}
126
127template<class IDLListType, class T>
129{
130 const auto iter = hashedTs_.cfind(keyword);
132 if (!iter.found())
133 {
135 << "'" << keyword << "' not found"
136 << exit(FatalError);
137 }
138
139 return *iter;
140}
141
142
143template<class IDLListType, class T>
145{
146 auto iter = hashedTs_.find(keyword);
148 if (!iter.found())
149 {
151 << "'" << keyword << "' not found"
152 << exit(FatalError);
153 }
155 return *iter;
156}
157
159template<class IDLListType, class T>
161{
162 // Cannot rely on the items themselves having a keyword() method
163 // so simply return the toc() from the hashed entries
164 // Make it sorted, since anything else would have no meaning.
165 return hashedTs_.sortedToc();
166}
167
168
169template<class IDLListType, class T>
171{
172 return hashedTs_.sortedToc();
173}
174
175
176template<class IDLListType, class T>
177template<class Compare>
179(
180 const Compare& comp
181) const
182{
183 return hashedTs_.sortedToc(comp);
184}
185
186
187template<class IDLListType, class T>
189{
190 // NOTE: we should probably check that HashTable::insert actually worked
191 hashedTs_.insert(keyword, ptr);
192 IDLListType::prepend(ptr);
193}
194
195
196template<class IDLListType, class T>
198{
199 // NOTE: we should probably check that HashTable::insert actually worked
200 hashedTs_.insert(keyword, ptr);
201 IDLListType::append(ptr);
202}
203
204
205template<class IDLListType, class T>
207{
208 auto iter = hashedTs_.find(keyword);
209
210 if (iter.found())
211 {
212 T* ptr = IDLListType::remove(iter());
213 hashedTs_.erase(iter);
214 return ptr;
215 }
216
217 return nullptr;
218}
219
220
221template<class IDLListType, class T>
223{
224 IDLListType::clear();
225 hashedTs_.clear();
226}
227
228
229template<class IDLListType, class T>
231(
233)
234{
235 if (this == &dict)
236 {
237 return; // Self-assignment is a no-op
238 }
239
240 IDLListType::transfer(dict);
241 hashedTs_.transfer(dict.hashedTs_);
242}
243
244
245// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
246
247template<class IDLListType, class T>
249(
251)
252{
253 if (this == &dict)
254 {
255 return; // Self-assignment is a no-op
256 }
257
258 IDLListType::operator=(dict);
259 this->hashedTs_.clear();
260 this->addEntries();
261}
262
263
264// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
265
266#include "DictionaryBaseIO.C"
267
268// ************************************************************************* //
bool found
Base dictionary class templated on both the form of doubly-linked list it uses as well as the type it...
T * find(const word &keyword)
Find and return an entry, nullptr on failure.
wordList sortedToc() const
Return the table of contents as a sorted list.
void clear()
Clear the dictionary.
wordList toc() const
Return the table of contents (as a sorted list)
const T * cfind(const word &keyword) const
Find and return an entry, nullptr on failure.
void prepend(const word &keyword, T *ptr)
Add to front of dictionary.
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:52
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
unsigned int remove()
Remove and return the last element.
Definition: PackedListI.H:709
Lookup type of boundary radiation properties.
Definition: lookup.H:66
bool append() const noexcept
True if output format uses an append mode.
A class for handling words, derived from Foam::string.
Definition: word.H:68
const volScalarField & T
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
dictionary dict