UCompactListListI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "UCompactListList.H"
27 #include "ListOps.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class T>
33 :
34  offsets_(nullptr, 1),
35  m_()
36 {}
37 
38 
39 template<class T>
41 (
42  const UList<label>& offsets,
43  const UList<T>& m
44 )
45 :
46  offsets_(offsets),
47  m_(m)
48 {}
49 
50 
51 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52 
53 template<class T>
54 inline const Foam::UCompactListList<T>&
56 {
57  return NullObjectRef<UCompactListList<T>>();
58 }
59 
60 
61 template<class T>
63 {
64  return offsets_.size() - 1;
65 }
66 
67 
68 template<class T>
70 {
71  return !size();
72 }
73 
74 
75 template<class T>
76 inline const Foam::UList<Foam::label>&
78 {
79  return offsets_;
80 }
81 
82 
83 template<class T>
85 {
86  return offsets_;
87 }
88 
89 
90 template<class T>
92 const
93 {
94  return m_;
95 }
96 
97 
98 template<class T>
100 {
101  return m_;
102 }
103 
104 
105 template<class T>
107 (
108  const UCompactListList<T>& l
109 )
110 {
111  offsets_.shallowCopy(l.offsets_);
112  m_.shallowCopy(l.m_);
113 }
114 
115 
116 template<class T>
118 (
119  const UCompactListList<T>& l
120 )
121 {
122  offsets_.deepCopy(l.offsets_);
123  m_.deepCopy(l.m_);
124 }
125 
126 
127 template<class T>
129 (
130  const label i,
131  const label j
132 ) const
133 {
134  return offsets_[i] + j;
135 }
136 
137 
138 template<class T>
140 {
141  if (i < 0 || i >= m_.size())
142  {
144  << "Index " << i << " outside 0.." << m_.size()
145  << abort(FatalError);
146  }
147 
148  return findLower(offsets_, i+1);
149 }
150 
151 
152 template<class T>
154 (
155  const label row,
156  const label i
157 ) const
158 {
159  return i - index(row, 0);
160 }
161 
162 
163 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
164 
165 template<class T>
167 (
168  const label i
169 )
170 {
171  label start = offsets_[i];
172  return UList<T>(m_.begin() + start, offsets_[i+1] - start);
173 }
174 
175 
176 template<class T>
177 inline const Foam::UList<T>
179 (
180  const label i
181 ) const
182 {
183  label start = offsets_[i];
184  return UList<T>
185  (
186  const_cast<T*>(m_.begin() + start),
187  offsets_[i+1] - start
188  );
189 }
190 
191 
192 template<class T>
194 (
195  const label i,
196  const label j
197 )
198 {
199  return m_[index(i, j)];
200 }
201 
202 
203 template<class T>
205 (
206  const label i,
207  const label j
208 ) const
209 {
210  return m_[index(i, j)];
211 }
212 
213 
214 template<class T>
216 {
217  m_ = t;
218 }
219 
220 
221 // ************************************************************************* //
friend Ostream & operator(Ostream &, const UCompactListList< T > &)
const UList< T > & m() const
Return the packed matrix of data.
label size() const
Return the primary size, i.e. the number of rows.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
void shallowCopy(const UCompactListList< T > &)
Copy the ULists, but not the underlying data.
Various functions to operate on Lists.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
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:60
const volScalarField & T
label index(const label row, const label col) const
Return index into m.
Unallocated base class of CompactListList.
Definition: fvMesh.H:83
label findLower(const ListType &, typename ListType::const_reference, const label stary, const BinaryOp &bop)
Find last element < given value in sorted list and return index,.
UCompactListList()
Null constructor.
void operator=(const T &)
Assignment of all entries to the given value.
const UList< label > & offsets() const
Return the offset table (= size()+1)
void deepCopy(const UCompactListList< T > &)
Copy the underlying data.
label whichRow(const label index) const
Get row for index into m.
static const UCompactListList< T > & null()
Return a null UCompactListList.
label whichColumn(const label row, const label index) const
Get column index (j) given above row.
bool empty() const
Return true if the number of rows is zero.