FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 UList<label>& addr
34 )
35 :
36  posList_(const_cast<UList<T>&>(posList)),
37  negList_(const_cast<UList<T>&>(negList)),
38  addressing_(addr)
39 {}
40 
41 
42 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
43 
44 template<class T>
45 inline Foam::label Foam::BiIndirectList<T>::size() const
46 {
47  return addressing_.size();
48 }
49 
50 
51 template<class T>
52 inline bool Foam::BiIndirectList<T>::empty() const
53 {
54  return addressing_.empty();
55 }
56 
57 
58 template<class T>
60 {
61  return posList_;
62 }
63 
64 
65 template<class T>
67 {
68  return negList_;
69 }
70 
71 
72 template<class T>
74  const
75 {
76  return addressing_;
77 }
78 
79 
80 template<class T>
82 {
83  return addressing_;
84 }
85 
86 
87 template<class T>
88 inline Foam::label Foam::BiIndirectList<T>::posIndex(const label i)
89 {
90  return i;
91 }
92 
93 
94 template<class T>
95 inline Foam::label Foam::BiIndirectList<T>::negIndex(const label i)
96 {
97  return -i-1;
98 }
99 
100 
101 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
102 
103 template<class T>
105 {
106  List<T> result(size());
107 
108  forAll(*this, i)
109  {
110  result[i] = operator[](i);
111  }
112 
113  return result;
114 }
115 
116 
117 template<class T>
119 {
120  label index = addressing_[i];
121 
122  if (index >= 0)
123  {
124  return posList_[index];
125  }
126  else
127  {
128  return negList_[-index-1];
129  }
130 }
131 
132 
133 template<class T>
134 inline const T& Foam::BiIndirectList<T>::operator[](const label i) const
135 {
136  label index = addressing_[i];
137 
138  if (index >= 0)
139  {
140  return posList_[index];
141  }
142  else
143  {
144  return negList_[-index-1];
145  }
146 }
147 
148 
149 template<class T>
151 {
152  if (addressing_.size() != ae.size())
153  {
154  FatalErrorIn("BiIndirectList<T>::operator=(const UList<T>&)")
155  << "Addressing and list of addressed elements "
156  "have different sizes: "
157  << addressing_.size() << " " << ae.size()
158  << abort(FatalError);
159  }
160 
161  forAll(addressing_, i)
162  {
163  operator[](i) = ae[i];
164  }
165 }
166 
167 
168 template<class T>
170 {
171  forAll(addressing_, i)
172  {
173  operator[](i) = t;
174  }
175 }
176 
177 
178 // ************************ vim: set sw=4 sts=4 et: ************************ //