FreeFOAM The Cross-Platform CFD Toolkit
IndirectListI.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>& completeList,
32  const UList<label>& addr
33 )
34 :
35  completeList_(const_cast<UList<T>&>(completeList)),
36  addressing_(addr)
37 {}
38 
39 
40 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
41 
42 template<class T>
43 inline Foam::label Foam::IndirectList<T>::size() const
44 {
45  return addressing_.size();
46 }
47 
48 
49 template<class T>
50 inline bool Foam::IndirectList<T>::empty() const
51 {
52  return addressing_.empty();
53 }
54 
55 
56 template<class T>
58 {
59  return completeList_;
60 }
61 
62 
63 template<class T>
65 {
66  return addressing_;
67 }
68 
69 
70 template<class T>
72 (
73  const UList<label>& addr
74 )
75 {
76  addressing_ = addr;
77 }
78 
79 
80 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
81 
82 template<class T>
84 {
85  List<T> result(size());
86 
87  forAll(*this, i)
88  {
89  result[i] = operator[](i);
90  }
91 
92  return result;
93 }
94 
95 
96 template<class T>
97 inline T& Foam::IndirectList<T>::operator[](const label i)
98 {
99  return completeList_[addressing_[i]];
100 }
101 
102 
103 template<class T>
104 inline const T& Foam::IndirectList<T>::operator[](const label i) const
105 {
106  return completeList_[addressing_[i]];
107 }
108 
109 
110 template<class T>
112 {
113  if (addressing_.size() != ae.size())
114  {
115  FatalErrorIn("IndirectList<T>::operator=(const UList<T>&)")
116  << "Addressing and list of addressed elements "
117  "have different sizes: "
118  << addressing_.size() << " " << ae.size()
119  << abort(FatalError);
120  }
121 
122  forAll(addressing_, i)
123  {
124  completeList_[addressing_[i]] = ae[i];
125  }
126 }
127 
128 
129 template<class T>
130 inline void Foam::IndirectList<T>::operator=(const T& t)
131 {
132  forAll(addressing_, i)
133  {
134  completeList_[addressing_[i]] = t;
135  }
136 }
137 
138 
139 // ************************ vim: set sw=4 sts=4 et: ************************ //