mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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
This commit is contained in:
@ -86,7 +86,8 @@ Foam::argList::initValidTables::initValidTables()
|
|||||||
argList::addOption
|
argList::addOption
|
||||||
(
|
(
|
||||||
"hostRoots", "(((host1 dir1) .. (hostN dirN))",
|
"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))");
|
validParOptions.set("hostRoots", "((host1 dir1) .. (hostN dirN))");
|
||||||
|
|
||||||
@ -647,7 +648,7 @@ bool Foam::argList::regroupArgv(int& argc, char**& argv)
|
|||||||
args_[nArgs++] = group;
|
args_[nArgs++] = group;
|
||||||
}
|
}
|
||||||
|
|
||||||
args_.setSize(nArgs);
|
args_.resize(nArgs);
|
||||||
|
|
||||||
std::string::size_type len = (nArgs-1); // Spaces between args
|
std::string::size_type len = (nArgs-1); // Spaces between args
|
||||||
forAll(args_, argi)
|
forAll(args_, argi)
|
||||||
@ -848,7 +849,7 @@ Foam::argList::argList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
args_.setSize(nArgs);
|
args_.resize(nArgs);
|
||||||
|
|
||||||
parse(checkArgs, checkOpts, initialise);
|
parse(checkArgs, checkOpts, initialise);
|
||||||
}
|
}
|
||||||
@ -1012,8 +1013,8 @@ void Foam::argList::parse
|
|||||||
{
|
{
|
||||||
if (Pstream::master())
|
if (Pstream::master())
|
||||||
{
|
{
|
||||||
slaveProcs.setSize(Pstream::nProcs() - 1);
|
slaveProcs.resize(Pstream::nProcs()-1);
|
||||||
slaveMachine.setSize(Pstream::nProcs() - 1);
|
slaveMachine.resize(Pstream::nProcs()-1);
|
||||||
label proci = 0;
|
label proci = 0;
|
||||||
for
|
for
|
||||||
(
|
(
|
||||||
@ -1027,11 +1028,11 @@ void Foam::argList::parse
|
|||||||
string slaveBuild;
|
string slaveBuild;
|
||||||
label slavePid;
|
label slavePid;
|
||||||
fromSlave >> slaveBuild >> slaveMachine[proci] >> slavePid;
|
fromSlave >> slaveBuild >> slaveMachine[proci] >> slavePid;
|
||||||
|
|
||||||
slaveProcs[proci] = slaveMachine[proci] + "." + name(slavePid);
|
slaveProcs[proci] = slaveMachine[proci] + "." + name(slavePid);
|
||||||
proci++;
|
proci++;
|
||||||
|
|
||||||
// Check build string to make sure all processors are running
|
// Verify that all processors are running the same build
|
||||||
// the same build
|
|
||||||
if (slaveBuild != Foam::FOAMbuild)
|
if (slaveBuild != Foam::FOAMbuild)
|
||||||
{
|
{
|
||||||
FatalErrorIn(executable())
|
FatalErrorIn(executable())
|
||||||
@ -1113,37 +1114,35 @@ void Foam::argList::parse
|
|||||||
}
|
}
|
||||||
else if (options_.found("hostRoots"))
|
else if (options_.found("hostRoots"))
|
||||||
{
|
{
|
||||||
source = "-hostRoots";
|
roots.resize(Pstream::nProcs()-1, fileName::null);
|
||||||
IStringStream is(options_["hostRoots"]);
|
|
||||||
List<Tuple2<wordRe, fileName>> hostRoots(is);
|
|
||||||
|
|
||||||
roots.setSize(Pstream::nProcs()-1);
|
source = "-hostRoots";
|
||||||
forAll(hostRoots, i)
|
ITstream is = this->lookup("hostRoots");
|
||||||
|
List<Tuple2<wordRe, fileName>> hostRoots(is);
|
||||||
|
warnTrailing(is, "hostRoots");
|
||||||
|
|
||||||
|
for (const auto& hostRoot : hostRoots)
|
||||||
{
|
{
|
||||||
const Tuple2<wordRe, fileName>& hostRoot = hostRoots[i];
|
|
||||||
const wordRe& re = hostRoot.first();
|
const wordRe& re = hostRoot.first();
|
||||||
labelList matchedRoots(findStrings(re, slaveMachine));
|
labelList matched(findStrings(re, slaveMachine));
|
||||||
forAll(matchedRoots, matchi)
|
for (const label slavei : matched)
|
||||||
{
|
{
|
||||||
label slavei = matchedRoots[matchi];
|
if (!roots[slavei].empty())
|
||||||
if (roots[slavei] != wordRe())
|
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "Slave " << slaveMachine[slavei]
|
<< "Slave " << slaveMachine[slavei]
|
||||||
<< " has multiple matching roots in "
|
<< " has multiple matching roots in "
|
||||||
<< hostRoots << exit(FatalError);
|
<< hostRoots << exit(FatalError);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
roots[slavei] = hostRoot.second();
|
roots[slavei] = hostRoot.second();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Check
|
// Check
|
||||||
forAll(roots, slavei)
|
forAll(roots, slavei)
|
||||||
{
|
{
|
||||||
if (roots[slavei] == wordRe())
|
if (roots[slavei].empty())
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "Slave " << slaveMachine[slavei]
|
<< "Slave " << slaveMachine[slavei]
|
||||||
@ -1188,7 +1187,7 @@ void Foam::argList::parse
|
|||||||
if (roots.size() == 1)
|
if (roots.size() == 1)
|
||||||
{
|
{
|
||||||
const fileName rootName(roots[0]);
|
const fileName rootName(roots[0]);
|
||||||
roots.setSize(Pstream::nProcs()-1, rootName);
|
roots.resize(Pstream::nProcs()-1, rootName);
|
||||||
|
|
||||||
// adjust dictNProcs for command-line '-roots' option
|
// adjust dictNProcs for command-line '-roots' option
|
||||||
if (dictNProcs < 0)
|
if (dictNProcs < 0)
|
||||||
|
|||||||
@ -105,6 +105,9 @@ SourceFiles
|
|||||||
#include "ITstream.H"
|
#include "ITstream.H"
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
// Transitional features - older style access (including 1712 release)
|
||||||
|
#define Foam_argList_1712
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
@ -374,65 +377,6 @@ public:
|
|||||||
inline bool readListIfPresent(const word& optName, List<T>& list) const;
|
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
|
// Edit
|
||||||
|
|
||||||
//- Append a (mandatory) argument to validArgs
|
//- Append a (mandatory) argument to validArgs
|
||||||
@ -572,6 +516,93 @@ public:
|
|||||||
//- The string associated with the named option
|
//- The string associated with the named option
|
||||||
inline const string& operator[](const word& optName) const;
|
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];
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
Reference in New Issue
Block a user