Test-labelRanges.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  Test label ranges
28 \*---------------------------------------------------------------------------*/
29 
30 #include "argList.H"
31 #include "IOobject.H"
32 #include "IOstreams.H"
33 #include "IFstream.H"
34 #include "IStringStream.H"
35 #include "labelRanges.H"
36 
37 using namespace Foam;
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 // Main program:
41 
42 int main(int argc, char *argv[])
43 {
45  argList::validArgs.insert("start size .. startN sizeN");
46  argList::addOption("verbose");
48  (
49  "The default is to add ranges, use 'add' and 'del' to toggle\n\n"
50  "Eg, 0 10 30 10 del 20 15"
51  );
52 
53  argList args(argc, argv, false, true);
54 
55  if (args.optionFound("verbose"))
56  {
58  }
59 
60 
61  labelRanges ranges;
62 
63  bool removeMode = false;
64  for (label argI=1; argI < args.size()-1; ++argI)
65  {
66  if (args[argI] == "add")
67  {
68  removeMode = false;
69  continue;
70  }
71  else if (args[argI] == "del")
72  {
73  removeMode = true;
74  continue;
75  }
76 
77  label start = 0;
78  label size = 0;
79 
80  IStringStream(args[argI])() >> start;
81  ++argI;
82  IStringStream(args[argI])() >> size;
83 
84  labelRange range(start, size);
85 
86  Info<< "---------------" << nl;
87  if (removeMode)
88  {
89  Info<< "del " << range << " :";
91  {
92  Info<< " " << iter();
93  }
94  Info<< nl;
95 
96  ranges.remove(range);
97  }
98  else
99  {
100  Info<< "add " << range << " :";
102  {
103  Info<< " " << iter();
104  }
105  Info<< nl;
106 
107  ranges.add(range);
108  }
109 
110  Info<< "<list>" << ranges << "</list>" << nl;
111  forAllConstIter(labelRanges, ranges, iter)
112  {
113  Info<< " " << iter();
114  }
115  Info<< nl;
116  }
117 
118  return 0;
119 }
120 
121 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::argList::addOption
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:108
Foam::argList::addNote
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:139
Foam::argList::size
label size() const
Return the number of arguments.
Definition: argListI.H:84
main
int main(int argc, char *argv[])
Definition: Test-labelRanges.C:39
Foam::labelRanges::remove
bool remove(const labelRange &)
Remove the range from the list.
Definition: labelRanges.C:185
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:97
labelRanges.H
IStringStream.H
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
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
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::labelRanges
A list of labelRange.
Definition: labelRanges.H:58
argList.H
Foam::labelRange
A label range specifier.
Definition: labelRange.H:56
IFstream.H
IOobject.H
Foam::IStringStream
Input from memory buffer stream.
Definition: IStringStream.H:49
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::labelRange::debug
static int debug
Definition: labelRange.H:65
range
scalar range
Definition: LISASMDCalcMethod1.H:12
Foam::argList::optionFound
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
args
Foam::argList args(argc, argv)
Foam::labelRanges::add
bool add(const labelRange &)
Add the range to the list.
Definition: labelRanges.C:127