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-2024 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 
147  // Conversion
148 
149  //- Convert to list of different pointer type
150  template<class T2>
152 
153 
154  // Member Operators
155 
156  using PtrList<T>::operator[];
157 
158  //- Find and return entry
159  const T& operator[](const word& key) const
160  {
161  return *DictionaryBase<PtrList<T>, T>::operator[](key);
162  }
163 
164  //- Find and return entry
165  T& operator[](const word& key)
166  {
167  return *DictionaryBase<PtrList<T>, T>::operator[](key);
168  }
169 };
170 
171 
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173 
174 } // End namespace Foam
175 
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 
178 #ifdef NoRepository
179  #include "PtrListDictionary.C"
180 #endif
181 
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 
184 #endif
185 
186 // ************************************************************************* //
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.
UPtrListDictionary< T2 > convert()
Convert to list of different pointer 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.
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(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)