BiIndirectListI.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-2016 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 \*---------------------------------------------------------------------------*/
25 
26 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
27 
28 template<class T>
30 (
31  const UList<T>& posList,
32  const UList<T>& negList,
33  const labelUList& addr
34 )
35 :
36  posList_(const_cast<UList<T>&>(posList)),
37  negList_(const_cast<UList<T>&>(negList)),
38  addressing_(addr)
39 {}
40 
41 
42 template<class T>
44 (
45  const UList<T>& posList,
46  const UList<T>& negList,
47  const Xfer<List<label>>& addr
48 )
49 :
50  posList_(const_cast<UList<T>&>(posList)),
51  negList_(const_cast<UList<T>&>(negList)),
52  addressing_(addr)
53 {}
54 
55 
56 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57 
58 template<class T>
60 {
61  return addressing_.size();
62 }
63 
64 
65 template<class T>
66 inline bool Foam::BiIndirectList<T>::empty() const
67 {
68  return addressing_.empty();
69 }
70 
71 
72 template<class T>
74 {
75  return posList_;
76 }
77 
78 
79 template<class T>
81 {
82  return negList_;
83 }
84 
85 
86 template<class T>
88  const
89 {
90  return addressing_;
91 }
92 
93 
94 template<class T>
96 (
97  const labelUList& addr
98 )
99 {
100  addressing_ = addr;
101 }
102 
103 
104 template<class T>
106 (
107  const Xfer<List<label>>& addr
108 )
109 {
110  addressing_.transfer(addr());
111 }
112 
113 
114 template<class T>
116 {
117  return i;
118 }
119 
120 
121 template<class T>
123 {
124  return -i-1;
125 }
126 
127 
128 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
129 
130 template<class T>
132 {
133  List<T> result(size());
134 
135  forAll(*this, i)
136  {
137  result[i] = operator[](i);
138  }
139 
140  return result;
141 }
142 
143 
144 template<class T>
146 {
147  label index = addressing_[i];
148 
149  if (index >= 0)
150  {
151  return posList_[index];
152  }
153  else
154  {
155  return negList_[-index-1];
156  }
157 }
158 
159 
160 template<class T>
161 inline const T& Foam::BiIndirectList<T>::operator[](const label i) const
162 {
163  label index = addressing_[i];
164 
165  if (index >= 0)
166  {
167  return posList_[index];
168  }
169  else
170  {
171  return negList_[-index-1];
172  }
173 }
174 
175 
176 template<class T>
178 {
179  if (addressing_.size() != ae.size())
180  {
182  << "Addressing and list of addressed elements "
183  "have different sizes: "
184  << addressing_.size() << " " << ae.size()
185  << abort(FatalError);
186  }
187 
188  forAll(addressing_, i)
189  {
190  operator[](i) = ae[i];
191  }
192 }
193 
194 
195 template<class T>
197 {
198  forAll(addressing_, i)
199  {
200  operator[](i) = t;
201  }
202 }
203 
204 
205 // ************************************************************************* //
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
BiIndirectList(const UList< T > &posList, const UList< T > &negList, const labelUList &)
Construct given the complete lists and the addressing array.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
const UList< T > & posList() const
static label negIndex(const label)
bool empty() const
Return true if the list is empty (ie, size() is zero).
T & operator[](const label)
Return non-const access to an element.
static label posIndex(const label)
Calculate index given whether index is into posList or negList.
void resetAddressing(const labelUList &)
Reset addressing.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
void operator=(const UList< T > &)
Assignment from UList of addressed elements.
const volScalarField & T
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299
List< T > operator()() const
Return the addressed elements as a List.
label size() const
Return the number of elements in the list.
const List< label > & addressing() const
Return the list addressing.
const UList< T > & negList() const