PtrListDictionary.H
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-2025 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 Class
25  Foam::PtrListDictionary
26 
27 Description
28  Template dictionary class which manages the storage associated with it.
29 
30  It is derived from DictionaryBase instantiated on the memory managed PtrList
31  of <T> to provide ordered indexing in addition to the dictionary lookup.
32 
33 SourceFiles
34  PtrListDictionary.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef PtrListDictionary_H
39 #define PtrListDictionary_H
40 
41 #include "DictionaryBase.H"
42 #include "PtrList.H"
43 #include "wordRe.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 template<class T>
51 class UPtrListDictionary;
52 
53 /*---------------------------------------------------------------------------*\
54  Class PtrListDictionary Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 template<class T>
59 :
60  public DictionaryBase<PtrList<T>, T>
61 {
62 
63 public:
64 
65  // Related types
66 
67  //- Declare friendship with the UPtrListDictionary class
68  friend class UPtrListDictionary<T>;
69 
70 
71  // Constructors
72 
73  //- Construct given initial list size
75 
76  //- Copy constructor
78 
79  //- Move constructor
81 
82  //- Construct from Istream using given Istream constructor class
83  template<class INew>
84  PtrListDictionary(Istream&, const INew&);
85 
86  //- Construct from Istream
88 
89 
90  // Member Functions
91 
92  // Access
93 
94  //- Return the index of the given the key or -1 if not found
95  label findIndex(const word& key) const;
96 
97  //- Return the indices for all matches
98  // of the given key regular expression
99  List<label> findIndices(const wordRe& key) const;
100 
101 
102  // Edit
103 
104  //- Append an element at the end of the list
105  inline void append(const word& key, T*);
106 
107  //- Append an element at the end of the list
108  inline void append(const word& key, const autoPtr<T>&);
109 
110  //- Append an element at the end of the list
111  inline void append(const word& key, const tmp<T>&);
112 
113  //- Append an element at the end of the list
114  // using the element's keyword as the key
115  inline void append(T*);
116 
117  //- Append an element at the end of the list
118  // using the element's keyword as the key
119  inline void append(const autoPtr<T>&);
120 
121  //- Append an element at the end of the list
122  // using the element's keyword as the key
123  inline void append(const tmp<T>&);
124 
125  //- Set element to pointer provided and return old element
126  autoPtr<T> set(const label, const word& key, T*);
127 
128  //- Set element to autoPtr value provided and return old element
129  autoPtr<T> set(const label, const word& key, const autoPtr<T>&);
130 
131  //- Set element to tmp value provided and return old element
132  autoPtr<T> set(const label, const word& key, const tmp<T>&);
133 
134  //- Set element to pointer provided and return old element
135  // using the element's keyword as the key
136  autoPtr<T> set(const label, T*);
137 
138  //- Set element to autoPtr value provided and return old element
139  // using the element's keyword as the key
140  autoPtr<T> set(const label, const autoPtr<T>&);
141 
142  //- Set element to tmp value provided and return old element
143  // using the element's keyword as the key
144  autoPtr<T> set(const label, const tmp<T>&);
145 
146  //- Remove an entry from the list and return
147  autoPtr<T> remove(const word& key);
148 
149 
150  // Conversion
151 
152  //- Convert to list of different type
153  template<class T2>
155 
156  //- Lookup and return the sub-list of the given type
157  template<class T2>
159 
160  //- Lookup and return the sub-list of the given type
161  template<class T2>
163 
164 
165  // Member Operators
166 
167  using PtrList<T>::operator[];
168 
169  //- Find and return entry
170  const T& operator[](const word& key) const
171  {
172  return *DictionaryBase<PtrList<T>, T>::operator[](key);
173  }
174 
175  //- Find and return entry
176  T& operator[](const word& key)
177  {
178  return *DictionaryBase<PtrList<T>, T>::operator[](key);
179  }
180 };
181 
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 } // End namespace Foam
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 #ifdef NoRepository
190  #include "PtrListDictionary.C"
191 #endif
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #endif
196 
197 // ************************************************************************* //
Base dictionary class templated on both the form of doubly-linked list it uses as well as the type it...
friend Ostream & operator(Ostream &, const DictionaryBase< PtrList< T >, T > &)
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.
autoPtr< T > remove(const word &key)
Remove an entry from the list and return.
UPtrListDictionary< T2 > convert()
Convert to list of different type.
List< label > findIndices(const wordRe &key) const
Return the indices for all matches.
void append(const word &key, T *)
Append an element at the end of the list.
const T & operator[](const word &key) const
Find and return entry.
UPtrListDictionary< T2 > lookupType()
Lookup and return the sub-list of the given type.
autoPtr< T > set(const label, const word &key, T *)
Set element to pointer provided and return old element.
label findIndex(const word &key) const
Return the index of the given the key or -1 if not found.
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
Template dictionary class which manages the storage associated with it.
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
A class for managing temporary objects.
Definition: tmp.H:55
A wordRe is a word, but can also have a regular expression for matching words.
Definition: wordRe.H:77
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
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
void T(LagrangianPatchField< Type > &f, const LagrangianPatchField< Type > &f1)