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 | Copyright (C) 2015 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>
47 template<class INew>
49 :
50  DictionaryBase<PtrList<T>, T>(is, iNew)
51 {}
52 
53 
54 template<class T>
56 :
57  DictionaryBase<PtrList<T>, T>(is)
58 {}
59 
60 
61 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
62 
63 template<class T>
65 (
66  const label i,
67  const word& key,
68  T* ptr
69 )
70 {
71  if (!DictionaryBase<PtrList<T>, T>::hashedTs_.insert(key, ptr))
72  {
74  << "Cannot insert with key '" << key << "' into hash-table"
75  << abort(FatalError);
76  }
77  return PtrList<T>::set(i, ptr);
78 }
79 
80 
81 template<class T>
83 (
84  const label i,
85  const word& key,
86  autoPtr<T>& aptr
87 )
88 {
89  T* ptr = aptr.ptr();
90  if (!DictionaryBase<PtrList<T>, T>::hashedTs_.insert(key, ptr))
91  {
93  << "Cannot insert with key '" << key << "' into hash-table"
94  << abort(FatalError);
95  }
96  return PtrList<T>::set(i, ptr);
97 }
98 
99 
100 template<class T>
102 (
103  const label i,
104  const word& key,
105  tmp<T>& t
106 )
107 {
108  T* ptr = t.ptr();
109  if (!DictionaryBase<PtrList<T>, T>::hashedTs_.insert(key, ptr))
110  {
112  << "Cannot insert with key '" << key << "' into hash-table"
113  << abort(FatalError);
114  }
115  return PtrList<T>::set(i, ptr);
116 }
117 
118 
119 // ************************************************************************* //
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:319
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
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
Template dictionary class which manages the storage associated with it.
A class for handling words, derived from string.
Definition: word.H:59
bool set(const label) const
Is element set.
Definition: PtrListI.H:65
HashTable< T * > hashedTs_
HashTable of the entries held on the IDLListType for quick lookup.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:131
T * ptr() const
Return tmp pointer for reuse.
Definition: tmpI.H:198
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
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:62
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:53
A class for managing temporary objects.
Definition: PtrList.H:54