HashPtrTable.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) 2011-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::HashPtrTable
26 
27 Description
28  A HashTable specialisation for hashing pointers.
29 
30 SourceFiles
31  HashPtrTableI.H
32  HashPtrTable.C
33  HashPtrTableIO.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef HashPtrTable_H
38 #define HashPtrTable_H
39 
40 #include "HashTable.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 class Istream;
48 class Ostream;
49 
50 // Forward declaration of friend functions and operators
51 
52 template<class T, class Key, class Hash> class HashPtrTable;
53 
54 template<class T, class Key, class Hash>
56 
57 template<class T, class Key, class Hash>
59 
60 
61 /*---------------------------------------------------------------------------*\
62  Class HashPtrTable Declaration
63 \*---------------------------------------------------------------------------*/
64 
65 template<class T, class Key=word, class Hash=string::hash>
66 class HashPtrTable
67 :
68  public HashTable<T*, Key, Hash>
69 {
70  // Private Member Functions
71 
72  //- Read from Istream using given Istream constructor class
73  template<class INew>
74  void read(Istream&, const INew& inewt);
75 
76  //- Read from dictionary using given dictionary constructor class
77  template<class INew>
78  void read(const dictionary& dict, const INew& inewt);
79 
80 
81 
82 public:
83 
86 
87 
88  // Constructors
89 
90  //- Construct given initial table size
91  HashPtrTable(const label size = 128);
92 
93  //- Construct from Istream using given Istream constructor class
94  template<class INew>
95  HashPtrTable(Istream&, const INew&);
96 
97  //- Construct from Istream using default Istream constructor class
99 
100  //- Construct from dictionary using default dictionary constructor
101  // class
102  HashPtrTable(const dictionary&);
103 
104  //- Copy constructor
106 
107  //- Move constructor
109 
110 
111  //- Destructor
112  ~HashPtrTable();
113 
114 
115  // Member Functions
116 
117  // Edit
118 
119  //- Remove and return the pointer specified by given iterator
120  T* remove(const iterator&);
121 
122  //- Erase an hashedEntry specified by given iterator
123  bool erase(const iterator&);
124 
125  //- Erase a hashedEntry specified by the given key
126  inline bool erase(const Key&);
127 
128  //- Clear all entries from table
129  void clear();
130 
131  //- Write
132  void write(Ostream& os) const;
133 
134 
135  // Member Operators
136 
137  //- Find and return a hashedEntry
138  inline T& operator[](const Key&);
139 
140  //- Find and return a hashedEntry
141  inline const T& operator[](const Key&) const;
142 
143  //- Assignment operator
145 
146  //- Move assignment operator
148 
149 
150  // IOstream Operators
151 
152  friend Istream& operator>> <T, Key, Hash>
153  (
154  Istream&,
156  );
157 
158  friend Ostream& operator<< <T, Key, Hash>
159  (
160  Ostream&,
162  );
163 };
164 
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 } // End namespace Foam
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 #include "HashPtrTableI.H"
173 
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175 
176 #ifdef NoRepository
177  #include "HashPtrTable.C"
178 #endif
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 #endif
183 
184 // ************************************************************************* //
A HashTable specialisation for hashing pointers.
Definition: HashPtrTable.H:68
T & operator[](const Key &)
Find and return a hashedEntry.
Definition: HashPtrTableI.H:39
bool erase(const iterator &)
Erase an hashedEntry specified by given iterator.
Definition: HashPtrTable.C:84
HashTable< T *, Key, Hash >::iterator iterator
Definition: HashPtrTable.H:83
void operator=(const HashPtrTable< T, Key, Hash > &)
Assignment operator.
Definition: HashPtrTable.C:125
T * remove(const iterator &)
Remove and return the pointer specified by given iterator.
Definition: HashPtrTable.C:75
void write(Ostream &os) const
Write.
HashTable< T *, Key, Hash >::const_iterator const_iterator
Definition: HashPtrTable.H:84
void clear()
Clear all entries from table.
Definition: HashPtrTable.C:105
~HashPtrTable()
Destructor.
Definition: HashPtrTable.C:66
An STL-conforming const_iterator.
Definition: HashTable.H:494
An STL-conforming iterator.
Definition: HashTable.H:443
An STL-conforming hash table.
Definition: HashTable.H:127
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
friend class HashPtrTable
Declare friendship with the HashPtrTable class.
Definition: HashTable.H:184
Hash function class for primitives. All non-primitives used to hash entries on hash tables likely nee...
Definition: Hash.H:53
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:50
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Namespace for OpenFOAM.
Istream & operator>>(Istream &, pointEdgeDist &)
Definition: pointEdgeDist.C:41
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
void T(GeometricField< Type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type, GeoMesh, PrimitiveField2 > &gf1)
dictionary dict