FreeFOAM The Cross-Platform CFD Toolkit
UIndirectListI.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::UIndirectList<T>::size() const
44 {
45  return addressing_.size();
46 }
47 
48 
49 template<class T>
50 inline bool Foam::UIndirectList<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 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
71 
72 template<class T>
74 {
75  List<T> result(size());
76 
77  forAll(*this, i)
78  {
79  result[i] = operator[](i);
80  }
81 
82  return result;
83 }
84 
85 
86 template<class T>
87 inline T& Foam::UIndirectList<T>::operator[](const label i)
88 {
89  return completeList_[addressing_[i]];
90 }
91 
92 
93 template<class T>
94 inline const T& Foam::UIndirectList<T>::operator[](const label i) const
95 {
96  return completeList_[addressing_[i]];
97 }
98 
99 
100 template<class T>
102 {
103  if (addressing_.size() != ae.size())
104  {
105  FatalErrorIn("UIndirectList<T>::operator=(const UList<T>&)")
106  << "Addressing and list of addressed elements "
107  "have different sizes: "
108  << addressing_.size() << " " << ae.size()
109  << abort(FatalError);
110  }
111 
112  forAll(addressing_, i)
113  {
114  completeList_[addressing_[i]] = ae[i];
115  }
116 }
117 
118 
119 template<class T>
121 {
122  forAll(addressing_, i)
123  {
124  completeList_[addressing_[i]] = t;
125  }
126 }
127 
128 
129 // ************************ vim: set sw=4 sts=4 et: ************************ //