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  DictionaryBase<PtrList<T>, T>(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  DictionaryBase<PtrList<T>, T>(is, iNew)
53 {}
54 
55 
56 template<class T>
58 :
59  DictionaryBase<PtrList<T>, T>(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  if (!DictionaryBase<PtrList<T>, T>::hashedTs_.insert(key, ptr))
74  {
76  << "Cannot insert with key '" << key << "' into hash-table"
77  << abort(FatalError);
78  }
79  return PtrList<T>::set(i, ptr);
80 }
81 
82 
83 template<class T>
85 (
86  const label i,
87  const word& key,
88  autoPtr<T>& aptr
89 )
90 {
91  T* ptr = aptr.ptr();
92  if (!DictionaryBase<PtrList<T>, T>::hashedTs_.insert(key, ptr))
93  {
95  << "Cannot insert with key '" << key << "' into hash-table"
96  << abort(FatalError);
97  }
98  return PtrList<T>::set(i, ptr);
99 }
100 
101 
102 template<class T>
104 (
105  const label i,
106  const word& key,
107  tmp<T>& t
108 )
109 {
110  T* ptr = t.ptr();
111  if (!DictionaryBase<PtrList<T>, T>::hashedTs_.insert(key, ptr))
112  {
114  << "Cannot insert with key '" << key << "' into hash-table"
115  << abort(FatalError);
116  }
117  return PtrList<T>::set(i, ptr);
118 }
119 
120 
121 // ************************************************************************* //
PtrListDictionary.H
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::glTF::key
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:108
Foam::PtrListDictionary::PtrListDictionary
PtrListDictionary(const label size)
Construct given initial list size.
Definition: PtrListDictionary.C:33
Foam::PtrListDictionary
Template dictionary class which manages the storage associated with it.
Definition: PtrListDictionary.H:55
Foam::INew
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:51
Foam::PtrListDictionary::set
autoPtr< T > set(const label, const word &key, T *)
Set element to pointer provided and return old element.
Definition: PtrListDictionary.C:67
resize
patchWriters resize(patchIds.size())
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
Foam::autoPtr::ptr
T * ptr() noexcept
Same as release().
Definition: autoPtr.H:172
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::tmp::ptr
T * ptr() const
Return managed pointer for reuse, or clone() the object reference.
Definition: tmpI.H:255
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
T
const volScalarField & T
Definition: createFieldRefs.H:2
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::DictionaryBase
Base dictionary class templated on both the form of doubly-linked list it uses as well as the type it...
Definition: DictionaryBase.H:64