HashPtrTableI.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) 2018 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 \*---------------------------------------------------------------------------*/
27 
28 #include "autoPtr.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class T, class Key, class Hash>
34 :
35  parent_type()
36 {}
37 
38 
39 template<class T, class Key, class Hash>
41 :
42  parent_type(size)
43 {}
44 
45 
46 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
47 
48 template<class T, class Key, class Hash>
50 (
51  const Key& key,
52  autoPtr<T>& aptr
53 )
54 {
55  if (parent_type::insert(key, aptr.get()))
56  {
57  aptr.release(); // Now owned by HashPtrTable
58  return true;
59  }
60 
61  return false;
62 }
63 
64 
65 template<class T, class Key, class Hash>
67 (
68  const Key& key,
69  autoPtr<T>&& aptr
70 )
71 {
72  if (parent_type::insert(key, aptr.get()))
73  {
74  aptr.release(); // Now owned by HashPtrTable
75  return true;
76  }
77 
78  return false;
79 }
80 
81 
82 template<class T, class Key, class Hash>
84 (
85  const Key& key,
86  T* ptr
87 )
88 {
89  return this->parent_type::set(key, ptr);
90 }
91 
92 
93 template<class T, class Key, class Hash>
95 (
96  const Key& key,
97  autoPtr<T>& aptr
98 )
99 {
100  return this->set(key, aptr.release());
101 }
102 
103 
104 template<class T, class Key, class Hash>
106 (
107  const Key& key,
108  autoPtr<T>&& aptr
109 )
110 {
111  return this->set(key, aptr.release());
112 }
113 
114 
115 // ************************************************************************* //
insert
srcOptions insert("case", fileName(rootDirSource/caseDirSource))
Foam::HashPtrTable::set
bool set(const Key &key, T *ptr)
Assign a new entry, overwriting existing entries.
Definition: HashPtrTableI.H:84
Foam::autoPtr::release
T * release() noexcept
Return pointer to the managed object and release ownership.
Definition: autoPtrI.H:100
Foam::autoPtr::get
T * get() noexcept
Return pointer to managed object without nullptr checking.
Definition: autoPtr.H:155
Foam::HashPtrTable::insert
bool insert(const Key &, T *)=delete
Foam::HashPtrTable::HashPtrTable
HashPtrTable()
Construct null with default table capacity.
Definition: HashPtrTableI.H:33
T
const volScalarField & T
Definition: createFieldRefs.H:2
Foam::HashTable
A HashTable similar to std::unordered_map.
Definition: HashTable.H:105
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
autoPtr.H