UIndirectList.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2014 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 
76  // Member Functions
77 
78  // Access
79 
80  //- Return the number of elements in the list
81  inline label size() const;
82 
83  //- Return true if the list is empty (ie, size() is zero).
84  inline bool empty() const;
85 
86  //- Return the first element of the list.
87  inline T& first();
88 
89  //- Return first element of the list.
90  inline const T& first() const;
91 
92  //- Return the last element of the list.
93  inline T& last();
94 
95  //- Return the last element of the list.
96  inline const T& last() const;
97 
98  //- Return the complete list
99  inline const UList<T>& completeList() const;
100 
101  //- Return the list addressing
102  inline const List<label>& addressing() const;
103 
104 
105  // Member Operators
106 
107  //- Return the addressed elements as a List
108  inline List<T> operator()() const;
109 
110  //- Return non-const access to an element
111  inline T& operator[](const label);
112 
113  //- Return const access to an element
114  inline const T& operator[](const label) const;
115 
116  //- Assignment from UList of addressed elements
117  inline void operator=(const UList<T>&);
118 
119  //- Assignment from UIndirectList of addressed elements
120  inline void operator=(const UIndirectList<T>&);
121 
122  //- Assignment of all entries to the given value
123  inline void operator=(const T&);
124 
125 
126  // STL type definitions
127 
128  //- Type of values the UList contains.
129  typedef T value_type;
130 
131  //- Type that can be used for storing into
132  // UList::value_type objects.
133  typedef T& reference;
134 
135  //- Type that can be used for storing into
136  // constant UList::value_type objects
137  typedef const T& const_reference;
138 
139  //- The type that can represent the difference between any two
140  // UList iterator objects.
141  typedef label difference_type;
142 
143  //- The type that can represent the size of a UList.
144  typedef label size_type;
145 
146 
147  // Ostream operator
148 
149  //- Write UIndirectList to Ostream
150  // Binary output is currently still a bit of a problem
151  friend Ostream& operator<< <T>
152  (
153  Ostream&,
154  const UIndirectList<T>&
155  );
156 };
157 
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 } // End namespace Foam
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 #include "UIndirectListI.H"
166 
167 #ifdef NoRepository
168 # include "UIndirectListIO.C"
169 #endif
170 
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 
173 #endif
174 
175 // ************************************************************************* //
T & last()
Return the last element of the list.
UList< label > labelUList
Definition: UList.H:63
bool empty() const
Return true if the list is empty (ie, size() is zero).
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
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
T & operator[](const label)
Return non-const access to an element.
Namespace for OpenFOAM.
label difference_type
The type that can represent the difference between any two.
const UList< T > & completeList() const
Return the complete list.
const List< label > & addressing() const
Return the list addressing.
A List with indirect addressing.
Definition: fvMatrix.H:106
label size() const
Return the number of elements in the list.
label size_type
The type that can represent the size of a UList.
T & first()
Return the first element of the list.
List< T > operator()() const
Return the addressed elements as a List.
const T & const_reference
Type that can be used for storing into.
void operator=(const UList< T > &)
Assignment from UList of addressed elements.
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.
UIndirectList(const UList< T > &, const labelUList &)
Construct given the complete list and the addressing array.
T & reference
Type that can be used for storing into.