PtrList.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) 2011-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::PtrList
26 
27 Description
28  A templated 1D list of pointers to objects of type <T>, where the
29  size of the array is known and used for subscript bounds checking, etc.
30 
31  The element operator [] returns a reference to the object rather than a
32  pointer.
33 
34 SourceFiles
35  PtrListI.H
36  PtrList.C
37  PtrListIO.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef PtrList_H
42 #define PtrList_H
43 
44 #include "UPtrList.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 // Forward declaration of classes
52 
53 template<class T> class autoPtr;
54 template<class T> class tmp;
55 
56 class SLListBase;
57 template<class LListBase, class T> class LPtrList;
58 template<class T>
59 using SLPtrList = LPtrList<SLListBase, T>;
60 
61 // Forward declaration of friend functions and operators
62 template<class T> class PtrList;
63 
64 template<class T>
66 
67 
68 /*---------------------------------------------------------------------------*\
69  Class PtrList Declaration
70 \*---------------------------------------------------------------------------*/
71 
72 template<class T>
73 class PtrList
74 :
75  public UPtrList<T>
76 {
77 
78 protected:
79 
80  // Protected Member Functions
81 
82  //- Read from Istream using given Istream constructor class
83  template<class INew>
84  void read(Istream&, const INew& inewt);
85 
86 
87 public:
88 
89  // Constructors
90 
91  //- Null Constructor
92  PtrList();
93 
94  //- Construct with size specified
95  explicit PtrList(const label);
96 
97  //- Copy constructor
98  PtrList(const PtrList<T>&);
99 
100  //- Copy constructor with additional argument for clone
101  template<class CloneArg>
102  PtrList(const PtrList<T>&, const CloneArg&);
103 
104  //- Move constructor
105  PtrList(PtrList<T>&&);
106 
107  //- Construct as copy or reuse as specified
108  PtrList(PtrList<T>&, bool reuse);
109 
110  //- Construct as copy of SLPtrList<T>
111  explicit PtrList(const SLPtrList<T>&);
112 
113  //- Construct from Istream using given Istream constructor class
114  template<class INew>
115  PtrList(Istream&, const INew&);
116 
117  //- Construct from Istream using default Istream constructor class
118  PtrList(Istream&);
119 
120 
121  //- Destructor
122  ~PtrList();
123 
124 
125  // Member Functions
126 
127  // Edit
128 
129  //- Reset size of PtrList. If extending the PtrList, new entries are
130  // set to nullptr. If truncating the PtrList, removed entries are
131  // deleted
132  void setSize(const label);
133 
134  //- Alias for setSize(const label)
135  inline void resize(const label);
136 
137  //- Shrink the allocated space to the number of elements used.
138  void shrink();
139 
140  //- Clear the PtrList, i.e. set size to zero deleting all the
141  // allocated entries
142  void clear();
143 
144  //- Append an element at the end of the list
145  inline void append(T*);
146 
147  //- Append an element at the end of the list
148  inline void append(const autoPtr<T>&);
149 
150  //- Append an element at the end of the list
151  inline void append(const tmp<T>&);
152 
153  //- Transfer the contents of the argument PtrList into this PtrList
154  // and annul the argument list
155  void transfer(PtrList<T>&);
156 
157  //- Is element set
158  inline bool set(const label) const;
159 
160  //- Set element to given T* and return old element (can be nullptr)
161  inline autoPtr<T> set(const label, T*);
162 
163  //- Set element to given autoPtr<T> and return old element
164  inline autoPtr<T> set(const label, const autoPtr<T>&);
165 
166  //- Set element to given tmp<T> and return old element
167  inline autoPtr<T> set(const label, const tmp<T>&);
168 
169  //- Reorders elements. Ordering does not have to be done in
170  // ascending or descending order. Reordering has to be unique.
171  // (is shuffle)
172  void reorder(const labelUList& oldToNew);
173 
174  //- Reorders elements. Ordering does not have to be done in
175  // ascending or descending order. Reordering has to be unique.
176  // Note: can create unset elements
177  void shuffle(const labelUList& newToOld);
178 
179 
180  // Member Operators
181 
182  //- Assignment operator
183  void operator=(const PtrList<T>&);
184 
185  //- Move assignment operator
186  void operator=(PtrList<T>&&);
187 
188 
189  // IOstream operator
190 
191  //- Read PtrList from Istream, discarding contents of existing PtrList
192  friend Istream& operator>> <T>(Istream&, PtrList<T>&);
193 };
194 
195 
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 
198 } // End namespace Foam
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 #include "PtrListI.H"
203 
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 
206 #ifdef NoRepository
207  #include "PtrList.C"
208 #endif
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 
212 #endif
213 
214 // ************************************************************************* //
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 class for non-intrusive linked PtrLists.
Definition: LPtrList.H:65
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
void read(Istream &, const INew &inewt)
Read from Istream using given Istream constructor class.
Definition: PtrListIO.C:36
void shrink()
Shrink the allocated space to the number of elements used.
Definition: PtrList.C:174
bool set(const label) const
Is element set.
Definition: PtrListI.H:62
PtrList()
Null Constructor.
Definition: PtrList.C:32
void resize(const label)
Alias for setSize(const label)
Definition: PtrListI.H:32
void reorder(const labelUList &oldToNew)
Reorders elements. Ordering does not have to be done in.
Definition: PtrList.C:221
void shuffle(const labelUList &newToOld)
Reorders elements. Ordering does not have to be done in.
Definition: PtrList.C:272
~PtrList()
Destructor.
Definition: PtrList.C:116
void clear()
Clear the PtrList, i.e. set size to zero deleting all the.
Definition: PtrList.C:198
void append(T *)
Append an element at the end of the list.
Definition: PtrListI.H:39
void operator=(const PtrList< T > &)
Assignment operator.
Definition: PtrList.C:298
void transfer(PtrList< T > &)
Transfer the contents of the argument PtrList into this PtrList.
Definition: PtrList.C:213
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:131
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:66
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
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
Istream & operator>>(Istream &, pistonPointEdgeData &)
LPtrList< SLListBase, T > SLPtrList
Definition: SLPtrList.H:43
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)