UIndirectList.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-2020 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::UIndirectList
26 
27 Description
28  A List with indirect addressing.
29 
30  Like IndirectList but does not store addressing.
31 
32  Note the const_cast of the completeList. This is so we can use it both
33  on const and non-const lists. Alternative would be to have a const_
34  variant etc.
35 
36 SourceFiles
37  UIndirectListI.H
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef UIndirectList_H
42 #define UIndirectList_H
43 
44 #include "List.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 // Forward declaration of friend functions and operators
52 template<class T> class UIndirectList;
53 template<class T> Ostream& operator<<(Ostream&, const UIndirectList<T>&);
54 
55 /*---------------------------------------------------------------------------*\
56  Class UIndirectList Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 template<class T>
60 class UIndirectList
61 {
62  // Private Data
63 
64  UList<T>& completeList_;
65  const labelUList& addressing_;
66 
67 
68 public:
69 
70  // Constructors
71 
72  //- Construct given the complete list and the addressing array
73  inline UIndirectList(const UList<T>&, const labelUList&);
74 
75  //- Copy constructor
76  UIndirectList(const UIndirectList<T>&) = default;
77 
78 
79  // Member Functions
80 
81  // Access
82 
83  //- Return the number of elements in the list
84  inline label size() const;
85 
86  //- Return true if the list is empty (ie, size() is zero).
87  inline bool empty() const;
88 
89  //- Return the first element of the list.
90  inline T& first();
91 
92  //- Return first element of the list.
93  inline const T& first() const;
94 
95  //- Return the last element of the list.
96  inline T& last();
97 
98  //- Return the last element of the list.
99  inline const T& last() const;
100 
101  //- Return the forward circular index, i.e. the next index
102  // which returns to the first at the end of the list
103  inline label fcIndex(const label i) const;
104 
105  //- Return the reverse circular index, i.e. the previous index
106  // which returns to the last at the beginning of the list
107  inline label rcIndex(const label i) const;
108 
109  //- Return the complete list
110  inline const UList<T>& completeList() const;
111 
112  //- Return the list addressing
113  inline const List<label>& addressing() const;
114 
115 
116  // Member Operators
117 
118  //- Return the addressed elements as a List
119  inline List<T> operator()() const;
120 
121  //- Return non-const access to an element
122  inline T& operator[](const label);
123 
124  //- Return const access to an element
125  inline const T& operator[](const label) const;
126 
127  //- Assignment to UList of addressed elements
128  inline void operator=(const UList<T>&);
129 
130  //- Assignment to UIndirectList of addressed elements
131  inline void operator=(const UIndirectList<T>&);
132 
133  //- Assignment of all entries to the given value
134  inline void operator=(const T&);
135 
136 
137  // STL type definitions
138 
139  //- Type of values the UList contains.
140  typedef T value_type;
141 
142  //- Type that can be used for storing into
143  // UList::value_type objects.
144  typedef T& reference;
145 
146  //- Type that can be used for storing into
147  // constant UList::value_type objects
148  typedef const T& const_reference;
149 
150  //- The type that can represent the difference between any two
151  // UList iterator objects.
152  typedef label difference_type;
153 
154  //- The type that can represent the size of a UList.
155  typedef label size_type;
156 
157 
158  // Ostream operator
159 
160  //- Write UIndirectList to Ostream
161  // Binary output is currently still a bit of a problem
162  friend Ostream& operator<< <T>
163  (
164  Ostream&,
165  const UIndirectList<T>&
166  );
167 };
168 
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 } // End namespace Foam
173 
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175 
176 #include "UIndirectListI.H"
177 
178 #ifdef NoRepository
179  #include "UIndirectListIO.C"
180 #endif
181 
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 
184 #endif
185 
186 // ************************************************************************* //
T & reference
Type that can be used for storing into.
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
label fcIndex(const label i) const
Return the forward circular index, i.e. the next index.
UList< label > labelUList
Definition: UList.H:65
label rcIndex(const label i) const
Return the reverse circular index, i.e. the previous index.
label size_type
The type that can represent the size of a UList.
label size() const
Return the number of elements in the list.
const UList< T > & completeList() const
Return the complete list.
List< T > operator()() const
Return the addressed elements as a List.
const T & const_reference
Type that can be used for storing into.
T & last()
Return the last element of the list.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
T value_type
Type of values the UList contains.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
T & first()
Return the first element of the list.
A List with indirect addressing.
Definition: fvMatrix.H:106
void operator=(const UList< T > &)
Assignment to UList of addressed elements.
UIndirectList(const UList< T > &, const labelUList &)
Construct given the complete list and the addressing array.
label difference_type
The type that can represent the difference between any two.
bool empty() const
Return true if the list is empty (ie, size() is zero).
Namespace for OpenFOAM.
T & operator[](const label)
Return non-const access to an element.
const List< label > & addressing() const
Return the list addressing.