SubList.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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2017-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::SubList
29
30Description
31 A List obtained as a section of another List.
32
33 Since the SubList is itself unallocated, no storage is allocated or
34 de-allocated during its use. To achieve this behaviour, SubList is
35 derived from UList rather than List.
36
37SourceFiles
38 SubListI.H
39
40\*---------------------------------------------------------------------------*/
41
42#ifndef Foam_SubList_H
43#define Foam_SubList_H
44
45#include "List.H"
46#include "labelRange.H"
47
48// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49
50namespace Foam
51{
52
53// Forward Declarations
54template<class T, unsigned N> class FixedList;
55template<class T> class SubList;
56
57// Common list types
61
62
63/*---------------------------------------------------------------------------*\
64 Class SubList Declaration
65\*---------------------------------------------------------------------------*/
66
67template<class T>
68class SubList
69:
70 public UList<T>
71{
72public:
73
74 // Static Functions
75
76 //- Return a null SubList
77 inline static const SubList<T>& null();
78
79
80 // Generated Methods
81
82 //- Default construct, zero-sized and nullptr
83 SubList() noexcept = default;
84
85 //- Copy construct, shallow copy
86 SubList(const SubList&) noexcept = default;
87
88
89 // Constructors
90
91 //- Construct from UList, the entire size
92 inline explicit SubList(const UList<T>& list);
93
94 //- Construct from FixedList, the entire size
95 template<unsigned N>
96 inline explicit SubList(const FixedList<T, N>& list);
97
98 //- Construct from UList and sub-list size, start at 0
99 inline SubList
100 (
101 const UList<T>& list,
102 const label subSize
103 );
104
105 //- Construct from UList, sub-list size and start index
106 inline SubList
107 (
108 const UList<T>& list,
109 const label subSize,
110 const label startIndex
111 );
112
113 //- Construct from UList and a (start,size) range.
114 // The range is subsetted with the list size itself to ensure that the
115 // result always addresses a valid section of the list.
116 inline SubList
117 (
118 const UList<T>& list,
119 const labelRange& range
120 );
121
122 //- Construct from UList and a (start,size) range, but bypassing
123 //- run-time range checking.
124 inline SubList
125 (
126 const labelRange& range,
127 const UList<T>& list
128 );
129
130
131 // Member Operators
132
133 //- Allow cast to a const List<T>&
134 inline operator const Foam::List<T>&() const;
135
136 //- Copy assign entries from given sub-list. Sizes must match!
137 inline void operator=(const SubList<T>& list);
138
139 //- Copy assign entries from given list. Sizes must match!
140 inline void operator=(const UList<T>& list);
141
142 //- Copy assign entries from given indirect list. Sizes must match!
143 template<class Addr>
144 inline void operator=(const IndirectListBase<T, Addr>& list);
145
146 //- Assign all entries to the given value
147 inline void operator=(const T& val);
148
149 //- Assign all entries to zero
150 inline void operator=(const Foam::zero);
151};
152
153
154// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155
156} // End namespace Foam
157
158// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159
160#include "SubListI.H"
161
162// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163
164template<class Type>
166Foam::UList<Type>::slice(const label pos, label len)
167{
168 if (len < 0)
169 {
170 len = (this->size() - pos);
171 }
172 return SubList<Type>(*this, len, pos);
173}
174
175
176template<class Type>
178Foam::UList<Type>::slice(const label pos, label len) const
179{
180 if (len < 0)
181 {
182 len = (this->size() - pos);
183 }
184 return SubList<Type>(*this, len, pos);
185}
186
187
188template<class Type>
191{
192 return SubList<Type>(*this, range); // with range checking
193}
194
195
196template<class Type>
199{
200 return SubList<Type>(*this, range); // with range checking
201}
202
203
204// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205
206#endif
207
208// ************************************************************************* //
scalar range
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: FixedList.H:81
Base for lists with indirect addressing, templated on the list contents type and the addressing type....
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
A List obtained as a section of another List.
Definition: SubList.H:70
SubList() noexcept=default
Default construct, zero-sized and nullptr.
static const SubList< T > & null()
Return a null SubList.
Definition: SubListI.H:116
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
SubList< T > slice(const label pos, label len=-1)
Return SubList slice (non-const access) - no range checking.
Definition: SubList.H:165
label size() const noexcept
The number of elements in the UList.
Definition: UListI.H:420
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:58
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:63
const volScalarField & T
Namespace for OpenFOAM.
dimensionedScalar pos(const dimensionedScalar &ds)
SubList< bool > boolSubList
A SubList of bools.
Definition: SubList.H:57
SubList< char > charSubList
A SubList of chars.
Definition: SubList.H:58
SubList< label > labelSubList
A SubList of labels.
Definition: SubList.H:59
const direction noexcept
Definition: Scalar.H:223
const Vector< label > N(dict.get< Vector< label > >("N"))