BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / applications / test / tokenize / Test-tokenize.C
blob8c099f9afc0d218519de7de6368fc822218e5120
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.
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.
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.
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/>.
24 Application
26 Description
27     Test the tokenizing of various things
28 \*---------------------------------------------------------------------------*/
30 #include "argList.H"
31 #include "IOobject.H"
32 #include "IOstreams.H"
33 #include "IFstream.H"
34 #include "IStringStream.H"
35 #include "cpuTime.H"
37 using namespace Foam;
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 //  Main program:
42 int main(int argc, char *argv[])
44     argList::noParallel();
45     argList::validArgs.insert("string .. stringN");
46     argList::addOption("file", "name");
47     argList::addOption("repeat", "count");
49     argList args(argc, argv, false, true);
51     const label repeat = args.optionLookupOrDefault<label>("repeat", 1);
53     cpuTime timer;
54     for (label count = 0; count < repeat; ++count)
55     {
56         for (label argI=1; argI < args.size(); ++argI)
57         {
58             const string& rawArg = args[argI];
59             if (count == 0)
60             {
61                 Info<< "input string: " << rawArg << nl;
62             }
64             IStringStream is(rawArg);
66             while (is.good())
67             {
68                 token tok(is);
69                 // char ch;
70                 // is.get(ch);
71                 // is.putback(ch);
72                 int lookahead = is.peek();
74                 if (count == 0)
75                 {
76                     Info<< "token: " << tok.info();
77                     Info<< "  lookahead: '" << char(lookahead) << "'" << endl;
78                 }
79             }
81             if (count == 0)
82             {
83                 Info<< nl;
84                 IOobject::writeDivider(Info);
85             }
86         }
87     }
89     Info<< "tokenized args " << repeat << " times in "
90         << timer.cpuTimeIncrement() << " s\n\n";
92     if (args.optionFound("file"))
93     {
94         for (label count = 0; count < repeat; ++count)
95         {
96             IFstream is(args["file"]);
98             if (count == 0)
99             {
100                 Info<< "tokenizing file: " << args["file"] << nl;
101             }
103             while (is.good())
104             {
105                 token tok(is);
106                 if (count == 0)
107                 {
108                     Info<< "token: " << tok.info() << endl;
109                 }
110             }
112             if (count == 0)
113             {
114                 Info<< nl;
115                 IOobject::writeDivider(Info);
116             }
117         }
119         Info<< "tokenized file " << repeat << " times in "
120             << timer.cpuTimeIncrement() << " s\n\n";
121     }
123     return 0;
126 // ************************************************************************* //