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-2019 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 complete list
102  inline const UList<T>& completeList() const;
103 
104  //- Return the list addressing
105  inline const List<label>& addressing() const;
106 
107 
108  // Member Operators
109 
110  //- Return the addressed elements as a List
111  inline List<T> operator()() const;
112 
113  //- Return non-const access to an element
114  inline T& operator[](const label);
115 
116  //- Return const access to an element
117  inline const T& operator[](const label) const;
118 
119  //- Assignment to UList of addressed elements
120  inline void operator=(const UList<T>&);
121 
122  //- Assignment to UIndirectList of addressed elements
123  inline void operator=(const UIndirectList<T>&);
124 
125  //- Assignment of all entries to the given value
126  inline void operator=(const T&);
127 
128 
129  // STL type definitions
130 
131  //- Type of values the UList contains.
132  typedef T value_type;
133 
134  //- Type that can be used for storing into
135  // UList::value_type objects.
136  typedef T& reference;
137 
138  //- Type that can be used for storing into
139  // constant UList::value_type objects
140  typedef const T& const_reference;
141 
142  //- The type that can represent the difference between any two
143  // UList iterator objects.
144  typedef label difference_type;
145 
146  //- The type that can represent the size of a UList.
147  typedef label size_type;
148 
149 
150  // Ostream operator
151 
152  //- Write UIndirectList to Ostream
153  // Binary output is currently still a bit of a problem
154  friend Ostream& operator<< <T>
155  (
156  Ostream&,
157  const UIndirectList<T>&
158  );
159 };
160 
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 } // End namespace Foam
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 #include "UIndirectListI.H"
169 
170 #ifdef NoRepository
171  #include "UIndirectListIO.C"
172 #endif
173 
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175 
176 #endif
177 
178 // ************************************************************************* //
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
UList< label > labelUList
Definition: UList.H:65
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:53
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.