HashPtrTable.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 | Copyright (C) 2011 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  //- Construct as copy
105 
106 
107  //- Destructor
108  ~HashPtrTable();
109 
110 
111  // Member Functions
112 
113  // Edit
114 
115  //- Remove and return the pointer specified by given iterator
116  T* remove(iterator&);
117 
118  //- Erase an hashedEntry specified by given iterator
119  bool erase(iterator&);
120 
121  //- Clear all entries from table
122  void clear();
123 
124  //- Write
125  void write(Ostream& os) const;
126 
127 
128  // Member Operators
129 
131 
132 
133  // IOstream Operators
134 
135  friend Istream& operator>> <T, Key, Hash>
136  (
137  Istream&,
139  );
140 
141  friend Ostream& operator<< <T, Key, Hash>
142  (
143  Ostream&,
145  );
146 };
147 
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 } // End namespace Foam
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 #ifdef NoRepository
156 # include "HashPtrTable.C"
157 #endif
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 #endif
162 
163 // ************************************************************************* //
void clear()
Clear all entries from table.
Definition: HashPtrTable.C:97
~HashPtrTable()
Destructor.
Definition: HashPtrTable.C:58
HashTable< T *, Key, Hash >::iterator iterator
Definition: HashPtrTable.H:82
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
An STL-conforming hash table.
Definition: HashTable.H:61
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
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
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:49
Namespace for OpenFOAM.
Hash function class for primitives. All non-primitives used to hash entries on hash tables likely nee...
Definition: Hash.H:54
dictionary dict
HashPtrTable(const label size=128)
Construct given initial table size.
Definition: HashPtrTable.C:33
label size() const
Return number of elements in table.
HashTable< T *, Key, Hash >::const_iterator const_iterator
Definition: HashPtrTable.H:83
void operator=(const HashPtrTable< T, Key, Hash > &)
Definition: HashPtrTable.C:117
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:144
bool erase(iterator &)
Erase an hashedEntry specified by given iterator.
Definition: HashPtrTable.C:76
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void write(Ostream &os) const
Write.
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50