Test-IndirectList.C
Go to the documentation of this file.
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.
10 
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.
15 
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.
20 
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/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "IndirectList.H"
29 #include "IOstreams.H"
30 
31 using namespace Foam;
32 
33 template<class ListType>
34 void printInfo(const ListType& lst)
35 {
36  Info<< "addr: " << lst.addressing() << nl
37  << "list: " << lst << nl
38  << endl;
39 }
40 
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 // Main program:
44 
45 int main(int argc, char *argv[])
46 {
47  List<double> completeList(10);
48 
49  forAll(completeList, i)
50  {
51  completeList[i] = 0.1*i;
52  }
53 
54  Info<< "raw : " << completeList << nl << endl;
55 
56 
57  List<label> addresses(5);
58  addresses[0] = 1;
59  addresses[1] = 0;
60  addresses[2] = 7;
61  addresses[3] = 8;
62  addresses[4] = 5;
63 
64  IndirectList<double> idl1(completeList, addresses);
65 
66  printInfo(idl1);
67 
68  addresses[4] = 1;
69  addresses[3] = 0;
70  addresses[2] = 7;
71  addresses[1] = 8;
72  addresses[0] = 5;
73 
74  idl1.resetAddressing(addresses.xfer());
75 
76  printInfo(idl1);
77 
78  // test copying
79  UIndirectList<double> uidl1(idl1);
80  IndirectList<double> idl2(uidl1);
81  IndirectList<double> idl3(idl2);
82 
83  printInfo(uidl1);
84 
86 // idl2.resetAddressing(List<label>());
87 
88  Info<<"after resetAddressing:" << nl << endl;
89 
90  printInfo(uidl1);
91  printInfo(idl1);
92  printInfo(idl2);
93  printInfo(idl3);
94 
95  Info<< "End\n" << endl;
96 
97  return 0;
98 }
99 
100 
101 // ************************************************************************* //
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::List::xfer
Xfer< List< T > > xfer()
Transfer contents to the Xfer container.
Definition: ListI.H:90
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::IndirectList::resetAddressing
void resetAddressing(const labelUList &)
Reset addressing.
Definition: IndirectListI.H:119
main
int main(int argc, char *argv[])
Definition: Test-IndirectList.C:45
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::IndirectList
A List with indirect addressing.
Definition: IndirectList.H:102
IndirectList.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::UIndirectList
A List with indirect addressing.
Definition: fvMatrix.H:106
printInfo
void printInfo(const ListType &lst)
Definition: Test-IndirectList.C:34