Commit 51039eab authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: provide argRead() method and operator[] for accessing argList arguments.

- also provide size() method, which returns the number of arguments
parent ee293cde
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -211,9 +211,19 @@ public:
//- Return arguments
inline const stringList& args() const;
//- Return additional arguments,
// i.e. those additional to the executable itself
stringList::subList additionalArgs() const;
//- Return the number of arguments
inline label size() const;
//- Return the argument corresponding to index.
// Index 0 corresponds to the name of the executable.
// Index 1 corresponds to the first argument.
inline const string& operator[](const label index) const;
//- Read a value from the argument at index.
// Index 0 corresponds to the name of the executable.
// Index 1 corresponds to the first argument.
template<class T>
inline T argRead(const label index) const;
//- Return options
inline const Foam::HashTable<string>& options() const;
......@@ -264,7 +274,6 @@ public:
}
// Edit
//- Add to a bool option to validOptions with usage information
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2009-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -64,6 +64,12 @@ inline const Foam::stringList& Foam::argList::args() const
}
inline Foam::label Foam::argList::size() const
{
return args_.size();
}
inline const Foam::HashTable<Foam::string>& Foam::argList::options() const
{
return options_;
......@@ -92,6 +98,30 @@ inline Foam::IStringStream Foam::argList::optionLookup(const word& opt) const
namespace Foam
{
// Template specialization for string
template<>
inline Foam::string
Foam::argList::argRead<Foam::string>(const label index) const
{
return args_[index];
}
// Template specialization for word
template<>
inline Foam::word
Foam::argList::argRead<Foam::word>(const label index) const
{
return args_[index];
}
// Template specialization for fileName
template<>
inline Foam::fileName
Foam::argList::argRead<Foam::fileName>(const label index) const
{
return args_[index];
}
// Template specialization for string
template<>
inline Foam::string
......@@ -120,6 +150,16 @@ namespace Foam
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline T Foam::argList::argRead(const label index) const
{
T val;
IStringStream(args_[index])() >> val;
return val;
}
template<class T>
inline T Foam::argList::optionRead(const word& opt) const
{
......@@ -187,4 +227,12 @@ inline T Foam::argList::optionLookupOrDefault
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline const Foam::string& Foam::argList::operator[](const label index) const
{
return args_[index];
}
// ************************************************************************* //
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment