All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2019 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  }
96  }
97 }
98 
99 
100 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
101 
102 template<class T>
104 {}
105 
106 
107 template<class T>
109 {
110  return autoPtr<List<T>>(new List<T>(*this));
111 }
112 
113 
114 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115 
116 template<class T>
118 {
119  return NullObjectRef<List<T>>();
120 }
121 
122 
123 template<class T>
124 inline void Foam::List<T>::clear()
125 {
126  if (this->v_)
127  {
128  delete[] this->v_;
129  this->v_ = 0;
130  }
131 
132  this->size_ = 0;
133 }
134 
135 
136 template<class T>
137 inline void Foam::List<T>::resize(const label newSize)
138 {
139  this->setSize(newSize);
140 }
141 
142 
143 template<class T>
144 inline void Foam::List<T>::resize(const label newSize, const T& a)
145 {
146  this->setSize(newSize, a);
147 }
148 
149 
150 template<class T>
152 {
153  if (i >= this->size())
154  {
155  setSize(2*this->size());
156  }
157 
158  return UList<T>::operator[](i);
159 }
160 
161 
162 template<class T>
163 inline void Foam::List<T>::size(const label n)
164 {
165  UList<T>::size_ = n;
166 }
167 
168 
169 template<class T>
171 {
172  return UList<T>::size_;
173 }
174 
175 
176 template<class T>
177 inline void Foam::List<T>::append(const T& t)
178 {
179  setSize(size()+1, t);
180 }
181 
182 
183 template<class T>
184 inline void Foam::List<T>::append(const UList<T>& lst)
185 {
186  if (this == &lst)
187  {
189  << "attempted appending to self" << abort(FatalError);
190  }
191 
192  label nextFree = this->size();
193  setSize(nextFree + lst.size());
194 
195  forAll(lst, elemI)
196  {
197  this->operator[](nextFree++) = lst[elemI];
198  }
199 }
200 
201 
202 template<class T>
204 {
205  label nextFree = this->size();
206  setSize(nextFree + lst.size());
207 
208  forAll(lst, elemI)
209  {
210  this->operator[](nextFree++) = lst[elemI];
211  }
212 }
213 
214 
215 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
216 
217 template<class T>
218 inline void Foam::List<T>::operator=(const T& t)
219 {
221 }
222 
223 
224 template<class T>
225 inline void Foam::List<T>::operator=(const zero)
226 {
228 }
229 
230 
231 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
tUEqn clear()
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:151
static const List< T > & null()
Return a null List.
Definition: ListI.H:117
void resize(const label)
Alias for setSize(const label)
Definition: ListI.H:137
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:124
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:177
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
const volScalarField & T
List()
Null constructor.
Definition: ListI.H:103
void operator=(const UList< T > &)
Assignment to UList operator. Takes linear time.
Definition: List.C:376
A List with indirect addressing.
Definition: fvMatrix.H:106
autoPtr< List< T > > clone() const
Clone.
Definition: ListI.H:108
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:299
label size() const
Return the number of elements in the UList.
Definition: ListI.H:170