Test-Map.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  testMapIterators
26 
27 Description
28  For each time calculate the magnitude of velocity.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "Map.H"
33 #include <map>
34 #include "IOstreams.H"
35 
36 using namespace Foam;
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 int main(int argc, char *argv[])
41 {
42  Map<bool> banana;
43 
44  banana.insert(5, true);
45 
46  // Taking a const iterator from find does not work!
47  // Also, fails later on op==
48  Map<bool>::const_iterator bananaIter = banana.find(5);
49 
50  // This works but now I can change the value.
51  //Map<bool>::iterator bananaIter = banana.find(5);
52 
53  if (bananaIter == banana.end())
54  {
55  Info<< "not found" << endl;
56  }
57  else
58  {
59  Info<< "5 is " << bananaIter() << endl;
60  }
61 
62  // Same with STL
63  Info<< "Same with STL" << endl;
64 
65  std::map<label, bool> STLbanana;
66  STLbanana[5] = true;
67  std::map<label, bool>::const_iterator STLbananaIter = STLbanana.find(5);
68 
69  if (STLbananaIter == STLbanana.end())
70  {
71  Info<< "not found" << endl;
72  }
73  else
74  {
75  Info<< "5 is " << STLbananaIter->second << endl;
76  }
77 
78 
79  Info<< "End\n" << endl;
80 
81  return 0;
82 }
83 
84 
85 // ************************************************************************* //
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::HashTable::const_iterator
An STL-conforming const_iterator.
Definition: HashTable.H:470
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: PrimitivePatchTemplate.H:68
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
main
int main(int argc, char *argv[])
Definition: Test-Map.C:37
Map.H
Foam::Info
messageStream Info
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30