HashTableDetail.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) 2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::Detail::HashTablePair
28 
29 Description
30  Internal storage type for HashTable
31 
32 SourceFiles
33  HashTableDetail.H
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef HashTableDetail_H
38 #define HashTableDetail_H
39 
40 #include "zero.H"
41 #include <memory>
42 #include <utility>
43 #include <type_traits>
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // Forward Declarations
51 class Ostream;
52 template<class T> class autoPtr;
53 
54 namespace Detail
55 {
56 
57 /*---------------------------------------------------------------------------*\
58  Class isPointerLike Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 //- Pointer-like behaviour
62 template<class T> struct isPointerLike : std::false_type {};
63 
64 //- Pointer-like behaviour for autoPtr
65 template<class T> struct isPointerLike<autoPtr<T>> : std::true_type {};
66 
67 //- Pointer-like behaviour for std::unique_ptr
68 template<class T> struct isPointerLike<std::unique_ptr<T>> : std::true_type {};
69 
70 
71 /*---------------------------------------------------------------------------*\
72  Class HashTablePair Declaration
73 \*---------------------------------------------------------------------------*/
74 
75 //- Internal storage type for HashTable entries
76 // Structure with a (K,V) tuple and a linked-list for collisions
77 // Could store key/val as std::pair, but no particular advantage
78 // unless the iterator dereference type changes.
79 template<class K, class V>
80 struct HashTablePair
81 {
82  // Types
83 
84  //- Type of key
85  typedef K key_type;
86 
87  //- Type of content
88  typedef V mapped_type;
89 
90  //- This struct stores a value
91  static constexpr bool stores_value() noexcept
92  {
93  return true;
94  }
95 
96 
97  // Member Data
98 
99  //- The lookup key
100  key_type key_;
101 
102  //- The mapped data
104 
105  //- Addressing (next in collision list)
107 
108 
109  // Member Functions
110 
111  //- No copy construct
112  HashTablePair(const HashTablePair&) = delete;
113 
114  //- No copy assignment
115  void operator=(const HashTablePair&) = delete;
116 
117 
118  //- Construct from next pointer, key, contents
119  template<class... Args>
121  (
122  HashTablePair* next,
123  const key_type& key,
124  Args&&... args
125  )
126  :
127  key_(key),
128  val_(std::forward<Args>(args)...),
129  next_(next)
130  {}
131 
132 
133  //- The key
134  const key_type& key() const
135  {
136  return key_;
137  }
138 
139  //- Const access to the mapped value
140  const mapped_type& cval() const
141  {
142  return val_;
143  }
144 
145  //- Non-const access to the mapped value
146  mapped_type& val()
147  {
148  return val_;
149  }
150 
151  //- Write (key, val) pair - for pointer types
152  template<class TypeT = V>
153  typename std::enable_if
154  <
155  (
156  std::is_pointer<TypeT>::value
158  ),
159  void
160  >::type
161  print(Ostream& os) const
162  {
163  os << key_;
164 
165  if (val_)
166  {
167  os << ' ' << *val_;
168  }
169  }
170 
171  //- Write (key, val) pair - for non-pointer types
172  template<class TypeT = V>
173  typename std::enable_if
174  <
175  (
176  !std::is_pointer<TypeT>::value
178  ),
179  void
180  >::type
181  print(Ostream& os) const
182  {
183  os << key_ << ' ' << val_;
184  }
185 };
186 
187 
188 /*---------------------------------------------------------------------------*\
189  Class HashTableSingle Declaration
190 \*---------------------------------------------------------------------------*/
191 
192 //- Internal storage type for HashSet entries
193 // Structure with a single (K) value and a linked-list for collisions
194 template<class K>
195 struct HashTableSingle
196 {
197  // Types
198 
199  //- Type of key
200  typedef K key_type;
201 
202  //- Type of content
204 
205  //- Content storage type to the entry
206  typedef key_type value_type;
207 
208  //- This struct does not store a value
209  static constexpr bool stores_value() noexcept
210  {
211  return false;
212  }
213 
214 
215  // Member Data
216 
217  //- The lookup key == content
218  key_type key_;
219 
220  //- Addressing (next in collision list)
222 
223 
224  // Member Functions
225 
226  //- No copy construct
227  HashTableSingle(const HashTableSingle&) = delete;
228 
229  //- No copy assignment
230  void operator=(const HashTableSingle&) = delete;
231 
232 
233  //- Construct from next pointer, key, (unused) contents
234  template<class... Args>
236  (
237  HashTableSingle* next,
238  const key_type& key,
239  Args&&...
240  )
241  :
242  key_(key),
243  next_(next)
244  {}
245 
246 
247  //- The key
248  const key_type& key() const
249  {
250  return key_;
251  }
252 
253  //- Const access to the (dummy) mapped value
254  const mapped_type& cval() const
255  {
257  }
258 
259  //- Non-const access to the (dummy) mapped value
260  mapped_type& val()
261  {
263  }
264 
265  //- Write the key. There is no value
266  void print(Ostream& os) const
267  {
268  os << key_;
269  }
270 };
271 
272 
273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274 
275 } // End namespace Detail
276 } // End namespace Foam
277 
278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 
280 #endif
281 
282 // ************************************************************************* //
Foam::Detail::HashTableSingle::HashTableSingle
HashTableSingle(const HashTableSingle &)=delete
No copy construct.
Foam::Detail::HashTablePair::operator=
void operator=(const HashTablePair &)=delete
No copy assignment.
Foam::Detail::HashTableSingle::value_type
key_type value_type
Content storage type to the entry.
Definition: HashTableDetail.H:205
Foam::Detail::HashTableSingle::val
mapped_type & val()
Non-const access to the (dummy) mapped value.
Definition: HashTableDetail.H:259
Foam::Detail::HashTableSingle
Internal storage type for HashSet entries.
Definition: HashTableDetail.H:194
Foam::Detail::HashTablePair::key_type
K key_type
Type of key.
Definition: HashTableDetail.H:84
Foam::Detail::HashTableSingle::next_
HashTableSingle * next_
Addressing (next in collision list)
Definition: HashTableDetail.H:220
Foam::Detail::HashTablePair::print
std::enable_if<(!std::is_pointer< TypeT >::value &&!Detail::isPointerLike< TypeT >::value), void >::type print(Ostream &os) const
Write (key, val) pair - for non-pointer types.
Definition: HashTableDetail.H:180
Foam::Detail::HashTableSingle::key_
key_type key_
The lookup key == content.
Definition: HashTableDetail.H:217
Foam::Detail::HashTablePair::next_
HashTablePair * next_
Addressing (next in collision list)
Definition: HashTableDetail.H:105
K
CGAL::Exact_predicates_exact_constructions_kernel K
Definition: CGALTriangulation3DKernel.H:58
Foam::Detail::HashTableSingle::stores_value
static constexpr bool stores_value() noexcept
This struct does not store a value.
Definition: HashTableDetail.H:208
Foam::Detail::HashTableSingle::key
const key_type & key() const
The key.
Definition: HashTableDetail.H:247
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::Detail::HashTablePair::val
mapped_type & val()
Non-const access to the mapped value.
Definition: HashTableDetail.H:145
Foam::Detail::HashTablePair::val_
mapped_type val_
The mapped data.
Definition: HashTableDetail.H:102
Foam::Detail::HashTableSingle::cval
const mapped_type & cval() const
Const access to the (dummy) mapped value.
Definition: HashTableDetail.H:253
zero.H
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Detail::HashTablePair::mapped_type
V mapped_type
Type of content.
Definition: HashTableDetail.H:87
Foam::zero::null
A zero class with a null output adapter.
Definition: zero.H:109
Foam::Detail::HashTablePair::HashTablePair
HashTablePair(const HashTablePair &)=delete
No copy construct.
Foam::Detail::HashTablePair::cval
const mapped_type & cval() const
Const access to the mapped value.
Definition: HashTableDetail.H:139
Foam::Detail::HashTablePair
Internal storage type for HashTable entries.
Definition: HashTableDetail.H:79
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::Detail::HashTableSingle::key_type
K key_type
Type of key.
Definition: HashTableDetail.H:199
Foam::Detail::HashTablePair::key_
key_type key_
The lookup key.
Definition: HashTableDetail.H:99
Foam::Detail::HashTableSingle::mapped_type
Foam::zero::null mapped_type
Type of content.
Definition: HashTableDetail.H:202
Foam::Detail::HashTablePair::stores_value
static constexpr bool stores_value() noexcept
This struct stores a value.
Definition: HashTableDetail.H:90
Foam::Detail::HashTablePair::key
const key_type & key() const
The key.
Definition: HashTableDetail.H:133
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::Detail::HashTableSingle::print
void print(Ostream &os) const
Write the key. There is no value.
Definition: HashTableDetail.H:265
Foam::zero::null::dummy
static null dummy
A static zero::null for dereferencing as a dummy element.
Definition: zero.H:118
Foam::Detail::HashTableSingle::operator=
void operator=(const HashTableSingle &)=delete
No copy assignment.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
args
Foam::argList args(argc, argv)
Foam::Detail::isPointerLike
Pointer-like behaviour.
Definition: HashTableDetail.H:61
Foam::Detail::HashTablePair::print
std::enable_if<(std::is_pointer< TypeT >::value||Detail::isPointerLike< TypeT >::value), void >::type print(Ostream &os) const
Write (key, val) pair - for pointer types.
Definition: HashTableDetail.H:160