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 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 Class
28  Foam::DictionaryBase
29 
30 Description
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 
37 Note
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 
42 See also
43  Dictionary and UDictionary
44 
45 SourceFiles
46  DictionaryBase.C
47  DictionaryBaseIO.C
48 
49 \*---------------------------------------------------------------------------*/
50 
51 #ifndef DictionaryBase_H
52 #define DictionaryBase_H
53 
54 #include "HashTable.H"
55 #include "wordList.H"
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 namespace Foam
60 {
61 
62 // Forward Declarations
63 
64 template<class IDLListType, class T>
65 class DictionaryBase;
66 
67 template<class IDLListType, class T>
69 
70 
71 /*---------------------------------------------------------------------------*\
72  Class DictionaryBase Declaration
73 \*---------------------------------------------------------------------------*/
74 
75 template<class IDLListType, class T>
76 class DictionaryBase
77 :
78  public IDLListType
79 {
80 protected:
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 
94 public:
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
109  DictionaryBase(Istream& is);
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 at head of dictionary
145  void insert(const word& keyword, T*);
146 
147  //- Add at tail of dictionary
148  void append(const word& keyword, T*);
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
181 
182  friend Ostream& operator<< <IDLListType, T>
183  (
184  Ostream&,
186  );
187 
188 
189  // Housekeeping
190 
191  //- Deprecated(2020-03) use cfind()
192  //
193  // \deprecated(2020-03) - use cfind() method
194  FOAM_DEPRECATED_FOR(2020-03, "cfind() method")
195  const T* lookupPtr(const word& keyword) const
196  {
197  return this->cfind(keyword);
198  }
199 
200  //- Deprecated(2020-03) use find()
201  //
202  // \deprecated(2020-03) - use find() method
203  FOAM_DEPRECATED_FOR(2020-03, "find() method")
204  T* lookupPtr(const word& keyword)
205  {
206  return this->find(keyword);
207  }
208 };
209 
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 } // End namespace Foam
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 #ifdef NoRepository
218  #include "DictionaryBase.C"
219 #endif
220 
221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
222 
223 #endif
224 
225 // ************************************************************************* //
Foam::DictionaryBase::operator=
void operator=(const DictionaryBase &)
Copy assignment.
Definition: DictionaryBase.C:249
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
HashTable.H
Foam::DictionaryBase::toc
wordList toc() const
Return the table of contents (as a sorted list)
Definition: DictionaryBase.C:160
Foam::DictionaryBase::operator[]
const T * operator[](const word &key) const
Find and return entry.
Definition: DictionaryBase.H:167
Foam::DictionaryBase::transfer
void transfer(DictionaryBase< IDLListType, T > &dict)
Transfer the contents of the argument into this DictionaryBase.
Definition: DictionaryBase.C:231
Foam::glTF::key
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:108
Foam::DictionaryBase::addEntries
void addEntries()
Definition: DictionaryBase.C:34
wordList.H
Foam::DictionaryBase::sortedToc
wordList sortedToc() const
Return the table of contents as a sorted list.
Definition: DictionaryBase.C:170
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::INew
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:51
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::DictionaryBase::DictionaryBase
DictionaryBase(const label size=128)
Construct with given or default (128) table capacity.
Definition: DictionaryBase.C:46
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::DictionaryBase::remove
T * remove(const word &keyword)
Remove and return entry specified by keyword.
Definition: DictionaryBase.C:206
Foam::DictionaryBase::found
bool found(const word &keyword) const
Search for given keyword.
Definition: DictionaryBase.C:90
Foam::DictionaryBase::lookupPtr
const T * lookupPtr(const word &keyword) const
Deprecated(2020-03) use cfind()
Definition: DictionaryBase.H:194
Foam::DictionaryBase::append
void append(const word &keyword, T *)
Add at tail of dictionary.
Definition: DictionaryBase.C:197
Foam::DictionaryBase::lookup
const T * lookup(const word &keyword) const
Find and return entry, FatalError on failure.
Definition: DictionaryBase.C:128
dict
dictionary dict
Definition: searchingEngine.H:14
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::DictionaryBase::find
T * find(const word &keyword)
Find and return an entry, nullptr on failure.
Definition: DictionaryBase.C:114
DictionaryBase.C
Foam::HashTable< T * >
Foam::DictionaryBase::insert
void insert(const word &keyword, T *)
Add at head of dictionary.
Definition: DictionaryBase.C:188
Foam::DictionaryBase::hashedTs_
HashTable< T * > hashedTs_
HashTable of the entries held on the IDLListType for quick lookup.
Definition: DictionaryBase.H:84
Foam::DictionaryBase::clear
void clear()
Clear the dictionary.
Definition: DictionaryBase.C:222
Foam::DictionaryBase::operator[]
T * operator[](const word &key)
Find and return entry.
Definition: DictionaryBase.H:173
Foam::List< word >
Foam::DictionaryBase
Base dictionary class templated on both the form of doubly-linked list it uses as well as the type it...
Definition: DictionaryBase.H:64
Foam::DictionaryBase::cfind
const T * cfind(const word &keyword) const
Find and return an entry, nullptr on failure.
Definition: DictionaryBase.C:98
Foam::FOAM_DEPRECATED_FOR
class FOAM_DEPRECATED_FOR(2017-05, "Foam::Enum") NamedEnum
Definition: NamedEnum.H:69
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56