DictionaryBase.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2020-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
27Class
28 Foam::DictionaryBase
29
30Description
31 Base dictionary class templated on both the form of doubly-linked list
32 it uses as well as the type it holds.
33
34 The double templating allows for the instantiation of forms with or
35 without storage management.
36
37Note
38 The IDLListType parameter should itself be a template but this confused
39 gcc 2.95.2 so it has to be instantiated for T when an instantiation of
40 DictionaryBase is requested
41
42See also
43 Dictionary and UDictionary
44
45SourceFiles
46 DictionaryBase.C
47 DictionaryBaseIO.C
48
49\*---------------------------------------------------------------------------*/
50
51#ifndef Foam_DictionaryBase_H
52#define Foam_DictionaryBase_H
53
54#include "HashTable.H"
55#include "wordList.H"
56
57// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58
59namespace Foam
60{
61
62// Forward Declarations
63
64template<class IDLListType, class T>
65class DictionaryBase;
66
67template<class IDLListType, class T>
69
70
71/*---------------------------------------------------------------------------*\
72 Class DictionaryBase Declaration
73\*---------------------------------------------------------------------------*/
74
75template<class IDLListType, class T>
77:
78 public IDLListType
79{
80protected:
81
82 // Protected Data
83
84 //- HashTable of the entries held on the IDLListType for quick lookup
86
87
88 // Protected Member Functions
89
90 // Add the IDLListType entries into the HashTable
91 void addEntries();
92
93
94public:
95
96 // Constructors
97
98 //- Construct with given or default (128) table capacity
99 explicit DictionaryBase(const label size = 128);
100
101 //- Copy construct
103
104 //- Construct from Istream using given Istream constructor class
105 template<class INew>
106 DictionaryBase(Istream& is, const INew& inew);
107
108 //- Construct from Istream using default Istream constructor class
110
111
112 // Member Functions
113
114 // Search and lookup
115
116 //- Search for given keyword
117 bool found(const word& keyword) const;
118
119 //- Find and return an entry, nullptr on failure.
120 const T* cfind(const word& keyword) const;
121
122 //- Find and return an entry, nullptr on failure.
123 T* find(const word& keyword);
124
125 //- Find and return entry, FatalError on failure.
126 const T* lookup(const word& keyword) const;
127
128 //- Find and return entry, FatalError on failure.
129 T* lookup(const word& keyword);
130
131 //- Return the table of contents (as a sorted list)
132 wordList toc() const;
133
134 //- Return the table of contents as a sorted list
135 wordList sortedToc() const;
136
137 //- Return table of contents sorted using the specified comparator
138 template<class Compare>
139 wordList sortedToc(const Compare& comp) const;
140
141
142 // Editing
143
144 //- Add to front of dictionary
145 void prepend(const word& keyword, T* ptr);
146
147 //- Add to back of dictionary
148 void append(const word& keyword, T* ptr);
149
150 //- Remove and return entry specified by keyword.
151 // Return nullptr if the keyword was not found.
152 T* remove(const word& keyword);
153
154 //- Clear the dictionary
155 void clear();
156
157 //- Transfer the contents of the argument into this DictionaryBase
158 // and annul the argument.
160
161
162 // Member Operators
163
164 //- Copy assignment
165 void operator=(const DictionaryBase&);
166
167 //- Find and return entry
168 const T* operator[](const word& key) const
169 {
170 return lookup(key);
171 }
172
173 //- Find and return entry
174 T* operator[](const word& key)
175 {
176 return lookup(key);
177 }
178
179
180 // Ostream Operator
182 friend Ostream& operator<< <IDLListType, T>
183 (
184 Ostream&,
186 );
187
188
189 // Housekeeping
190
191 //- Deprecated(2020-03) use cfind()
192 // \deprecated(2020-03) - use cfind() method
193 FOAM_DEPRECATED_FOR(2020-03, "cfind() method")
194 const T* lookupPtr(const word& keyword) const
195 {
196 return this->cfind(keyword);
197 }
198
199 //- Deprecated(2020-03) use find()
200 // \deprecated(2020-03) - use find() method
201 FOAM_DEPRECATED_FOR(2020-03, "find() method")
202 T* lookupPtr(const word& keyword)
203 {
204 return this->find(keyword);
205 }
206
207 //- Add to front of dictionary
208 void insert(const word& keyword, T* ptr)
209 {
210 this->prepend(keyword, ptr);
211 }
212};
213
214
215// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216
217} // End namespace Foam
218
219// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220
221#ifdef NoRepository
222 #include "DictionaryBase.C"
223#endif
224
225// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226
227#endif
228
229// ************************************************************************* //
bool found
Base dictionary class templated on both the form of doubly-linked list it uses as well as the type it...
T * operator[](const word &key)
Find and return entry.
void transfer(DictionaryBase< IDLListType, T > &dict)
Transfer the contents of the argument into this DictionaryBase.
void operator=(const DictionaryBase &)
Copy assignment.
T * find(const word &keyword)
Find and return an entry, nullptr on failure.
HashTable< T * > hashedTs_
HashTable of the entries held on the IDLListType for quick lookup.
T * remove(const word &keyword)
Remove and return entry specified by keyword.
wordList sortedToc(const Compare &comp) const
Return table of contents sorted using the specified comparator.
wordList sortedToc() const
Return the table of contents as a sorted list.
void insert(const word &keyword, T *ptr)
Add to front of dictionary.
void clear()
Clear the dictionary.
void append(const word &keyword, T *ptr)
Add to back of 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.
const T * lookupPtr(const word &keyword) const
Deprecated(2020-03) use cfind()
const T * operator[](const word &key) const
Find and return entry.
void prepend(const word &keyword, T *ptr)
Add to front of dictionary.
A HashTable similar to std::unordered_map.
Definition: HashTable.H:123
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
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Lookup type of boundary radiation properties.
Definition: lookup.H:66
A class for handling words, derived from Foam::string.
Definition: word.H:68
const volScalarField & T
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
dictionary dict
#define FOAM_DEPRECATED_FOR(since, replacement)
Definition: stdFoam.H:52