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-2024 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 UList<label>& 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 UList<label>&);
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  //- Equality comparison. Compares element-by-element.
137  inline bool operator==(const UIndirectList<T>&) const;
138 
139  //- Inequality comparison. Compares element-by-element.
140  inline bool operator!=(const UIndirectList<T>&) const;
141 
142 
143  // STL type definitions
144 
145  //- Type of values the UList contains.
146  typedef T value_type;
147 
148  //- Type that can be used for storing into
149  // UList::value_type objects.
150  typedef T& reference;
151 
152  //- Type that can be used for storing into
153  // constant UList::value_type objects
154  typedef const T& const_reference;
155 
156  //- The type that can represent the difference between any two
157  // UList iterator objects.
158  typedef label difference_type;
159 
160  //- The type that can represent the size of a UList.
161  typedef label size_type;
162 
163 
164  // Ostream operator
165 
166  //- Write UIndirectList to Ostream
167  // Binary output is currently still a bit of a problem
168  friend Ostream& operator<< <T>
169  (
170  Ostream&,
171  const UIndirectList<T>&
172  );
173 };
174 
175 
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 
178 } // End namespace Foam
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 #include "UIndirectListI.H"
183 
184 #ifdef NoRepository
185  #include "UIndirectListIO.C"
186 #endif
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 #endif
191 
192 // ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A List with indirect addressing.
Definition: UIndirectList.H:60
label size_type
The type that can represent the size of a UList.
UIndirectList(const UList< T > &, const UList< label > &)
Construct given the complete list and the addressing array.
label difference_type
The type that can represent the difference between any two.
T & first()
Return the first element of the list.
T value_type
Type of values the UList contains.
label rcIndex(const label i) const
Return the reverse circular index, i.e. the previous index.
label size() const
Return the number of elements in the list.
label fcIndex(const label i) const
Return the forward circular index, i.e. the next index.
bool empty() const
Return true if the list is empty (ie, size() is zero).
const UList< T > & completeList() const
Return the complete list.
bool operator==(const UIndirectList< T > &) const
Equality comparison. Compares element-by-element.
T & operator[](const label)
Return non-const access to an element.
T & reference
Type that can be used for storing into.
bool operator!=(const UIndirectList< T > &) const
Inequality comparison. Compares element-by-element.
void operator=(const UList< T > &)
Assignment to UList of addressed elements.
List< T > operator()() const
Return the addressed elements as a List.
T & last()
Return the last element of the list.
const T & const_reference
Type that can be used for storing into.
const List< label > & addressing() const
Return the list addressing.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:74
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
void T(LagrangianPatchField< Type > &f, const LagrangianPatchField< Type > &f1)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)