Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / OpenFOAM / containers / Lists / UIndirectList / UIndirectListI.H
blob02d5250a504fb3a5208ace7a0c74a34662edb766
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
26 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
28 template<class T>
29 inline Foam::UIndirectList<T>::UIndirectList
31     const UList<T>& completeList,
32     const labelUList& addr
35     completeList_(const_cast<UList<T>&>(completeList)),
36     addressing_(addr)
40 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
42 template<class T>
43 inline Foam::label Foam::UIndirectList<T>::size() const
45     return addressing_.size();
49 template<class T>
50 inline bool Foam::UIndirectList<T>::empty() const
52     return addressing_.empty();
56 template<class T>
57 inline T& Foam::UIndirectList<T>::first()
59     return completeList_[addressing_.first()];
63 template<class T>
64 inline const T& Foam::UIndirectList<T>::first() const
66     return completeList_[addressing_.first()];
70 template<class T>
71 inline T& Foam::UIndirectList<T>::last()
73     return completeList_[addressing_.last()];
77 template<class T>
78 inline const T& Foam::UIndirectList<T>::last() const
80     return completeList_[addressing_.last()];
84 template<class T>
85 inline const Foam::UList<T>& Foam::UIndirectList<T>::completeList() const
87     return completeList_;
91 template<class T>
92 inline const Foam::List<Foam::label>& Foam::UIndirectList<T>::addressing() const
94     return addressing_;
98 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
100 template<class T>
101 inline Foam::List<T> Foam::UIndirectList<T>::operator()() const
103     List<T> result(size());
105     forAll(*this, i)
106     {
107         result[i] = operator[](i);
108     }
110     return result;
114 template<class T>
115 inline T& Foam::UIndirectList<T>::operator[](const label i)
117     return completeList_[addressing_[i]];
121 template<class T>
122 inline const T& Foam::UIndirectList<T>::operator[](const label i) const
124     return completeList_[addressing_[i]];
128 template<class T>
129 inline void Foam::UIndirectList<T>::operator=(const UList<T>& ae)
131     if (addressing_.size() != ae.size())
132     {
133         FatalErrorIn("UIndirectList<T>::operator=(const UList<T>&)")
134             << "Addressing and list of addressed elements "
135                "have different sizes: "
136             << addressing_.size() << " " << ae.size()
137             << abort(FatalError);
138     }
140     forAll(addressing_, i)
141     {
142         completeList_[addressing_[i]] = ae[i];
143     }
147 template<class T>
148 inline void Foam::UIndirectList<T>::operator=(const T& t)
150     forAll(addressing_, i)
151     {
152         completeList_[addressing_[i]] = t;
153     }
157 // ************************************************************************* //