ListListOps.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-2013 OpenFOAM Foundation
9  Copyright (C) 2018 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 template<class T, class AccessOp>
31 (
32  const UList<T>& lists,
33  AccessOp aop
34 )
35 {
36  labelList output(lists.size());
37  auto out = output.begin();
38 
39  for (const T& sub : lists)
40  {
41  *out = aop(sub).size();
42  ++out;
43  }
44 
45  return output;
46 }
47 
48 
49 template<class T, class AccessOp>
51 (
52  const UList<T>& lists,
53  AccessOp aop
54 )
55 {
56  label len = 0;
57 
58  for (const T& sub : lists)
59  {
60  len += aop(sub).size();
61  }
62 
63  return len;
64 }
65 
66 
67 template<class AccessType, class T, class AccessOp>
69 (
70  const UList<T>& lists,
71  AccessOp aop
72 )
73 {
74  label len = 0;
75 
76  for (const T& sub : lists)
77  {
78  len += aop(sub).size();
79  }
80 
81  AccessType output(len);
82  auto out = output.begin();
83 
84  for (const T& sub : lists)
85  {
86  for (const auto& item : aop(sub))
87  {
88  *out = item;
89  ++out;
90  }
91  }
92 
93  return output;
94 }
95 
96 
97 template<class AccessType, class T, class AccessOp, class OffsetOp>
99 (
100  const UList<T>& lists,
101  const labelUList& offsets,
102  AccessOp aop,
103  OffsetOp oop
104 )
105 {
106  label len = 0;
107 
108  for (const T& sub : lists)
109  {
110  len += aop(sub).size();
111  }
112 
113  AccessType output(len);
114  auto out = output.begin();
115  auto off = offsets.begin();
116 
117  label offset = 0;
118  for (const T& sub : lists)
119  {
120  for (const auto& item : aop(sub))
121  {
122  *out = oop(item, offset);
123  ++out;
124  }
125 
126  offset += *off;
127  ++off;
128  }
129 
130  return output;
131 }
132 
133 
134 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::ListListOps::combineOffset
AccessType combineOffset(const UList< T > &lists, const labelUList &offsets, AccessOp aop, OffsetOp oop=offsetOp< T >())
Like combine but also offsets sublists based on passed sizes.
Definition: ListListOps.C:99
Foam::output
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
Foam::ListListOps::subSizes
labelList subSizes(const IndirectListBase< T, Addr > &lists, AccessOp aop)
Return the sizes of the sub-lists.
Definition: ensightOutput.H:67
Foam::UList::begin
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition: UListI.H:329
Foam::ListListOps::combine
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:69
Foam::ListListOps::sumSizes
label sumSizes(const UList< T > &lists, AccessOp aop=accessOp< T >())
The total size of all sub-lists.
T
const volScalarField & T
Definition: createFieldRefs.H:2
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::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