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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class T>
33 (
34  const UList<T>& posList,
35  const UList<T>& negList,
36  const labelUList& addr
37 )
38 :
39  posList_(const_cast<UList<T>&>(posList)),
40  negList_(const_cast<UList<T>&>(negList)),
41  addr_(addr)
42 {}
43 
44 
45 template<class T>
47 (
48  const UList<T>& posList,
49  const UList<T>& negList,
50  labelList&& addr
51 )
52 :
53  posList_(const_cast<UList<T>&>(posList)),
54  negList_(const_cast<UList<T>&>(negList)),
55  addr_(std::move(addr))
56 {}
57 
58 
59 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
60 
61 template<class T>
63 {
64  addr_ = addr;
65 }
66 
67 
68 template<class T>
70 {
71  addr_.transfer(addr);
72 }
73 
74 
75 template<class T>
77 {
78  List<T> result(size());
79 
80  forAll(*this, i)
81  {
82  result[i] = operator[](i);
83  }
84 
85  return result;
86 }
87 
88 
89 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
90 
91 template<class T>
92 inline T& Foam::BiIndirectList<T>::operator[](const label i)
93 {
94  const label index = addr_[i];
95 
96  return (index >= 0 ? posList_[index] : negList_[-index-1]);
97 }
98 
99 
100 template<class T>
101 inline const T& Foam::BiIndirectList<T>::operator[](const label i) const
102 {
103  const label index = addr_[i];
104 
105  return (index >= 0 ? posList_[index] : negList_[-index-1]);
106 }
107 
108 
109 template<class T>
110 inline void Foam::BiIndirectList<T>::operator=(const UList<T>& ae)
111 {
112  if (addr_.size() != ae.size())
113  {
115  << "Addressing and list of addressed elements "
116  "have different sizes: "
117  << addr_.size() << " " << ae.size()
118  << abort(FatalError);
119  }
120 
121  forAll(addr_, i)
122  {
123  operator[](i) = ae[i];
124  }
125 }
126 
127 
128 template<class T>
129 inline void Foam::BiIndirectList<T>::operator=(const T& val)
130 {
131  forAll(addr_, i)
132  {
133  operator[](i) = val;
134  }
135 }
136 
137 
138 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
T & operator[](const label i)
Return non-const access to an element.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
void operator=(const UList< T > &ae)
Assignment to UList of addressed elements.
errorManip< error > abort(error &err)
Definition: errorManip.H:139
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:105
const volScalarField & T
List< T > list() const
Return the addressed elements as a List.
BiIndirectList(const UList< T > &posList, const UList< T > &negList, const labelUList &addr)
Construct given the complete lists and the addressing array.
void resetAddressing(const labelUList &addr)
Copy reset addressing.