Test-xferList.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 Application
25 
26 Description
27 
28 \*---------------------------------------------------------------------------*/
29 
30 #include "OSspecific.H"
31 
32 #include "IOstreams.H"
33 #include "IStringStream.H"
34 #include "labelList.H"
35 #include "DynamicList.H"
36 #include "face.H"
37 
38 using namespace Foam;
39 
40 
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 // Main program:
44 
45 int main(int argc, char *argv[])
46 {
47  List<label> lstA(10);
48  List<label> lstC(IStringStream("(1 2 3 4)")());
49 
50  forAll(lstA, i)
51  {
52  lstA[i] = i;
53  }
54 
55  Info<< "lstA: " << lstA << endl;
56  Info<< "lstC: " << lstC << endl;
57 
58  Xfer<List<label> > xA = xferMove(lstA);
59  Xfer<List<label> > xB;
60 
61  List<label> lstB( xA );
62 
63  Info<< "xA: " << xA() << endl;
64  Info<< "xB: " << xB() << endl;
65  Info<< "lstA: " << lstA << endl;
66  Info<< "lstB: " << lstB << endl;
67  Info<< "lstC: " << lstC << endl;
68 
69  xA = lstB;
70 
71  Info<< "xA: " << xA() << endl;
72  Info<< "xB: " << xB() << endl;
73  Info<< "lstA: " << lstA << endl;
74  Info<< "lstB: " << lstB << endl;
75  Info<< "lstC: " << lstC << endl;
76 
77  xB = xA;
78 
79  List<label> lstD(xferCopy(lstC));
80  List<label> lstE(xferMove(lstC));
81 
82  // this must be empty
83  List<label> lstF = xferCopy(lstC);
84 
85  Info<< "xA: " << xA() << endl;
86  Info<< "xB: " << xB() << endl;
87  Info<< "lstA: " << lstA << endl;
88  Info<< "lstB: " << lstB << endl;
89  Info<< "lstC: " << lstC << endl;
90  Info<< "lstD: " << lstD << endl;
91  Info<< "lstE: " << lstE << endl;
92  Info<< "lstF: " << lstF << endl;
93 
94  Info<< "xB[" << xB->size() << "]\n";
95 
96  // clear the underlying List
97  xB->clear();
98 
99  Info<< "xB[" << xB->size() << "]\n";
100 
101  DynamicList<label> dl(10);
102  for (label i = 0; i < 5; ++i)
103  {
104  dl.append(i);
105  }
106 
107  face f1(dl);
108  face f2(xferCopy<labelList>(dl));
109 
110  Info<< "dl[" << dl.size() << "/" << dl.capacity() << "] " << dl << endl;
111  Info<< "f1: " << f1 << endl;
112  Info<< "f2: " << f2 << endl;
113 
114  // add some more labels
115  for (label i = 5; i < 8; ++i)
116  {
117  dl.append(i);
118  }
119 
120  // note: xfer() method returns a plain labelList
121  face f3(dl.xfer());
122  Info<< "dl[" << dl.size() << "/" << dl.capacity() << "] " << dl << endl;
123  Info<< "f3: " << f3 << endl;
124 
125  Info<<"\nflip faces:" << endl;
126  f1.flip();
127  f3.flip();
128  Info<< "f1: " << f1 << endl;
129  Info<< "f3: " << f3 << endl;
130 
131  return 0;
132 }
133 
134 
135 // ************************************************************************* //
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Foam::DynamicList::xfer
Xfer< List< T > > xfer()
Transfer contents to the Xfer container as a plain List.
Definition: DynamicListI.H:301
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::DynamicList::capacity
label capacity() const
Size of the underlying storage.
Definition: DynamicListI.H:100
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::DynamicList< label >
face.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::Xfer
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
IStringStream.H
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
labelList.H
Foam::Info
messageStream Info
f1
scalar f1
Definition: createFields.H:28
Foam::face::flip
void flip()
Flip the face in-place.
Definition: face.C:474
Foam::IStringStream
Input from memory buffer stream.
Definition: IStringStream.H:49
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::xferMove
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
Foam::xferCopy
Xfer< T > xferCopy(const T &)
Construct by copying the contents of the arg.
Foam::List< label >
main
int main(int argc, char *argv[])
Definition: Test-xferList.C:42
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
DynamicList.H