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

CompactListList.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 Class
00025     Foam::CompactListList
00026 
00027 Description
00028     A packed storage unstructured matrix of objects of type <T>
00029     using an offset table for access.
00030 
00031     The offset table is the size of the number of rows whose elements are the
00032     accumulated sizes of the rows, i.e.
00033       - offset[i] gives the index of first element of row i + 1
00034       - offset[i] - offset[i-1] is the number of elements in row i
00035 
00036     and for i = 0, offset[i-1] = 0.
00037 
00038     Storage is allocated on free-store during construction.
00039 
00040 SourceFiles
00041     CompactListList.C
00042     CompactListListI.H
00043     CompactListListIO.C
00044 
00045 \*---------------------------------------------------------------------------*/
00046 
00047 #ifndef CompactListList_H
00048 #define CompactListList_H
00049 
00050 #include <OpenFOAM/labelList.H>
00051 
00052 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00053 
00054 namespace Foam
00055 {
00056 
00057 // Forward declaration of friend functions and operators
00058 
00059 template<class T> class CompactListList;
00060 
00061 template<class T> Istream& operator>>(Istream&, CompactListList<T>&);
00062 template<class T> Ostream& operator<<(Ostream&, const CompactListList<T>&);
00063 
00064 
00065 /*---------------------------------------------------------------------------*\
00066                        Class CompactListList Declaration
00067 \*---------------------------------------------------------------------------*/
00068 
00069 template<class T>
00070 class CompactListList
00071 {
00072     // Private data
00073 
00074         //- Offset table
00075         List<label> offsets_;
00076 
00077         //- Packed matrix of data
00078         List<T> m_;
00079 
00080 
00081 public:
00082 
00083     // Static Member Functions
00084 
00085         //- Return a null CompactListList
00086         inline static const CompactListList<T>& null();
00087 
00088     // Constructors
00089 
00090         //- Null constructor.
00091         inline CompactListList();
00092 
00093         //- Construct by converting given List<List<T> >
00094         CompactListList(const List<List<T> >&);
00095 
00096         //- Construct given size of offset table (number of rows)
00097         //  and number of data.
00098         inline CompactListList(const label nRows, const label nData);
00099 
00100         //- Construct given size of offset table (number of rows),
00101         //  the number of data and a value for all elements.
00102         inline CompactListList(const label nRows, const label nData, const T&);
00103 
00104         //- Construct given list of row-sizes.
00105         CompactListList(const UList<label>& rowSizes);
00106 
00107         //- Construct given list of row-sizes
00108         CompactListList(const UList<label>& rowSizes, const T&);
00109 
00110         //- Construct by transferring the parameter contents
00111         CompactListList(const Xfer<CompactListList<T> >&);
00112 
00113         //- Construct as copy or re-use as specified.
00114         CompactListList(CompactListList<T>&, bool reUse);
00115 
00116         //- Construct from Istream.
00117         CompactListList(Istream&);
00118 
00119         //- Clone
00120         inline autoPtr<CompactListList<T> > clone() const;
00121 
00122 
00123     // Member Functions
00124 
00125         // Access
00126 
00127             //- Return the primary size, i.e. the number of rows
00128             inline label size() const;
00129 
00130             //- Return true if the number of rows is zero
00131             inline bool empty() const;
00132 
00133             //- Return the offset table
00134             inline const List<label>& offsets() const;
00135 
00136             //- Return non-const access to the offset table
00137             inline List<label>& offsets();
00138 
00139             //- Return the packed matrix of data
00140             inline const List<T>& m() const;
00141 
00142             //- Return non-const access to the packed matrix of data
00143             inline List<T>& m();
00144 
00145 
00146         // Edit
00147 
00148             //- Reset size of CompactListList.
00149             //  This form only allows contraction of the CompactListList.
00150             void setSize(const label nRows);
00151 
00152             //- Reset size of CompactListList.
00153             void setSize(const label nRows, const label nData);
00154 
00155             //- Reset sizes of CompactListList and value for new elements.
00156             void setSize(const label nRows, const label nData, const T&);
00157 
00158             //- Reset size of CompactListList.
00159             void setSize(const UList<label>& rowSizes);
00160 
00161             //- Reset size of CompactListList.
00162             //  This form only allows contraction of the CompactListList.
00163             inline void resize(const label nRows);
00164 
00165             //- Reset size of CompactListList.
00166             inline void resize(const label nRows, const label nData);
00167 
00168             //- Reset sizes of CompactListList and value for new elements.
00169             inline void resize(const label nRows, const label nData, const T&);
00170 
00171             //- Reset size of CompactListList.
00172             inline void resize(const UList<label>& rowSizes);
00173 
00174             //- Clear the CompactListList, i.e. set sizes to zero.
00175             void clear();
00176 
00177             //- Return sizes (to be used e.g. for construction)
00178             labelList sizes() const;
00179 
00180             //- Transfer the contents of the argument CompactListList
00181             //  into this CompactListList and annull the argument list.
00182             void transfer(CompactListList<T>&);
00183 
00184             //- Transfer the contents to the Xfer container
00185             inline Xfer<CompactListList<T> > xfer();
00186 
00187         // Other
00188 
00189             //- Return index into m
00190             inline label index(const label row, const label col) const;
00191 
00192             //- Get row for index into m.
00193             inline label whichRow(const label index) const;
00194 
00195             //- Get column index (j) given above row
00196             inline label whichColumn(const label row, const label index) const;
00197 
00198 
00199     // Member operators
00200 
00201         //- Return subscript-checked row as UList.
00202         inline UList<T> operator[](const label i);
00203 
00204         //- Return const subscript-checked row as UList.
00205         inline const UList<T> operator[](const label i) const;
00206 
00207         //- Return subscript-checked element.
00208         inline T& operator()(const label i, const label j);
00209 
00210         //- Return const subscript-checked element.
00211         inline const T& operator()(const label i, const label j) const;
00212 
00213         //- Return as List<List<T> >
00214         List<List<T> > operator()() const;
00215 
00216         //- Assignment of all entries to the given value
00217         inline void operator=(const T&);
00218 
00219 
00220     // Istream operator
00221 
00222         //- Read CompactListList from Istream, discarding contents
00223         //  of existing CompactListList.
00224         friend Istream& operator>> <T>(Istream&, CompactListList<T>&);
00225 
00226         // Write CompactListList to Ostream.
00227         friend Ostream& operator<< <T>(Ostream&, const CompactListList<T>&);
00228 };
00229 
00230 
00231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00232 
00233 } // End namespace Foam
00234 
00235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00236 
00237 #   include <OpenFOAM/CompactListListI.H>
00238 
00239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00240 
00241 #ifdef NoRepository
00242 #   include <OpenFOAM/CompactListList.C>
00243 #endif
00244 
00245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00246 
00247 #endif
00248 
00249 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines