IndirectList.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-2022 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::IndirectList
29 
30 Description
31  A List with indirect addressing.
32 
33 See also
34  Foam::UIndirectList for a version without addressing allocation.
35 
36 Class
37  Foam::UIndirectList
38 
39 Description
40  A List with indirect addressing.
41  Like IndirectList but does not store addressing
42 
43  Note the const_cast of the list values. This is so we can use it both
44  on const and non-const lists. Alternative would be to have a const_
45  variant etc.
46 
47 SourceFiles
48  IndirectListI.H
49 
50 \*---------------------------------------------------------------------------*/
51 
52 #ifndef Foam_IndirectList_H
53 #define Foam_IndirectList_H
54 
55 #include "List.H"
56 #include "IndirectListAddressing.H"
57 #include "IndirectListBase.H"
58 
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 
61 namespace Foam
62 {
63 
64 // Forward Declarations
65 template<class T> class IndirectList;
66 template<class T> class UIndirectList;
67 
68 // Common list types
71 
72 
73 /*---------------------------------------------------------------------------*\
74  Class UIndirectList Declaration
75 \*---------------------------------------------------------------------------*/
76 
77 template<class T>
78 class UIndirectList
79 :
80  public IndirectListBase<T, labelUList>
81 {
82 public:
83 
84  // Constructors
85 
86  //- Shallow copy values and addressing
87  UIndirectList(const UList<T>& values, const labelUList& addr)
88  :
90  {}
91 
92  //- Copy construct (shallow copy values and addressing)
94  :
96  {}
97 
98 
99  // Member Operators
100 
101  //- Use standard assignment operations
103 
104  //- Deep copy values, Fatal if list sizes are not identical
105  void operator=(const UIndirectList<T>& rhs)
106  {
107  this->copyList(rhs);
108  }
109 };
110 
111 
112 /*---------------------------------------------------------------------------*\
113  Class IndirectList Declaration
114 \*---------------------------------------------------------------------------*/
115 
116 template<class T>
117 class IndirectList
118 :
119  private IndirectListAddressing<labelList>,
120  public UIndirectList<T>
121 {
122 public:
123 
124  // Constructors
125 
126  //- Copy construct addressing, shallow copy values reference
127  inline IndirectList(const UList<T>& values, const labelUList& addr);
128 
129  //- Move construct addressing, shallow copy values reference
130  inline IndirectList(const UList<T>& values, labelList&& addr);
131 
132  //- Zero-sized addressing, shallow copy values reference
133  inline IndirectList(const UList<T>& values, const Foam::zero);
134 
135  //- Copy construct addressing, shallow copy values reference
136  inline IndirectList(const IndirectList<T>& list);
137 
138  //- Move construct addressing, shallow copy values reference
139  inline IndirectList(IndirectList<T>&& list);
140 
141  //- Copy construct addressing, shallow copy values reference
142  inline explicit IndirectList(const UIndirectList<T>& list);
143 
144 
145  // Static Functions
146 
147  //- Return an IndirectList comprising entries with \em positions
148  //- that satisfy the condition predicate.
149  //
150  // The condition predicate can be considered a type of \em mask
151  // for any given position.
152  // A boolList, bitSet, labelRange or labelHashSet all satisfy
153  // the requirements for use as position condition predicates.
154  //
155  // \param values The source list values
156  // \param select Accept/reject predicate based on \em position.
157  // \param invert Invert (negate) the selection logic
158  template<class UnaryCondition>
159  static IndirectList<T> subset
160  (
161  const UList<T>& values,
162  const UnaryCondition& select,
163  const bool invert = false
164  );
165 
166  //- Return an IndirectList comprising entries with \em values
167  //- that satisfy the predicate.
168  //
169  // \param values The source list values
170  // \param pred Predicate used to test the \em value
171  // \param invert Invert (negate) the selection logic
172  template<class UnaryPredicate>
173  static IndirectList<T> subset_if
174  (
175  const UList<T>& values,
176  const UnaryPredicate& pred,
177  const bool invert = false
178  );
179 
180  //- Return an IndirectList with duplicate entries filtered out.
181  // Preserves the original input order, unless sorted = true
182  //
183  // \param values The source list values
184  // \param sorted Retain sorted order instead of original order
185  static IndirectList<T> uniq
186  (
187  const UList<T>& values,
188  const bool sorted = false
189  );
190 
191 
192  // Member Functions
193 
194  //- The list addressing
196 
197 
198  // Member Operators
199 
200  //- Assignment operator
201  using UIndirectList<T>::operator=;
202 
203  //- Deep copy values, Fatal if list sizes are not identical
204  void operator=(const IndirectList<T>& rhs)
205  {
206  this->copyList(rhs);
207  }
208 };
209 
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 } // End namespace Foam
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 #include "IndirectListI.H"
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
221 #endif
222 
223 // ************************************************************************* //
const UList< T > & values() const noexcept
The list of values (without addressing)
void operator=(const IndirectList< T > &rhs)
Deep copy values, Fatal if list sizes are not identical.
Definition: IndirectList.H:234
List< bool > select(const label n, const labelUList &locations)
Construct a selection list of bools (all false) with the given pre-size, subsequently add specified l...
Definition: BitOps.C:134
UIndirectList< label > labelUIndList
UIndirectList of labels.
Definition: IndirectList.H:65
IndirectList(const UList< T > &values, const labelUList &addr)
Copy construct addressing, shallow copy values reference.
Definition: IndirectListI.H:26
static IndirectList< T > subset(const UList< T > &values, const UnaryCondition &select, const bool invert=false)
Return an IndirectList comprising entries with positions that satisfy the condition predicate...
Base for lists with indirect addressing, templated on the list contents type and the addressing type...
static IndirectList< T > subset_if(const UList< T > &values, const UnaryPredicate &pred, const bool invert=false)
Return an IndirectList comprising entries with values that satisfy the predicate. ...
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
void operator=(const UIndirectList< T > &rhs)
Deep copy values, Fatal if list sizes are not identical.
Definition: IndirectList.H:108
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:105
const labelUList & addressing() const noexcept
The addressing used for the list.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
UIndirectList(const UList< T > &values, const labelUList &addr)
Shallow copy values and addressing.
Definition: IndirectList.H:84
labelList invert(const label len, const labelUList &map)
Create an inverse one-to-one mapping.
Definition: ListOps.C:29
const Addr & addressing() const noexcept
Const access to the addressing.
A List with indirect addressing. Like IndirectList but does not store addressing. ...
Definition: faMatrix.H:56
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
static IndirectList< T > uniq(const UList< T > &values, const bool sorted=false)
Return an IndirectList with duplicate entries filtered out.
void copyList(const ListType &rhs)
Deep copy values from the list.
List< label > labelList
A List of labels.
Definition: List.H:62
A List with indirect addressing.
Definition: IndirectList.H:60
UIndirectList< bool > boolUIndList
UIndirectList of bools.
Definition: IndirectList.H:61
List< T > list() const
Return the addressed elements as a List.
Namespace for OpenFOAM.