ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / applications / test / CompactListList / Test-CompactListList.C
blob13a73cde7be9e2c9155b9be6990ad01ce69c694f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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 Application
25     CompactListListTest
27 Description
28     Simple demonstration and test application for the CompactListList class.
30 \*---------------------------------------------------------------------------*/
32 #include "CompactListList.H"
33 #include "IOstreams.H"
34 #include "OStringStream.H"
35 #include "IStringStream.H"
36 #include "faceList.H"
38 using namespace Foam;
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 //  Main program:
43 int main(int argc, char *argv[])
45     {
46         // null construct
47         CompactListList<label> cll1;
48         Info<< "cll1:" << cll1 << endl;
50         // Resize and assign row by row
51         labelList row0(2, 0);
52         labelList row1(3, 1);
54         labelList rowSizes(2);
55         rowSizes[0] = row0.size();
56         rowSizes[1] = row1.size();
57         cll1.resize(rowSizes);
59         cll1[0].assign(row0);   //note: operator= will not work since UList
60         cll1[1].assign(row1);
61         Info<< "cll1:" << cll1 << endl;
63         forAll(cll1.m(), i)
64         {
65             Info<< "i:" << i << " whichRow:" << cll1.whichRow(i) << endl;
66         }
67     }
69     List<List<label> > lll(5);
70     lll[0].setSize(3, 0);
71     lll[1].setSize(2, 1);
72     lll[2].setSize(6, 2);
73     lll[3].setSize(0, 3);
74     lll[4].setSize(1, 4);
76     CompactListList<label> cll2(lll);
78     Info<< "cll2  = " << cll2 << endl;
80     forAll(cll2, i)
81     {
82         Info<< cll2[i] << endl;
83     }
85     Info<< endl;
87     Info<< "cll2(2, 3) = " << cll2(2, 3) << nl << endl;
88     cll2(2, 3) = 999;
89     Info<< "cll2(2, 3) = " << cll2(2, 3) << nl << endl;
91     Info<< "cll2 as List<List<label > > " << cll2()
92         << endl;
94     cll2.setSize(3);
96     Info<< "cll2  = " << cll2 << endl;
98     cll2.setSize(0);
100     Info<< "cll2  = " << cll2 << endl;
103     List<label> rowSizes(5);
104     rowSizes[0] = 2;
105     rowSizes[1] = 0;
106     rowSizes[2] = 1;
107     rowSizes[3] = 3;
108     rowSizes[4] = 2;
110     CompactListList<label> cll3(rowSizes, 1);
112     Info<< "cll3 = " << cll3 << endl;
114     CompactListList<label> cll4;
116     cll4.transfer(cll3);
118     Info<< "cll3 = " << cll3 << endl;
119     Info<< "cll4 = " << cll4 << endl;
122     {
123         // IO
124         OStringStream ostr;
125         ostr << cll4;
127         IStringStream istr(ostr.str());
128         CompactListList<label> cll5(istr);
129         Info<< "cll5 = " << cll5 << endl;
130     }
131     {
132         // IO
133         cll4.clear();
134         OStringStream ostr;
135         ostr << cll4;
137         IStringStream istr(ostr.str());
138         CompactListList<label> cll5(istr);
139         Info<< "cll5 = " << cll5 << endl;
140     }
142     {
143         faceList fcs(2);
144         fcs[0] = face(labelList(1, 111));
145         fcs[1] = face(labelList(2, 222));
147         CompactListList<label, face> compactFcs(fcs);
148         Info<< "comactFcs:" << compactFcs << endl;
150         faceList fcs2 = compactFcs();
151         Info<< "fcs2:" << fcs2 << endl;
152     }
154     return 0;
158 // ************************************************************************* //