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 SLPtrList;
54 template<class T> class autoPtr;
55 template<class T> class tmp;
56 
57 // Forward declaration of friend functions and operators
58 template<class T> class PtrList;
59 
60 template<class T>
62 
63 
64 /*---------------------------------------------------------------------------*\
65  Class PtrList Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 template<class T>
69 class PtrList
70 :
71  public UPtrList<T>
72 {
73 
74 protected:
75 
76  // Protected Member Functions
77 
78  //- Read from Istream using given Istream constructor class
79  template<class INew>
80  void read(Istream&, const INew& inewt);
81 
82 
83 public:
84 
85  // Constructors
86 
87  //- Null Constructor
88  PtrList();
89 
90  //- Construct with size specified
91  explicit PtrList(const label);
92 
93  //- Copy constructor
94  PtrList(const PtrList<T>&);
95 
96  //- Copy constructor with additional argument for clone
97  template<class CloneArg>
98  PtrList(const PtrList<T>&, const CloneArg&);
99 
100  //- Construct by transferring the parameter contents
101  PtrList(const Xfer<PtrList<T>>&);
102 
103  //- Construct as copy or re-use as specified
104  PtrList(PtrList<T>&, bool reuse);
105 
106  //- Construct as copy of SLPtrList<T>
107  explicit PtrList(const SLPtrList<T>&);
108 
109  //- Construct from Istream using given Istream constructor class
110  template<class INew>
111  PtrList(Istream&, const INew&);
112 
113  //- Construct from Istream using default Istream constructor class
114  PtrList(Istream&);
115 
116 
117  //- Destructor
118  ~PtrList();
119 
120 
121  // Member functions
122 
123  // Edit
124 
125  //- Reset size of PtrList. If extending the PtrList, new entries are
126  // set to NULL. If truncating the PtrList, removed entries are
127  // deleted
128  void setSize(const label);
129 
130  //- Alias for setSize(const label)
131  inline void resize(const label);
132 
133  //- Clear the PtrList, i.e. set size to zero deleting all the
134  // allocated entries
135  void clear();
136 
137  //- Append an element at the end of the list
138  inline void append(T*);
139  inline void append(const autoPtr<T>&);
140  inline void append(const tmp<T>&);
141 
142  //- Transfer the contents of the argument PtrList into this PtrList
143  // and annul the argument list
144  void transfer(PtrList<T>&);
145 
146  //- Transfer contents to the Xfer container
147  inline Xfer<PtrList<T>> xfer();
148 
149  //- Is element set
150  inline bool set(const label) const;
151 
152  //- Set element to given T* and return old element (can be NULL)
153  inline autoPtr<T> set(const label, T*);
154 
155  //- Set element to given autoPtr<T> and return old element
156  inline autoPtr<T> set(const label, const autoPtr<T>&);
157 
158  //- Set element to given tmp<T> and return old element
159  inline autoPtr<T> set(const label, const tmp<T>&);
160 
161  //- Reorders elements. Ordering does not have to be done in
162  // ascending or descending order. Reordering has to be unique.
163  // (is shuffle)
164  void reorder(const labelUList&);
165 
166 
167  // Member operators
168 
169  //- Assignment
170  void operator=(const PtrList<T>&);
171 
172 
173  // IOstream operator
174 
175  //- Read PtrList from Istream, discarding contents of existing PtrList
176  friend Istream& operator>> <T>(Istream&, PtrList<T>&);
177 };
178 
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 } // End namespace Foam
183 
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 
186 #include "PtrListI.H"
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 #ifdef NoRepository
191  #include "PtrList.C"
192 #endif
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 #endif
197 
198 // ************************************************************************* //
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
Non-intrusive singly-linked pointer list.
Definition: SLPtrList.H:47
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
void read(Istream &, const INew &inewt)
Read from Istream using given Istream constructor class.
Definition: PtrListIO.C:36
~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:60
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:62
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:53
A class for managing temporary objects.
Definition: PtrList.H:54
PtrList()
Null Constructor.
Definition: PtrList.C:32
Namespace for OpenFOAM.