Test-SLList.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 "SLList.H"
34 
35 using namespace Foam;
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // Main program:
39 
40 int main(int argc, char *argv[])
41 {
42  SLList<scalar> myList;
43 
44  for (int i = 0; i<10; i++)
45  {
46  myList.append(1.3*i);
47  }
48 
49  myList.append(100.3);
50  myList.append(500.3);
51 
52  Info<< nl << "And again using STL iterator: " << nl << endl;
53 
54  forAllIter(SLList<scalar>, myList, iter)
55  {
56  Info<< "element:" << *iter << endl;
57  }
58 
59  Info<< nl << "And again using STL const_iterator: " << nl << endl;
60 
61  const SLList<scalar>& const_myList = myList;
62 
63  forAllConstIter(SLList<scalar>, const_myList, iter)
64  {
65  Info<< "element:" << *iter << endl;
66  }
67 
68  forAllIter(SLList<scalar>, myList, iter)
69  {
70  Info<< "Removing element:" << *iter << endl;
71  myList.remove(iter);
72  }
73 
74  forAllConstIter(SLList<scalar>, const_myList, iter)
75  {
76  Info<< "element:" << *iter << endl;
77  }
78 
79 
80  for (int i = 0; i<10; i++)
81  {
82  myList.append(1.3*i);
83  }
84 
85  myList.append(100.3);
86  myList.append(500.3);
87 
88  Info<< nl << "Testing transfer: " << nl << endl;
89  Info<< "original: " << myList << endl;
90 
91  SLList<scalar> newList;
92  newList.transfer(myList);
93 
94  Info<< nl << "source: " << myList << nl
95  << nl << "target: " << newList << endl;
96 
97 
98  Info<< nl << "Done." << endl;
99  return 0;
100 }
101 
102 
103 // ************************************************************************* //
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::LList< SLListBase, T >::append
void append(const T &a)
Add at tail of list.
Definition: LList.H:166
forAllIter
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:431
Foam::SLList
Non-intrusive singly-linked list.
Definition: SLList.H:47
main
int main(int argc, char *argv[])
Definition: Test-SLList.C:37
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::LList< SLListBase, T >::remove
T remove(link *l)
Remove and return element.
Definition: LList.H:181
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
SLList.H
Foam::LList< SLListBase, T >::transfer
void transfer(LList< LListBase, T > &)
Transfer the contents of the argument into this List.
Definition: LList.C:66