OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

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