DynamicList.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011 OpenFOAM Foundation
9  Copyright (C) 2017 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "DynamicList.H"
30 #include "labelRange.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 template<class T, int SizeMin>
36 (
37  const labelRange& slice
38 )
39 {
40  if (!slice.size())
41  {
42  // Noop
43  return 0;
44  }
45  else if (slice.after() >= this->size())
46  {
47  // Remove tail
48  this->resize(slice.first());
49  }
50  else
51  {
52  // Copy (swap) down
53  label j = slice.first();
54  const label len = this->size();
55 
56  for (label i = slice.after(); i < len; ++i, ++j)
57  {
58  Foam::Swap(this->operator[](i), this->operator[](j));
59  }
60 
61  resize(this->size() - slice.size());
62  }
63 
64  return slice.size();
65 }
66 
67 
68 template<class T, int SizeMin>
70 (
71  const labelRange& slice
72 )
73 {
74  if (slice.first() > 0)
75  {
76  // Copy (swap) down
77  label j = slice.first();
78  const label len = slice.size();
79 
80  for (label i = 0; i < len; ++i, ++j)
81  {
82  Foam::Swap(this->operator[](i), this->operator[](j));
83  }
84  }
85 
86  // Don't need min size, since slice size was already checked before
87  resize(slice.size());
88  return this->size();
89 }
90 
91 
92 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
93 
94 template<class T, int SizeMin>
96 :
97  List<T>(is),
98  capacity_(List<T>::size())
99 {}
100 
101 
102 template<class T, int SizeMin>
103 Foam::Ostream& Foam::operator<<
104 (
105  Ostream& os,
106  const DynamicList<T, SizeMin>& lst
107 )
108 {
109  os << static_cast<const List<T>&>(lst);
110  return os;
111 }
112 
113 
114 template<class T, int SizeMin>
115 Foam::Istream& Foam::operator>>
116 (
117  Istream& is,
118  DynamicList<T, SizeMin>& lst
119 )
120 {
121  is >> static_cast<List<T>&>(lst);
122  lst.capacity_ = lst.List<T>::size();
123 
124  return is;
125 }
126 
127 
128 // ************************************************************************* //
Foam::DynamicList::DynamicList
constexpr DynamicList() noexcept
Default construct, an empty list without allocation.
Definition: DynamicListI.H:62
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::Swap
void Swap(DynamicList< T, SizeMin1 > &a, DynamicList< T, SizeMin2 > &b)
Definition: DynamicListI.H:913
resize
patchWriters resize(patchIds.size())
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
T
const volScalarField & T
Definition: createFieldRefs.H:2
labelRange.H
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
DynamicList.H
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56