Test-ISLList.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 "ISLList.H"
34 
35 using namespace Foam;
36 
37 class Scalar
38 :
39  public ISLList<Scalar>::link
40 {
41 public:
42 
43  scalar data_;
44 
45  Scalar()
46  :
47  data_(0)
48  {}
49 
50  Scalar(scalar s)
51  :
52  data_(s)
53  {}
54 
55  friend Ostream& operator<<(Ostream& os, const Scalar& s)
56  {
57  os << s.data_;
58  return os;
59  }
60 
61 };
62 
63 
64 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65 // Main program:
66 
67 int main(int argc, char *argv[])
68 {
69  ISLList<Scalar> myList;
70 
71  for (int i = 0; i<10; i++)
72  {
73  myList.append(new Scalar(1.3*i));
74  }
75 
76  myList.append(new Scalar(100.3));
77  myList.append(new Scalar(500.3));
78 
79  Info<< nl << "And again using STL iterator: " << nl << endl;
80 
81  forAllIter(SLList<scalar>, myList, iter)
82  {
83  Info<< "element:" << *iter << endl;
84  }
85 
86  Info<< nl << "And again using STL const_iterator: " << nl << endl;
87 
88  const ISLList<Scalar>& const_myList = myList;
89 
90  forAllConstIter(SLList<scalar>, const_myList, iter)
91  {
92  Info<< "element:" << *iter << endl;
93  }
94 
95 
96  Info<< nl << "Testing transfer: " << nl << endl;
97  Info<< "original: " << myList << endl;
98 
99  ISLList<Scalar> newList;
100  newList.transfer(myList);
101 
102  Info<< nl << "source: " << myList << nl
103  << nl << "target: " << newList << endl;
104 
105  Info<< nl << "Bye." << endl;
106  return 0;
107 }
108 
109 
110 // ************************************************************************* //
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...
Scalar::Scalar
Scalar()
Definition: Test-ISLList.C:42
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
Scalar
Definition: Test-Dictionary.C:65
Scalar::operator<<
friend Ostream & operator<<(Ostream &os, const Scalar &s)
Definition: Test-ISLList.C:52
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Scalar
#define Scalar
Definition: doubleScalar.C:33
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::ILList< SLListBase, T >::transfer
void transfer(ILList< LListBase, T > &)
Transfer the contents of the argument into this List.
Definition: ILList.C:125
main
int main(int argc, char *argv[])
Definition: Test-ISLList.C:64
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::ISLList
Intrusive singly-linked list.
Definition: ISLList.H:47
Scalar::Scalar
Scalar(scalar s)
Definition: Test-ISLList.C:47
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
ISLList.H
s
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53