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 -------------------------------------------------------------------------------
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 Class
28  Foam::SubList
29 
30 Description
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 
37 SourceFiles
38  SubListI.H
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef SubList_H
43 #define SubList_H
44 
45 #include "List.H"
46 #include "FixedList.H"
47 #include "labelRange.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward Declarations
55 template<class T> class SubList;
56 
57 // Common list types
61 
62 
63 /*---------------------------------------------------------------------------*\
64  Class SubList Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 template<class T>
68 class SubList
69 :
70  public UList<T>
71 {
72 public:
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 
164 template<class Type>
166 Foam::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 
176 template<class Type>
178 Foam::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 
188 template<class Type>
191 {
192  return SubList<Type>(*this, range); // with range checking
193 }
194 
195 
196 template<class Type>
199 {
200  return SubList<Type>(*this, range); // with range checking
201 }
202 
203 
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 
206 #endif
207 
208 // ************************************************************************* //
List.H
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:54
SubListI.H
Foam::labelSubList
SubList< label > labelSubList
A SubList of labels.
Definition: SubList.H:59
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::labelRange
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:55
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::SubList::operator=
void operator=(const SubList< T > &list)
Copy assign entries from given sub-list. Sizes must match!
Definition: SubListI.H:130
Foam::boolSubList
SubList< bool > boolSubList
A SubList of bools.
Definition: SubList.H:54
Foam::UList::slice
SubList< T > slice(const label pos, label len=-1)
Return SubList slice (non-const access) - no range checking.
Definition: SubList.H:165
range
scalar range
Definition: LISASMDCalcMethod1.H:12
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
Foam::FixedList
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:104
Foam::UList
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:103
Foam::SubList::SubList
SubList() noexcept=default
Default construct, zero-sized and nullptr.
Foam::IndirectListBase
Base for lists with indirect addressing, templated on the list contents type and the addressing type....
Definition: IndirectListBase.H:56
FixedList.H
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:62
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177
Foam::charSubList
SubList< char > charSubList
A SubList of chars.
Definition: SubList.H:58