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-2019 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 specialization for hashing pointers.
29 
30 SourceFiles
31  HashPtrTable.C
32  HashPtrTableIO.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef HashPtrTable_H
37 #define HashPtrTable_H
38 
39 #include "HashTable.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 class Istream;
47 class Ostream;
48 
49 // Forward declaration of friend functions and operators
50 
51 template<class T, class Key, class Hash> class HashPtrTable;
52 
53 template<class T, class Key, class Hash>
55 
56 template<class T, class Key, class Hash>
57 Ostream& operator<<(Ostream&, const HashPtrTable<T, Key, Hash>&);
58 
59 
60 /*---------------------------------------------------------------------------*\
61  Class HashPtrTable Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 template<class T, class Key=word, class Hash=string::hash>
65 class HashPtrTable
66 :
67  public HashTable<T*, Key, Hash>
68 {
69  // Private Member Functions
70 
71  //- Read from Istream using given Istream constructor class
72  template<class INew>
73  void read(Istream&, const INew& inewt);
74 
75  //- Read from dictionary using given dictionary constructor class
76  template<class INew>
77  void read(const dictionary& dict, const INew& inewt);
78 
79 
80 
81 public:
82 
85 
86 
87  // Constructors
88 
89  //- Construct given initial table size
90  HashPtrTable(const label size = 128);
91 
92  //- Construct from Istream using given Istream constructor class
93  template<class INew>
94  HashPtrTable(Istream&, const INew&);
95 
96  //- Construct from Istream using default Istream constructor class
98 
99  //- Construct from dictionary using default dictionary constructor
100  // class
101  HashPtrTable(const dictionary&);
102 
103  //- Copy constructor
105 
106  //- Move constructor
108 
109 
110  //- Destructor
111  ~HashPtrTable();
112 
113 
114  // Member Functions
115 
116  // Edit
117 
118  //- Remove and return the pointer specified by given iterator
119  T* remove(iterator&);
120 
121  //- Erase an hashedEntry specified by given iterator
122  bool erase(iterator&);
123 
124  //- Clear all entries from table
125  void clear();
126 
127  //- Write
128  void write(Ostream& os) const;
129 
130 
131  // Member Operators
132 
133  //- Assignment operator
135 
136  //- Move assignment operator
138 
139 
140  // IOstream Operators
141 
142  friend Istream& operator>> <T, Key, Hash>
143  (
144  Istream&,
146  );
147 
148  friend Ostream& operator<< <T, Key, Hash>
149  (
150  Ostream&,
152  );
153 };
154 
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 } // End namespace Foam
159 
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 
162 #ifdef NoRepository
163  #include "HashPtrTable.C"
164 #endif
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 #endif
169 
170 // ************************************************************************* //
dictionary dict
~HashPtrTable()
Destructor.
Definition: HashPtrTable.C:66
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
HashPtrTable(const label size=128)
Construct given initial table size.
Definition: HashPtrTable.C:32
void operator=(const HashPtrTable< T, Key, Hash > &)
Assignment operator.
Definition: HashPtrTable.C:125
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
void clear()
Clear all entries from table.
Definition: HashPtrTable.C:105
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
void write(Ostream &os) const
Write.
HashTable< T *, Key, Hash >::const_iterator const_iterator
Definition: HashPtrTable.H:83
Istream & operator>>(Istream &, directionInfo &)
An STL-conforming hash table.
Definition: HashTable.H:61
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:49
Hash function class for primitives. All non-primitives used to hash entries on hash tables likely nee...
Definition: Hash.H:54
HashTable< T *, Key, Hash >::iterator iterator
Definition: HashPtrTable.H:82
bool erase(iterator &)
Erase an hashedEntry specified by given iterator.
Definition: HashPtrTable.C:84
Namespace for OpenFOAM.