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-2023 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 #include "UPtrListDictionary.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class T>
33 :
34  DictionaryBase<PtrList<T>, T>(2*size)
35 {
37 }
38 
39 
40 template<class T>
42 :
44 {}
45 
46 
47 template<class T>
49 :
50  DictionaryBase<PtrList<T>, T>(move(dict))
51 {}
52 
53 
54 template<class T>
55 template<class INew>
57 :
58  DictionaryBase<PtrList<T>, T>(is, iNew)
59 {}
60 
61 
62 template<class T>
64 :
65  DictionaryBase<PtrList<T>, T>(is)
66 {}
67 
68 
69 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
70 
71 template<class T>
73 (
74  const label i,
75  const word& key,
76  T* ptr
77 )
78 {
79  if (!DictionaryBase<PtrList<T>, T>::hashedTs_.insert(key, ptr))
80  {
82  << "Cannot insert with key '" << key << "' into hash-table"
83  << abort(FatalError);
84  }
85  return PtrList<T>::set(i, ptr);
86 }
87 
88 
89 template<class T>
91 (
92  const label i,
93  const word& key,
94  autoPtr<T>& aptr
95 )
96 {
97  T* ptr = aptr.ptr();
98  if (!DictionaryBase<PtrList<T>, T>::hashedTs_.insert(key, ptr))
99  {
101  << "Cannot insert with key '" << key << "' into hash-table"
102  << abort(FatalError);
103  }
104  return PtrList<T>::set(i, ptr);
105 }
106 
107 
108 template<class T>
110 (
111  const label i,
112  const word& key,
113  tmp<T>& t
114 )
115 {
116  T* ptr = t.ptr();
117  if (!DictionaryBase<PtrList<T>, T>::hashedTs_.insert(key, ptr))
118  {
120  << "Cannot insert with key '" << key << "' into hash-table"
121  << abort(FatalError);
122  }
123  return PtrList<T>::set(i, ptr);
124 }
125 
126 
127 template<class T>
128 template<class T2>
130 {
131  UPtrListDictionary<T2> result(this->size());
132 
133  forAll(*this, i)
134  {
135  result.set
136  (
137  i,
138  this->operator()(i)->keyword(),
139  dynamic_cast<T2*>(this->operator()(i))
140  );
141  }
142 
143  return result;
144 }
145 
146 
147 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Base dictionary class templated on both the form of doubly-linked list it uses as well as the type it...
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:50
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
Template dictionary class which manages the storage associated with it.
UPtrListDictionary< T2 > convert()
Convert to list of different pointer type.
autoPtr< T > set(const label, const word &key, T *)
Set element to pointer provided and return old element.
PtrListDictionary(const label size)
Construct given initial list size.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
bool set(const label) const
Is element set.
Definition: PtrListI.H:65
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:131
Template dictionary class which manages the storage associated with it.
bool set(const label) const
Is element set.
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
T * ptr()
Return object pointer for reuse.
Definition: autoPtrI.H:90
A class for managing temporary objects.
Definition: tmp.H:55
T * ptr() const
Return tmp pointer for reuse.
Definition: tmpI.H:205
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
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
errorManip< error > abort(error &err)
Definition: errorManip.H:131
error FatalError
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
dictionary dict