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

CompactListList_dev.C

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 "CompactListList_dev.H"
00027 
00028 // * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * * //
00029 
00030 template<class T, class Container>
00031 Foam::CompactListList_dev<T, Container>::CompactListList_dev(const List<Container>& ll)
00032 :
00033     size_(ll.size()),
00034     offsets_(ll.size()+1)
00035 {
00036     label sumSize = 0;
00037     offsets_[0] = 0;
00038     forAll(ll, i)
00039     {
00040         sumSize += ll[i].size();
00041         offsets_[i+1] = sumSize;
00042     }
00043 
00044     m_.setSize(sumSize);
00045 
00046     label k = 0;
00047     forAll(ll, i)
00048     {
00049         const Container& lli = ll[i];
00050 
00051         forAll(lli, j)
00052         {
00053             m_[k++] = lli[j];
00054         }
00055     }
00056 }
00057 
00058 
00059 template<class T, class Container>
00060 Foam::CompactListList_dev<T, Container>::CompactListList_dev
00061 (
00062     const UList<label>& rowSizes
00063 )
00064 :
00065     size_(rowSizes.size()),
00066     offsets_(rowSizes.size()+1)
00067 {
00068     label sumSize = 0;
00069     offsets_[0] = 0;
00070     forAll(rowSizes, i)
00071     {
00072         sumSize += rowSizes[i];
00073         offsets_[i+1] = sumSize;
00074     }
00075 
00076     m_.setSize(sumSize);
00077 }
00078 
00079 
00080 template<class T, class Container>
00081 Foam::CompactListList_dev<T, Container>::CompactListList_dev
00082 (
00083     const UList<label>& rowSizes,
00084     const T& t
00085 )
00086 :
00087     size_(rowSizes.size()),
00088     offsets_(rowSizes.size()+1)
00089 {
00090     label sumSize = 0;
00091     offsets_[0] = 0;
00092     forAll(rowSizes, i)
00093     {
00094         sumSize += rowSizes[i];
00095         offsets_[i+1] = sumSize;
00096     }
00097 
00098     m_.setSize(sumSize, t);
00099 }
00100 
00101 
00102 template<class T, class Container>
00103 Foam::CompactListList_dev<T, Container>::CompactListList_dev
00104 (
00105     const Xfer<CompactListList_dev<T, Container> >& lst
00106 )
00107 {
00108     transfer(lst());
00109 }
00110 
00111 
00112 template<class T, class Container>
00113 Foam::CompactListList_dev<T, Container>::CompactListList_dev
00114 (
00115     CompactListList_dev<T, Container>& lst,
00116     bool reUse
00117 )
00118 :
00119     size_(lst.size()),
00120     offsets_(lst.offsets_, reUse),
00121     m_(lst.m_, reUse)
00122 {}
00123 
00124 
00125 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00126 
00127 template<class T, class Container>
00128 void Foam::CompactListList_dev<T, Container>::setSize(const label nRows)
00129 {
00130     if (nRows == 0)
00131     {
00132         clear();
00133     }
00134     if (nRows < size())
00135     {
00136         size_ = nRows;
00137         offsets_.setSize(nRows+1);
00138         m_.setSize(offsets_[nRows]);
00139     }
00140     else if (nRows > size())
00141     {
00142         FatalErrorIn
00143         (
00144             "CompactListList_dev<T, Container>::setSize(const label nRows)"
00145         )   << "Cannot be used to extend the list from " << offsets_.size()
00146             << " to " << nRows << nl
00147             << "    Please use one of the other setSize member functions"
00148             << abort(FatalError);
00149     }
00150 }
00151 
00152 
00153 template<class T, class Container>
00154 void Foam::CompactListList_dev<T, Container>::setSize
00155 (
00156     const label nRows,
00157     const label nData
00158 )
00159 {
00160     size_ = nRows;
00161     offsets_.setSize(nRows+1);
00162     m_.setSize(nData);
00163 }
00164 
00165 
00166 template<class T, class Container>
00167 void Foam::CompactListList_dev<T, Container>::setSize
00168 (
00169     const label nRows,
00170     const label nData,
00171     const T& t
00172 )
00173 {
00174     size_ = nRows;
00175     offsets_.setSize(nRows+1);
00176     m_.setSize(nData, t);
00177 }
00178 
00179 
00180 template<class T, class Container>
00181 void Foam::CompactListList_dev<T, Container>::setSize(const UList<label>& rowSizes)
00182 {
00183     size_ = rowSizes.size();
00184     offsets_.setSize(rowSizes.size()+1);
00185 
00186     label sumSize = 0;
00187     offsets_[0] = 0;
00188     forAll(rowSizes, i)
00189     {
00190         sumSize += rowSizes[i];
00191         offsets_[i+1] = sumSize;
00192     }
00193 
00194     m_.setSize(sumSize);
00195 }
00196 
00197 
00198 template<class T, class Container>
00199 Foam::labelList Foam::CompactListList_dev<T, Container>::sizes() const
00200 {
00201     labelList rowSizes(size());
00202 
00203     if (rowSizes.size() > 0)
00204     {
00205         forAll(rowSizes, i)
00206         {
00207             rowSizes[i] = offsets_[i+1] - offsets_[i];
00208         }
00209     }
00210     return rowSizes;
00211 }
00212 
00213 
00214 template<class T, class Container>
00215 void Foam::CompactListList_dev<T, Container>::clear()
00216 {
00217     size_ = 0;
00218     offsets_.clear();
00219     m_.clear();
00220 }
00221 
00222 
00223 template<class T, class Container>
00224 void Foam::CompactListList_dev<T, Container>::transfer
00225 (
00226     CompactListList_dev<T, Container>& a
00227 )
00228 {
00229     size_ = a.size_;
00230     offsets_.transfer(a.offsets_);
00231     m_.transfer(a.m_);
00232 }
00233 
00234 
00235 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00236 
00237 template<class T, class Container>
00238 Foam::List<Container> Foam::CompactListList_dev<T, Container>::operator()()
00239 const
00240 {
00241     List<Container> ll(size());
00242 
00243     forAll(ll, i)
00244     {
00245         ll[i] = Container(operator[](i));
00246     }
00247 
00248     return ll;
00249 }
00250 
00251 
00252 // * * * * * * * * * * * * * * * *  IOStream operators * * * * * * * * * * * //
00253 
00254 #include "CompactListList_devIO.C"
00255 
00256 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines