PtrListDictionary.C
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) 2015-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 \*---------------------------------------------------------------------------*/
25 
26 #include "PtrListDictionary.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class T>
32 :
33  DictionaryBase<PtrList<T>, T>(2*size)
34 {
35  PtrList<T>::setSize(size);
36 }
37 
38 
39 template<class T>
41 :
42  DictionaryBase<PtrList<T>, T>(dict)
43 {}
44 
45 
46 template<class T>
48 :
49  DictionaryBase<PtrList<T>, T>(move(dict))
50 {}
51 
52 
53 template<class T>
54 template<class INew>
56 :
57  DictionaryBase<PtrList<T>, T>(is, iNew)
58 {}
59 
60 
61 template<class T>
63 :
64  DictionaryBase<PtrList<T>, T>(is)
65 {}
66 
67 
68 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
69 
70 template<class T>
72 (
73  const label i,
74  const word& key,
75  T* ptr
76 )
77 {
78  if (!DictionaryBase<PtrList<T>, T>::hashedTs_.insert(key, ptr))
79  {
81  << "Cannot insert with key '" << key << "' into hash-table"
82  << abort(FatalError);
83  }
84  return PtrList<T>::set(i, ptr);
85 }
86 
87 
88 template<class T>
90 (
91  const label i,
92  const word& key,
93  autoPtr<T>& aptr
94 )
95 {
96  T* ptr = aptr.ptr();
97  if (!DictionaryBase<PtrList<T>, T>::hashedTs_.insert(key, ptr))
98  {
100  << "Cannot insert with key '" << key << "' into hash-table"
101  << abort(FatalError);
102  }
103  return PtrList<T>::set(i, ptr);
104 }
105 
106 
107 template<class T>
109 (
110  const label i,
111  const word& key,
112  tmp<T>& t
113 )
114 {
115  T* ptr = t.ptr();
116  if (!DictionaryBase<PtrList<T>, T>::hashedTs_.insert(key, ptr))
117  {
119  << "Cannot insert with key '" << key << "' into hash-table"
120  << abort(FatalError);
121  }
122  return PtrList<T>::set(i, ptr);
123 }
124 
125 
126 // ************************************************************************* //
dictionary dict
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
PtrListDictionary(const label size)
Construct given initial list size.
Base dictionary class templated on both the form of doubly-linked list it uses as well as the type it...
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
autoPtr< T > set(const label, const word &key, T *)
Set element to pointer provided and return old element.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
T * ptr()
Return object pointer for reuse.
Definition: autoPtrI.H:90
points setSize(newPointi)
Template dictionary class which manages the storage associated with it.
A class for handling words, derived from string.
Definition: word.H:59
errorManip< error > abort(error &err)
Definition: errorManip.H:131
const volScalarField & T
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:70
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:49
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
T * ptr() const
Return tmp pointer for reuse.
Definition: tmpI.H:205
A class for managing temporary objects.
Definition: PtrList.H:53