ListI.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-2020 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 \*---------------------------------------------------------------------------*/
25 
26 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
27 
28 template<class T>
29 inline void Foam::List<T>::alloc()
30 {
31  if (this->size_ > 0)
32  {
33  this->v_ = new T[this->size_];
34  }
35 }
36 
37 
38 template<class T>
39 inline void Foam::List<T>::reAlloc(const label s)
40 {
41  if (this->size_ != s)
42  {
43  clear();
44  this->size_ = s;
45  alloc();
46  }
47 }
48 
49 
50 template<class T>
51 template<class List2>
52 inline void Foam::List<T>::copyList(const List2& lst)
53 {
54  if (this->size_)
55  {
56  forAll(*this, i)
57  {
58  this->operator[](i) = lst[i];
59  }
60  }
61 }
62 
63 
64 template<class T>
65 template<class List2>
66 inline void Foam::List<T>::allocCopyList(const List2& lst)
67 {
68  if (this->size_)
69  {
70  alloc();
71  copyList(lst);
72  }
73 }
74 
75 
76 template<class T>
77 template<class InputIterator>
79 (
80  InputIterator first,
81  InputIterator last,
82  const label s
83 )
84 :
85  UList<T>(nullptr, s)
86 {
87  if (this->size_)
88  {
89  alloc();
90 
91  InputIterator iter = first;
92  forAll(*this, i)
93  {
94  this->operator[](i) = *iter;
95  ++iter;
96  }
97  }
98 }
99 
100 
101 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
102 
103 template<class T>
105 {}
106 
107 
108 template<class T>
110 {
111  return autoPtr<List<T>>(new List<T>(*this));
112 }
113 
114 
115 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
116 
117 template<class T>
119 {
120  return NullObjectRef<List<T>>();
121 }
122 
123 
124 template<class T>
125 inline void Foam::List<T>::clear()
126 {
127  if (this->v_)
128  {
129  delete[] this->v_;
130  this->v_ = 0;
131  }
132 
133  this->size_ = 0;
134 }
135 
136 
137 template<class T>
138 inline void Foam::List<T>::resize(const label newSize)
139 {
140  this->setSize(newSize);
141 }
142 
143 
144 template<class T>
145 inline void Foam::List<T>::resize(const label newSize, const T& a)
146 {
147  this->setSize(newSize, a);
148 }
149 
150 
151 template<class T>
153 {
154  if (i >= this->size())
155  {
156  setSize(2*this->size());
157  }
158 
159  return UList<T>::operator[](i);
160 }
161 
162 
163 template<class T>
164 inline void Foam::List<T>::size(const label n)
165 {
166  UList<T>::size_ = n;
167 }
168 
169 
170 template<class T>
172 {
173  return UList<T>::size_;
174 }
175 
176 
177 template<class T>
178 inline void Foam::List<T>::append(const T& t)
179 {
180  setSize(size()+1, t);
181 }
182 
183 
184 template<class T>
185 inline void Foam::List<T>::append(const UList<T>& lst)
186 {
187  if (this == &lst)
188  {
190  << "attempted appending to self" << abort(FatalError);
191  }
192 
193  label nextFree = this->size();
194  setSize(nextFree + lst.size());
195 
196  forAll(lst, elemI)
197  {
198  this->operator[](nextFree++) = lst[elemI];
199  }
200 }
201 
202 
203 template<class T>
205 {
206  label nextFree = this->size();
207  setSize(nextFree + lst.size());
208 
209  forAll(lst, elemI)
210  {
211  this->operator[](nextFree++) = lst[elemI];
212  }
213 }
214 
215 
216 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
217 
218 template<class T>
219 inline void Foam::List<T>::operator=(const T& t)
220 {
222 }
223 
224 
225 template<class T>
226 inline void Foam::List<T>::operator=(const zero)
227 {
229 }
230 
231 
232 // ************************************************************************* //
labelList first(const UList< labelPair > &p)
Definition: patchToPatch.C:38
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
tUEqn clear()
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
T & newElmt(const label)
Return subscript-checked element of UList.
Definition: ListI.H:152
static const List< T > & null()
Return a null List.
Definition: ListI.H:118
void resize(const label)
Alias for setSize(const label)
Definition: ListI.H:138
points setSize(newPointi)
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
label size() const
Return the number of elements in the list.
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:178
static const zero Zero
Definition: zero.H:97
errorManip< error > abort(error &err)
Definition: errorManip.H:131
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
List()
Null constructor.
Definition: ListI.H:104
void operator=(const UList< T > &)
Assignment to UList operator. Takes linear time.
Definition: List.C:376
const volScalarField & T
A List with indirect addressing.
Definition: fvMatrix.H:106
autoPtr< List< T > > clone() const
Clone.
Definition: ListI.H:109
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:49
label n
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171