PtrList.H
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) 2011-2016 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>
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  //- Construct by transferring the parameter contents
105  PtrList(const Xfer<PtrList<T>>&);
106 
107  //- Construct as copy or re-use 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  //- Clear the PtrList, i.e. set size to zero deleting all the
138  // allocated entries
139  void clear();
140 
141  //- Append an element at the end of the list
142  inline void append(T*);
143  inline void append(const autoPtr<T>&);
144  inline void append(const tmp<T>&);
145 
146  //- Transfer the contents of the argument PtrList into this PtrList
147  // and annul the argument list
148  void transfer(PtrList<T>&);
149 
150  //- Transfer contents to the Xfer container
151  inline Xfer<PtrList<T>> xfer();
152 
153  //- Is element set
154  inline bool set(const label) const;
155 
156  //- Set element to given T* and return old element (can be nullptr)
157  inline autoPtr<T> set(const label, T*);
158 
159  //- Set element to given autoPtr<T> and return old element
160  inline autoPtr<T> set(const label, const autoPtr<T>&);
161 
162  //- Set element to given tmp<T> and return old element
163  inline autoPtr<T> set(const label, const tmp<T>&);
164 
165  //- Reorders elements. Ordering does not have to be done in
166  // ascending or descending order. Reordering has to be unique.
167  // (is shuffle)
168  void reorder(const labelUList&);
169 
170 
171  // Member operators
172 
173  //- Assignment
174  void operator=(const PtrList<T>&);
175 
176 
177  // IOstream operator
178 
179  //- Read PtrList from Istream, discarding contents of existing PtrList
180  friend Istream& operator>> <T>(Istream&, PtrList<T>&);
181 };
182 
183 
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 
186 } // End namespace Foam
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 #include "PtrListI.H"
191 
192 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193 
194 #ifdef NoRepository
195  #include "PtrList.C"
196 #endif
197 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 #endif
201 
202 // ************************************************************************* //
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
void append(T *)
Append an element at the end of the list.
Definition: PtrListI.H:39
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
Xfer< PtrList< T > > xfer()
Transfer contents to the Xfer container.
Definition: PtrListI.H:103
void reorder(const labelUList &)
Reorders elements. Ordering does not have to be done in.
Definition: PtrList.C:197
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Base singly-linked list.
Definition: SLListBase.H:50
void read(Istream &, const INew &inewt)
Read from Istream using given Istream constructor class.
Definition: PtrListIO.C:36
Template class for non-intrusive linked PtrLists.
Definition: LPtrList.H:47
~PtrList()
Destructor.
Definition: PtrList.C:116
void operator=(const PtrList< T > &)
Assignment.
Definition: PtrList.C:250
Istream & operator>>(Istream &, directionInfo &)
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:54
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:61
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:131
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:63
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:49
void transfer(PtrList< T > &)
Transfer the contents of the argument PtrList into this PtrList.
Definition: PtrList.C:189
void resize(const label)
Alias for setSize(const label)
Definition: PtrListI.H:32
void clear()
Clear the PtrList, i.e. set size to zero deleting all the.
Definition: PtrList.C:174
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
A class for managing temporary objects.
Definition: PtrList.H:53
PtrList()
Null Constructor.
Definition: PtrList.C:32
Namespace for OpenFOAM.