ENH: more stringent checks for fileName concatenation

- avoids some doubled slashes

STYLE: simplify concatenation of processor directory names
This commit is contained in:
Mark Olesen
2018-10-11 10:07:11 +02:00
parent a77ab5d4eb
commit c4542294a8
11 changed files with 38 additions and 31 deletions

View File

@ -358,8 +358,7 @@ int main(int argc, char *argv[])
if (Pstream::parRun())
{
sourceCaseDir =
sourceCaseDir
/"processor" + Foam::name(Pstream::myProcNo());
sourceCaseDir/("processor" + Foam::name(Pstream::myProcNo()));
}
wordList sourcePatches;
dict.readEntry("sourcePatches", sourcePatches);

View File

@ -589,7 +589,7 @@ int main(int argc, char *argv[])
(
Time::controlDictName,
args.rootPath(),
args.caseName()/fileName(word("processor") + name(proci))
args.caseName()/("processor" + Foam::name(proci))
);
processorDb.setTime(runTime);
@ -1016,7 +1016,7 @@ int main(int argc, char *argv[])
Time::controlDictName,
args.rootPath(),
args.caseName()
/fileName(word("processor") + name(proci))
/ ("processor" + Foam::name(proci))
)
);
}
@ -1374,8 +1374,8 @@ int main(int argc, char *argv[])
(
Time::controlDictName,
args.rootPath(),
args.caseName()/
fileName(word("processor") + name(procI))
args.caseName()
/ ("processor" + Foam::name(procI))
);
processorDb.setTime(runTime);

View File

@ -305,7 +305,7 @@ bool Foam::domainDecomposition::writeDecomposition(const bool decomposeSets)
fileName processorCasePath
(
time().caseName()/fileName(word("processor") + Foam::name(proci))
time().caseName()/("processor" + Foam::name(proci))
);
// create a database

View File

@ -50,7 +50,7 @@ void Foam::faMeshDecomposition::distributeFaces()
(
Time::controlDictName,
time().rootPath(),
time().caseName()/fileName(word("processor") + Foam::name(procI))
time().caseName()/("processor" + Foam::name(procI))
);
fvMesh procMesh
@ -250,7 +250,7 @@ void Foam::faMeshDecomposition::decomposeMesh()
(
Time::controlDictName,
time().rootPath(),
time().caseName()/fileName(word("processor") + Foam::name(procI))
time().caseName()/("processor" + Foam::name(procI))
);
fvMesh procFvMesh
@ -1059,8 +1059,7 @@ void Foam::faMeshDecomposition::decomposeMesh()
{
fileName processorCasePath
(
time().caseName()/fileName(word("processor")
+ Foam::name(procI))
time().caseName()/("processor" + Foam::name(procI))
);
// create a database
@ -1179,7 +1178,7 @@ bool Foam::faMeshDecomposition::writeDecomposition()
fileName processorCasePath
(
time().caseName()/fileName(word("processor") + Foam::name(procI))
time().caseName()/("processor" + Foam::name(procI))
);
// create a database

View File

@ -223,7 +223,7 @@ int main(int argc, char *argv[])
(
Time::controlDictName,
args.rootPath(),
args.caseName()/fileName(word("processor") + name(proci))
args.caseName()/("processor" + Foam::name(proci))
)
);
}

View File

@ -550,7 +550,7 @@ int main(int argc, char *argv[])
forAll(databases, proci)
{
Info<< "Reading database "
<< args.caseName()/fileName(word("processor") + name(proci))
<< args.caseName()/("processor" + Foam::name(proci))
<< endl;
databases.set
@ -560,7 +560,7 @@ int main(int argc, char *argv[])
(
Time::controlDictName,
args.rootPath(),
args.caseName()/fileName(word("processor") + name(proci))
args.caseName()/("processor" + Foam::name(proci))
)
);
}

View File

@ -88,7 +88,7 @@ int main(int argc, char *argv[])
const label nProcs = fileHandler().nProcs(args.path());
#else
label nProcs = 0;
while (isDir(args.path()/(word("processor") + name(nProcs))))
while (isDir(args.path()/("processor" + Foam::name(nProcs))))
{
++nProcs;
}
@ -106,7 +106,7 @@ int main(int argc, char *argv[])
(
Time::controlDictName,
args.rootPath(),
args.caseName()/fileName(word("processor") + name(proci))
args.caseName()/("processor" + Foam::name(proci))
)
);
}

View File

@ -396,7 +396,7 @@ int main(int argc, char *argv[])
(
Time::controlDictName,
rootDirSource,
caseDirSource/fileName(word("processor") + name(proci))
caseDirSource/("processor" + Foam::name(proci))
);
#include "setTimeIndex.H"
@ -471,7 +471,7 @@ int main(int argc, char *argv[])
(
Time::controlDictName,
rootDirTarget,
caseDirTarget/fileName(word("processor") + name(proci))
caseDirTarget/("processor" + Foam::name(proci))
);
fvMesh meshTarget
@ -536,7 +536,7 @@ int main(int argc, char *argv[])
(
Time::controlDictName,
rootDirSource,
caseDirSource/fileName(word("processor") + name(procISource))
caseDirSource/("processor" + Foam::name(procISource))
);
#include "setTimeIndex.H"
@ -572,8 +572,7 @@ int main(int argc, char *argv[])
(
Time::controlDictName,
rootDirTarget,
caseDirTarget/fileName(word("processor")
+ name(procITarget))
caseDirTarget/("processor" + Foam::name(procITarget))
);
fvMesh meshTarget

View File

@ -1317,7 +1317,7 @@ void Foam::argList::parse
isDir
(
rootPath_/globalCase_
/ "processor" + Foam::name(++nProcDirs)
/ ("processor" + Foam::name(++nProcDirs))
)
)
{}

View File

@ -367,8 +367,7 @@ Foam::fileOperations::masterUncollatedFileOperation::localObjectPath
// Uncollated type, e.g. processor1
const word procName
(
"processor"
+Foam::name(Pstream::myProcNo(Pstream::worldComm))
"processor" + Foam::name(Pstream::myProcNo(Pstream::worldComm))
);
return
processorsPath

View File

@ -426,13 +426,17 @@ Foam::fileName& Foam::fileName::operator/=(const string& other)
{
// Two non-empty strings: can concatenate
s.append("/");
if (s.back() != '/' && other.front() != '/')
{
s += '/';
}
s.append(other);
}
}
else if (other.size())
{
// Or, if the first string is empty
// The first string is empty
s = other;
}
@ -449,16 +453,23 @@ Foam::fileName Foam::operator/(const string& a, const string& b)
if (b.size())
{
// Two non-empty strings: can concatenate
return fileName(a + '/' + b);
if (a.back() == '/' || b.front() == '/')
{
return fileName(a + b);
}
else
{
return fileName(a + '/' + b);
}
}
return a;
return a; // The second string was empty
}
// Or, if the first string is empty
if (b.size())
{
// The first string is empty
return b;
}