BiIndirectList.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 Class
28  Foam::BiIndirectList
29 
30 Description
31  Indexes into negList (negative index) or posList (zero or positive index).
32 
33 SourceFiles
34  BiIndirectListI.H
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_BiIndirectList_H
39 #define Foam_BiIndirectList_H
40 
41 #include "List.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class BiIndirectList Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 template<class T>
53 class BiIndirectList
54 {
55  // Private Data
56 
57  UList<T>& posList_;
58  UList<T>& negList_;
59 
60  labelList addr_;
61 
62 public:
63 
64  // Constructors
65 
66  //- Construct given the complete lists and the addressing array
67  inline BiIndirectList
68  (
69  const UList<T>& posList,
70  const UList<T>& negList,
71  const labelUList& addr
72  );
73 
74  //- Construct given the complete list and by transferring addressing
75  inline BiIndirectList
76  (
77  const UList<T>& posList,
78  const UList<T>& negList,
79  labelList&& addr
80  );
81 
82 
83  // Member Functions
84 
85  // Access
86 
87  //- True if the list is empty (ie, size() is zero).
88  bool empty() const noexcept { return addr_.empty(); }
89 
90  //- The number of elements in the list
91  label size() const noexcept { return addr_.size(); }
92 
93  //- The list of positive values (without addressing)
94  const UList<T>& posList() const noexcept { return posList_; }
95 
96  //- The list of negative values (without addressing)
97  const UList<T>& negList() const noexcept { return negList_; }
98 
99  //- The addressing used for the list
100  const labelList& addressing() const noexcept { return addr_; }
101 
102  //- Calculate index given whether index is into posList or negList
103  static label posIndex(const label i) noexcept { return i; }
104  static label negIndex(const label i) noexcept { return (-i-1); }
105 
106 
107  // Edit
108 
109  //- Copy reset addressing
110  inline void resetAddressing(const labelUList& addr);
111 
112  //- Move reset addressing
113  inline void resetAddressing(labelList&& addr);
115  //- Return the addressed elements as a List
116  inline List<T> list() const;
117 
118 
119  // Member Operators
120 
121  //- Return the addressed elements as a List
122  List<T> operator()() const { return this->list(); }
123 
124  //- Return non-const access to an element
125  inline T& operator[](const label i);
126 
127  //- Return const access to an element
128  inline const T& operator[](const label i) const;
129 
130  //- Assignment to UList of addressed elements
131  inline void operator=(const UList<T>& ae);
132 
133  //- Assignment of all entries to the given value
134  inline void operator=(const T& val);
135 };
136 
137 
138 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
139 
140 } // End namespace Foam
142 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
143 
144 #include "BiIndirectListI.H"
145 
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 
148 #endif
149 
150 // ************************************************************************* //
const UList< T > & negList() const noexcept
The list of negative values (without addressing)
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
T & operator[](const label i)
Return non-const access to an element.
const UList< T > & posList() const noexcept
The list of positive values (without addressing)
void operator=(const UList< T > &ae)
Assignment to UList of addressed elements.
static label negIndex(const label i) noexcept
List< T > operator()() const
Return the addressed elements as a List.
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 direction noexcept
Definition: Scalar.H:258
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Indexes into negList (negative index) or posList (zero or positive index).
List< T > list() const
Return the addressed elements as a List.
static label posIndex(const label i) noexcept
Calculate index given whether index is into posList or negList.
BiIndirectList(const UList< T > &posList, const UList< T > &negList, const labelUList &addr)
Construct given the complete lists and the addressing array.
bool empty() const noexcept
True if the list is empty (ie, size() is zero).
const labelList & addressing() const noexcept
The addressing used for the list.
label size() const noexcept
The number of elements in the list.
void resetAddressing(const labelUList &addr)
Copy reset addressing.
Namespace for OpenFOAM.