UCompactListList.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-2023 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 Class
25  Foam::UCompactListList
26 
27 Description
28  Unallocated base class of CompactListList
29 
30 SourceFiles
31  UCompactListList.C
32  UCompactListListI.H
33  UCompactListListIO.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef UCompactListList_H
38 #define UCompactListList_H
39 
40 #include "labelList.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 // Forward declaration of friend functions and operators
48 
49 template<class T> class UCompactListList;
50 
51 template<class T> Ostream& operator<<(Ostream&, const UCompactListList<T>&);
52 
53 /*---------------------------------------------------------------------------*\
54  Class UCompactListList Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 template<class T>
58 class UCompactListList
59 {
60  // Private Data
61 
62  //- Offset table
63  UList<label> offsets_;
64 
65  //- Packed matrix of data
66  UList<T> m_;
67 
68 
69 public:
70 
71  // Static Member Functions
72 
73  //- Return a null UCompactListList
74  inline static const UCompactListList<T>& null();
75 
76  //- Set the sizes to match that of the given list-list
77  template<class ListType, class ListListType>
78  static void setSizeToListList
79  (
80  ListType& offsets,
81  ListType& m,
82  const ListListType& ll
83  );
84 
85  //- Set the sizes and values to match that of the given list-list
86  template<class ListType, class ListListType>
87  static void setSizeAndValuesToListList
88  (
89  ListType& offsets,
90  ListType& m,
91  const ListListType& ll
92  );
93 
94 
95  // Constructors
96 
97  //- Null constructor.
98  inline UCompactListList();
99 
100  //- Construct from components
101  inline UCompactListList(const UList<label>& offsets, const UList<T>& m);
102 
103 
104  // Member Functions
105 
106  // Access
107 
108  //- Return the primary size, i.e. the number of rows
109  inline label size() const;
110 
111  //- Return true if the number of rows is zero
112  inline bool empty() const;
113 
114  //- Return the offset table (= size()+1)
115  inline const UList<label>& offsets() const;
116 
117  //- Return non-const access to the offset table
118  inline UList<label>& offsets();
119 
120  //- Return the packed matrix of data
121  inline const UList<T>& m() const;
122 
123  //- Return non-const access to the packed matrix of data
124  inline UList<T>& m();
125 
126 
127  //- Copy the ULists, but not the underlying data
128  inline void shallowCopy(const UCompactListList<T>&);
129 
130  //- Copy the underlying data
131  inline void deepCopy(const UCompactListList<T>&);
132 
133  //- Return index into m
134  inline label index(const label row, const label col) const;
135 
136  //- Get row for index into m.
137  inline label whichRow(const label index) const;
138 
139  //- Get column index (j) given above row
140  inline label whichColumn(const label row, const label index) const;
141 
142  //- Return sizes (to be used e.g. for construction)
143  labelList sizes() const;
144 
145  //- Convert to List<Container>
146  template<class Container = List<T>>
147  List<Container> list() const;
148 
149 
150  // Member Operators
151 
152  //- Return subscript-checked row as UList.
153  inline UList<T> operator[](const label i);
154 
155  //- Return const subscript-checked row as UList.
156  inline const UList<T> operator[](const label i) const;
157 
158  //- Return subscript-checked element.
159  inline T& operator()(const label i, const label j);
160 
161  //- Return const subscript-checked element.
162  inline const T& operator()(const label i, const label j) const;
163 
164  //- Assignment of all entries to the given value
165  inline void operator=(const T&);
166 
167 
168  // Istream operator
169 
170  // Write UCompactListList to Ostream.
171  friend Ostream& operator<< <T>
172  (
173  Ostream&,
174  const UCompactListList<T>&
175  );
176 };
177 
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 } // End namespace Foam
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 #include "UCompactListListI.H"
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 #ifdef NoRepository
190  #include "UCompactListList.C"
191 #endif
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #endif
196 
197 // ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Unallocated base class of CompactListList.
List< Container > list() const
Convert to List<Container>
const UList< label > & offsets() const
Return the offset table (= size()+1)
const UList< T > & m() const
Return the packed matrix of data.
label size() const
Return the primary size, i.e. the number of rows.
label index(const label row, const label col) const
Return index into m.
bool empty() const
Return true if the number of rows is zero.
T & operator()(const label i, const label j)
Return subscript-checked element.
void operator=(const T &)
Assignment of all entries to the given value.
static void setSizeToListList(ListType &offsets, ListType &m, const ListListType &ll)
Set the sizes to match that of the given list-list.
label whichRow(const label index) const
Get row for index into m.
static void setSizeAndValuesToListList(ListType &offsets, ListType &m, const ListListType &ll)
Set the sizes and values to match that of the given list-list.
labelList sizes() const
Return sizes (to be used e.g. for construction)
UCompactListList()
Null constructor.
label whichColumn(const label row, const label index) const
Get column index (j) given above row.
void shallowCopy(const UCompactListList< T > &)
Copy the ULists, but not the underlying data.
void deepCopy(const UCompactListList< T > &)
Copy the underlying data.
UList< T > operator[](const label i)
Return subscript-checked row as UList.
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & operator<<(Ostream &, const ensightPart &)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)