introduce readList<T> function

- Read a bracket-delimited list, or handle a single value as list of size 1.
  Mostly useful for handling command-line arguments.
  eg,
      if (args.options().found("patches"))
      {
          patches = readList<word>(IStringStream(args.options()["patches"])());
      }
  can handle both of these:
      -patches  patch0
      -patches \( patch1 patch2 patch3 \)
This commit is contained in:
Mark Olesen
2009-05-18 12:05:52 +02:00
parent 06517656e8
commit a0a9cd3366
3 changed files with 85 additions and 7 deletions

View File

@ -29,6 +29,8 @@ Description
\*---------------------------------------------------------------------------*/
#include "OSspecific.H"
#include "argList.H"
#include "wordReList.H"
#include "IOstreams.H"
#include "IStringStream.H"
@ -38,11 +40,19 @@ Description
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noParallel();
argList::validOptions.insert("reList", "reList");
argList::validOptions.insert("wordList", "wordList");
argList::validOptions.insert("stringList", "stringList");
# include "setRootCase.H"
List<vector> list1(IStringStream("1 ((0 1 2))")());
Info<< "list1: " << list1 << endl;
@ -69,6 +79,31 @@ int main(int argc, char *argv[])
Info<< "Elements " << map << " out of " << list3
<< " => " << subList3 << endl;
wordReList reLst;
wordList wLst;
stringList sLst;
if (args.options().found("reList"))
{
reLst = readList<wordRe>(IStringStream(args.options()["reList"])());
}
if (args.options().found("wordList"))
{
wLst = readList<word>(IStringStream(args.options()["wordList"])());
}
if (args.options().found("stringList"))
{
sLst = readList<string>(IStringStream(args.options()["stringList"])());
}
Info<< nl
<< "-reList: " << reLst << nl
<< "-wordList: " << wLst << nl
<< "-stringList: " << sLst << endl;
return 0;
}