PtrListDictionary.C
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) 2015 OpenFOAM Foundation
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 "PtrListDictionary.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class T>
34 :
35  dict_type(2*size)
36 {
37  PtrList<T>::resize(size);
38 }
39 
40 
41 template<class T>
43 :
45 {}
46 
47 
48 template<class T>
49 template<class INew>
51 :
52  dict_type(is, iNew)
53 {}
54 
55 
56 template<class T>
58 :
59  dict_type(is)
60 {}
61 
62 
63 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
64 
65 template<class T>
67 (
68  const label i,
69  const word& key,
70  T* ptr
71 )
72 {
73  autoPtr<T> old(PtrList<T>::set(i, ptr));
74 
75  if (!dict_type::addHashEntry(key, ptr))
76  {
78  << "Cannot insert with key '" << key << "' into hash-table"
79  << abort(FatalError);
80  }
81 
82  return old;
83 }
84 
85 
86 template<class T>
88 (
89  const label i,
90  const word& key,
91  autoPtr<T>& ptr
92 )
93 {
94  return this->set(i, key, ptr.release());
95 }
96 
97 
98 template<class T>
100 (
101  const label i,
102  const word& key,
103  tmp<T>& ptr
104 )
105 {
106  return this->set(i, key, ptr.ptr()); // release or clone
107 }
108 
109 
110 // ************************************************************************* //
dictionary dict
PtrListDictionary(const label size)
Construct given initial list size.
patchWriters resize(patchIds.size())
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Template dictionary class which manages the storage associated with it.
A class for handling words, derived from Foam::string.
Definition: word.H:63
errorManip< error > abort(error &err)
Definition: errorManip.H:139
T * release() noexcept
Release ownership and return the pointer.
Definition: autoPtrI.H:28
const volScalarField & T
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:46
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
T * ptr() const
Return managed pointer for reuse, or clone() the object reference.
Definition: tmpI.H:256
A class for managing temporary objects.
Definition: HashPtrTable.H:50
autoPtr< T > set(const label i, const word &key, T *ptr)
Set element to pointer provided and return old element.