Commit e7b82aad authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: segregate older-style access methods with preprocessor define

- enclosed with a #ifdef Foam_argList_1712 .. #endif pair
  (defined by default).
  In a later release, this can be disabled by default.

ENH: add input length check for -hostRoots option
parent b1996f34
......@@ -86,7 +86,8 @@ Foam::argList::initValidTables::initValidTables()
argList::addOption
(
"hostRoots", "(((host1 dir1) .. (hostN dirN))",
"slave root directories (per host) for distributed running"
"slave root directories (per host) for distributed running. "
"The host specification can use a regex."
);
validParOptions.set("hostRoots", "((host1 dir1) .. (hostN dirN))");
......@@ -647,7 +648,7 @@ bool Foam::argList::regroupArgv(int& argc, char**& argv)
args_[nArgs++] = group;
}
args_.setSize(nArgs);
args_.resize(nArgs);
std::string::size_type len = (nArgs-1); // Spaces between args
forAll(args_, argi)
......@@ -848,7 +849,7 @@ Foam::argList::argList
}
}
args_.setSize(nArgs);
args_.resize(nArgs);
parse(checkArgs, checkOpts, initialise);
}
......@@ -1012,8 +1013,8 @@ void Foam::argList::parse
{
if (Pstream::master())
{
slaveProcs.setSize(Pstream::nProcs() - 1);
slaveMachine.setSize(Pstream::nProcs() - 1);
slaveProcs.resize(Pstream::nProcs()-1);
slaveMachine.resize(Pstream::nProcs()-1);
label proci = 0;
for
(
......@@ -1027,11 +1028,11 @@ void Foam::argList::parse
string slaveBuild;
label slavePid;
fromSlave >> slaveBuild >> slaveMachine[proci] >> slavePid;
slaveProcs[proci] = slaveMachine[proci] + "." + name(slavePid);
proci++;
// Check build string to make sure all processors are running
// the same build
// Verify that all processors are running the same build
if (slaveBuild != Foam::FOAMbuild)
{
FatalErrorIn(executable())
......@@ -1113,37 +1114,35 @@ void Foam::argList::parse
}
else if (options_.found("hostRoots"))
{
roots.resize(Pstream::nProcs()-1, fileName::null);
source = "-hostRoots";
IStringStream is(options_["hostRoots"]);
ITstream is = this->lookup("hostRoots");
List<Tuple2<wordRe, fileName>> hostRoots(is);
warnTrailing(is, "hostRoots");
roots.setSize(Pstream::nProcs()-1);
forAll(hostRoots, i)
for (const auto& hostRoot : hostRoots)
{
const Tuple2<wordRe, fileName>& hostRoot = hostRoots[i];
const wordRe& re = hostRoot.first();
labelList matchedRoots(findStrings(re, slaveMachine));
forAll(matchedRoots, matchi)
labelList matched(findStrings(re, slaveMachine));
for (const label slavei : matched)
{
label slavei = matchedRoots[matchi];
if (roots[slavei] != wordRe())
if (!roots[slavei].empty())
{
FatalErrorInFunction
<< "Slave " << slaveMachine[slavei]
<< " has multiple matching roots in "
<< hostRoots << exit(FatalError);
}
else
{
roots[slavei] = hostRoot.second();
}
roots[slavei] = hostRoot.second();
}
}
// Check
forAll(roots, slavei)
{
if (roots[slavei] == wordRe())
if (roots[slavei].empty())
{
FatalErrorInFunction
<< "Slave " << slaveMachine[slavei]
......@@ -1188,7 +1187,7 @@ void Foam::argList::parse
if (roots.size() == 1)
{
const fileName rootName(roots[0]);
roots.setSize(Pstream::nProcs()-1, rootName);
roots.resize(Pstream::nProcs()-1, rootName);
// adjust dictNProcs for command-line '-roots' option
if (dictNProcs < 0)
......
......@@ -105,6 +105,9 @@ SourceFiles
#include "ITstream.H"
#include <utility>
// Transitional features - older style access (including 1712 release)
#define Foam_argList_1712
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
......@@ -374,65 +377,6 @@ public:
inline bool readListIfPresent(const word& optName, List<T>& list) const;
// Older style access (including 1712 release)
//- Read a value from the argument at index.
// Index 1 is the first non-option argument.
// \deprecated in favour of read() - JAN-2018
template<class T>
inline T argRead(const label index) const;
//- Return true if the named option is found
// \deprecated in favour of found() - JAN-2018
inline bool optionFound(const word& optName) const;
//- Return an input stream from the named option
// \deprecated in favour of lookup() - JAN-2018
inline ITstream optionLookup(const word& optName) const;
//- Read a value from the named option
// \deprecated in favour of opt() - JAN-2018
template<class T>
inline T optionRead(const word& optName) const;
//- Read a value from the named option if present.
// Return true if the named option was found.
// \deprecated in favour of readIfPresent() - JAN-2018
template<class T>
inline bool optionReadIfPresent
(
const word& optName,
T& val
) const;
//- Read a value from the named option if present.
// Return true if the named option was found, otherwise
// use the supplied default and return false.
// \deprecated in favour of readIfPresent() - JAN-2018
template<class T>
inline bool optionReadIfPresent
(
const word& optName,
T& val,
const T& deflt
) const;
//- Read a value from the named option if present.
// Return supplied default otherwise.
// \deprecated in favour of lookupOrDefault() - JAN-2018
template<class T>
inline T optionLookupOrDefault
(
const word& optName,
const T& deflt
) const;
//- Read a List of values from the named option
// \deprecated in favour of readList() - JAN-2018
template<class T>
inline List<T> optionReadList(const word& optName) const;
// Edit
//- Append a (mandatory) argument to validArgs
......@@ -572,6 +516,93 @@ public:
//- The string associated with the named option
inline const string& operator[](const word& optName) const;
// Older style access (including 1712 release)
#ifdef Foam_argList_1712
//- Read a value from the argument at index.
// Index 1 is the first non-option argument.
// \deprecated in favour of read() - JAN-2018
template<class T>
inline T argRead(const label index) const
{
return this->read<T>(index);
}
//- Return true if the named option is found
// \deprecated in favour of found() - JAN-2018
inline bool optionFound(const word& optName) const
{
return found(optName);
}
//- Return an input stream from the named option
// \deprecated in favour of lookup() - JAN-2018
inline ITstream optionLookup(const word& optName) const
{
return lookup(optName);
}
//- Read a value from the named option
// \deprecated in favour of opt() - JAN-2018
template<class T>
inline T optionRead(const word& optName) const
{
return opt<T>(optName);
}
//- Read a value from the named option if present.
// Return true if the named option was found.
// \deprecated in favour of readIfPresent() - JAN-2018
template<class T>
inline bool optionReadIfPresent
(
const word& optName,
T& val
) const
{
return readIfPresent<T>(optName, val);
}
//- Read a value from the named option if present.
// Return true if the named option was found, otherwise
// use the supplied default and return false.
// \deprecated in favour of readIfPresent() - JAN-2018
template<class T>
inline bool optionReadIfPresent
(
const word& optName,
T& val,
const T& deflt
) const
{
return readIfPresent<T>(optName, val, deflt);
}
//- Read a value from the named option if present.
// Return supplied default otherwise.
// \deprecated in favour of lookupOrDefault() - JAN-2018
template<class T>
inline T optionLookupOrDefault
(
const word& optName,
const T& deflt
) const
{
return lookupOrDefault<T>(optName, deflt);
}
//- Read a List of values from the named option
// \deprecated in favour of readList() - JAN-2018
template<class T>
inline List<T> optionReadList(const word& optName) const
{
return this->readList<T>(optName);
}
#endif /* Foam_argList_1712 */
};
......
......@@ -211,7 +211,6 @@ namespace Foam
{
return options_[optName];
}
}
......@@ -359,72 +358,4 @@ inline const Foam::string& Foam::argList::operator[](const word& optName) const
}
// * * * * * * * * * * * * * * * Compatibility * * * * * * * * * * * * * * * //
template<class T>
inline T Foam::argList::argRead(const label index) const
{
return this->read<T>(index);
}
inline bool Foam::argList::optionFound(const word& optName) const
{
return found(optName);
}
inline Foam::ITstream Foam::argList::optionLookup(const word& optName) const
{
return lookup(optName);
}
template<class T>
inline T Foam::argList::optionRead(const word& optName) const
{
return opt<T>(optName);
}
template<class T>
inline bool
Foam::argList::optionReadIfPresent(const word& optName, T& val) const
{
return readIfPresent<T>(optName, val);
}
template<class T>
inline bool Foam::argList::optionReadIfPresent
(
const word& optName,
T& val,
const T& deflt
) const
{
return readIfPresent<T>(optName, val, deflt);
}
template<class T>
inline T Foam::argList::optionLookupOrDefault
(
const word& optName,
const T& deflt
) const
{
return lookupOrDefault<T>(optName, deflt);
}
template<class T>
inline Foam::List<T>
Foam::argList::optionReadList(const word& optName) const
{
return this->readList<T>(optName);
}
// ************************************************************************* //
Markdown is supported
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