FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

CompactListList_devI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <OpenFOAM/ListOps.H>
00027 #include <OpenFOAM/SubList.H>
00028 
00029 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00030 
00031 template<class T, class Container>
00032 inline Foam::CompactListList_dev<T, Container>::CompactListList_dev()
00033 :
00034     size_(0)
00035 {}
00036 
00037 
00038 template<class T, class Container>
00039 inline Foam::CompactListList_dev<T, Container>::CompactListList_dev
00040 (
00041     const label nRows,
00042     const label nData
00043 )
00044 :
00045     size_(nRows),
00046     offsets_(nRows+1, 0),
00047     m_(nData)
00048 {}
00049 
00050 
00051 template<class T, class Container>
00052 inline Foam::CompactListList_dev<T, Container>::CompactListList_dev
00053 (
00054     const label nRows,
00055     const label nData,
00056     const T& t
00057 )
00058 :
00059     size_(nRows),
00060     offsets_(nRows+1, 0),
00061     m_(nData, t)
00062 {}
00063 
00064 
00065 template<class T, class Container>
00066 inline Foam::autoPtr<Foam::CompactListList_dev<T, Container> >
00067 Foam::CompactListList_dev<T, Container>::clone() const
00068 {
00069     return autoPtr<CompactListList_dev<T, Container> >
00070     (
00071         new CompactListList_dev<T, Container>(*this)
00072     );
00073 }
00074 
00075 
00076 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00077 
00078 template<class T, class Container>
00079 inline const Foam::CompactListList_dev<T, Container>&
00080 Foam::CompactListList_dev<T, Container>::null()
00081 {
00082     return *reinterpret_cast< CompactListList_dev<T, Container>* >(0);
00083 }
00084 
00085 
00086 template<class T, class Container>
00087 inline Foam::label Foam::CompactListList_dev<T, Container>::size() const
00088 {
00089     return size_;
00090 }
00091 
00092 
00093 template<class T, class Container>
00094 inline bool Foam::CompactListList_dev<T, Container>::empty() const
00095 {
00096     return !size_;
00097 }
00098 
00099 
00100 template<class T, class Container>
00101 inline const Foam::List<Foam::label>&
00102 Foam::CompactListList_dev<T, Container>::offsets() const
00103 {
00104     return offsets_;
00105 }
00106 
00107 
00108 template<class T, class Container>
00109 inline Foam::List<Foam::label>& Foam::CompactListList_dev<T, Container>::offsets()
00110 {
00111     return offsets_;
00112 }
00113 
00114 
00115 template<class T, class Container>
00116 inline const Foam::List<T>& Foam::CompactListList_dev<T, Container>::m()
00117 const
00118 {
00119     return m_;
00120 }
00121 
00122 
00123 template<class T, class Container>
00124 inline Foam::List<T>& Foam::CompactListList_dev<T, Container>::m()
00125 {
00126     return m_;
00127 }
00128 
00129 
00130 template<class T, class Container>
00131 inline Foam::label Foam::CompactListList_dev<T, Container>::index
00132 (
00133     const label i,
00134     const label j
00135 ) const
00136 {
00137     return offsets_[i] + j;
00138 }
00139 
00140 
00141 template<class T, class Container>
00142 inline Foam::label Foam::CompactListList_dev<T, Container>::whichRow(const label i)
00143 const
00144 {
00145     if (i < 0 || i >= m_.size())
00146     {
00147         FatalErrorIn
00148         (
00149             "CompactListList_dev<T, Container>::whichRow(const label) const"
00150         )   << "Index " << i << " outside 0.." << m_.size()
00151             << abort(FatalError);
00152     }
00153 
00154     return findLower(offsets_, i+1);
00155 }
00156 
00157 
00158 template<class T, class Container>
00159 inline Foam::label Foam::CompactListList_dev<T, Container>::whichColumn
00160 (
00161     const label row,
00162     const label i
00163 ) const
00164 {
00165     return i - index(row, 0);
00166 }
00167 
00168 
00169 template<class T, class Container>
00170 inline Foam::Xfer<Foam::CompactListList_dev<T, Container> >
00171 Foam::CompactListList_dev<T, Container>::xfer()
00172 {
00173     return xferMove(*this);
00174 }
00175 
00176 
00177 template<class T, class Container>
00178 inline void Foam::CompactListList_dev<T, Container>::resize(const label nRows)
00179 {
00180     this->setSize(nRows);
00181 }
00182 
00183 
00184 template<class T, class Container>
00185 inline void Foam::CompactListList_dev<T, Container>::resize
00186 (
00187     const label nRows,
00188     const label nData
00189 )
00190 {
00191     this->setSize(nRows, nData);
00192 }
00193 
00194 
00195 template<class T, class Container>
00196 inline void Foam::CompactListList_dev<T, Container>::resize
00197 (
00198     const label nRows,
00199     const label nData,
00200     const T& t
00201 )
00202 {
00203     this->setSize(nRows, nData, t);
00204 }
00205 
00206 
00207 template<class T, class Container>
00208 inline void Foam::CompactListList_dev<T, Container>::resize
00209 (
00210     const UList<label>& rowSizes
00211 )
00212 {
00213     this->setSize(rowSizes);
00214 }
00215 
00216 
00217 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00218 
00219 template<class T, class Container>
00220 inline Foam::UList<T> Foam::CompactListList_dev<T, Container>::operator[]
00221 (
00222     const label i
00223 )
00224 {
00225     label start = offsets_[i];
00226     return UList<T>((m_.size() ? &m_[start] : NULL), offsets_[i+1] - start);
00227 }
00228 
00229 
00230 template<class T, class Container>
00231 inline const Foam::UList<T>
00232 Foam::CompactListList_dev<T, Container>::operator[]
00233 (
00234     const label i
00235 ) const
00236 {
00237     label start = offsets_[i];
00238     return UList<T>
00239     (
00240         (m_.size() ? const_cast<T*>(&m_[start]) : NULL),
00241         offsets_[i+1] - start
00242     );
00243 }
00244 
00245 
00246 template<class T, class Container>
00247 inline T& Foam::CompactListList_dev<T, Container>::operator()
00248 (
00249     const label i,
00250     const label j
00251 )
00252 {
00253     return m_[index(i, j)];
00254 }
00255 
00256 
00257 template<class T, class Container>
00258 inline const T& Foam::CompactListList_dev<T, Container>::operator()
00259 (
00260     const label i,
00261     const label j
00262 ) const
00263 {
00264     return m_[index(i, j)];
00265 }
00266 
00267 
00268 template<class T, class Container>
00269 inline void Foam::CompactListList_dev<T, Container>::operator=(const T& t)
00270 {
00271     m_ = t;
00272 }
00273 
00274 
00275 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines