ENH: improve consistency of fileName handling windows/non-windows (#2057)

- wrap command-line retrieval of fileName with an implicit validate.

  Instead of this:
      fileName input(args[1]);
      fileName other(args["someopt"]);

  Now use this:
      auto input = args.get<fileName>(1);
      auto other = args.get<fileName>("someopt");

  which adds a fileName::validate on the inputs

  Because of how it is implemented, it will automatically also apply
  to argList getOrDefault<fileName>, readIfPresent<fileName> etc.

- adjust fileName::validate and clean to handle backslash conversion.
  This makes it easier to ensure that path names arising from MS-Windows
  are consistently handled internally.

- dictionarySearch: now check for initial '/' directly instead of
  relying on fileName isAbsolute(), which now does more things

BREAKING: remove fileName::clean() const method

- relying on const/non-const to control the behaviour (inplace change
  or return a copy) is too fragile and the const version was
  almost never used.

  Replace:
      fileName sanitized = constPath.clean();

  With:
      fileName sanitized(constPath);
      sanitized.clean());

STYLE: test empty() instead of comparing with fileName::null
This commit is contained in:
Mark Olesen 2021-04-12 22:56:20 +02:00 committed by Andrew Heather
parent 96a1b86fb9
commit b060378dca
109 changed files with 483 additions and 456 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -101,7 +101,7 @@ int main(int argc, char *argv[])
{
if (true)
{
IFstream is(args[argi]);
IFstream is(args.get<fileName>(argi));
Info<< nl << nl
<< "read from " << is.name() << nl << endl;
@ -132,7 +132,7 @@ int main(int argc, char *argv[])
if (true)
{
IFstream is(args[argi]);
IFstream is(args.get<fileName>(argi));
Info<< nl << nl
<< "read from " << is.name() << nl << endl;

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -125,9 +126,9 @@ int main(int argc, char *argv[])
}
for (label argI=1; argI < args.size(); ++argI)
for (label argi=1; argi < args.size(); ++argi)
{
const string& srcFile = args[argI];
const auto srcFile = args.get<fileName>(argi);
Info<< nl << "reading " << srcFile << nl;
IFstream ifs(srcFile);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -74,8 +74,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
const fileName decompFile = args[1];
const auto decompFile = args.get<fileName>(1);
const bool region = args.found("region");
const bool allRegions = args.found("allRegions");
const bool verbose = args.found("verbose");

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -59,9 +60,9 @@ int main(int argc, char *argv[])
else
{
IOobject::writeDivider(Info);
for (label argI=1; argI < args.size(); ++argI)
for (label argi=1; argi < args.size(); ++argi)
{
const string& dictFile = args[argI];
const auto dictFile = args.get<fileName>(argi);
IFstream is(dictFile);
dictionary dict(is);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -179,7 +179,7 @@ int main(int argc, char *argv[])
for (label argi=1; argi < args.size(); ++argi)
{
const string& dictFile = args[argi];
const auto dictFile = args.get<fileName>(argi);
IFstream is(dictFile);
dictionary inputDict(is);
@ -201,7 +201,7 @@ int main(int argc, char *argv[])
{
for (label argi=1; argi < args.size(); ++argi)
{
const string& dictFile = args[argi];
const auto dictFile = args.get<fileName>(argi);
IFstream is(dictFile);
dictionary inputDict(is);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -135,8 +135,8 @@ int main(int argc, char *argv[])
args.readIfPresent("maxPath", maxPath);
#endif
const fileName srcFile(fileName::validate(args[1]));
const fileName dstFile(fileName::validate(args[2]));
const auto srcFile = args.get<fileName>(1);
const auto dstFile = args.get<fileName>(2);
const fileName tmpFile(dstFile + Foam::name(pid()));
Info<< "src : " << srcFile << nl

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -54,7 +55,7 @@ int main(int argc, char *argv[])
#include "createTime.H"
const fileName file(args[1]);
const auto file = args.get<fileName>(1);
Info<< "Reading " << file << nl << endl;
decomposedBlockData data

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2012 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -123,9 +124,9 @@ int main(int argc, char *argv[])
else
{
IOobject::writeDivider(Info);
for (label argI=1; argI < args.size(); ++argI)
for (label argi=1; argi < args.size(); ++argi)
{
const string& dictFile = args[argI];
const auto dictFile = args.get<fileName>(argi);
IFstream is(dictFile);
dictionary dict(is);

View File

@ -69,7 +69,7 @@ int main(int argc, char *argv[])
for (label argi=1; argi < args.size(); ++argi)
{
const string& dictFile = args[argi];
const auto dictFile = args.get<fileName>(argi);
IFstream is(dictFile);
dictionary input(is);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -61,7 +61,7 @@ int main(int argc, char *argv[])
for (label argi=1; argi < args.size(); ++argi)
{
IFstream is(args[argi]);
IFstream is(args.get<fileName>(argi));
dictionary dict(is);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -70,7 +70,7 @@ int main(int argc, char *argv[])
for (int argi = 1; argi < args.size(); ++argi)
{
const fileName libName(fileName::validate(args[argi]));
const auto libName = args.get<fileName>(argi);
if (libName.empty())
{

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -79,7 +79,7 @@ int main(int argc, char *argv[])
{
IOobject::writeDivider(Info);
IFstream is(args[argi]);
IFstream is(args.get<fileName>(argi));
const dictionary dict(is);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2017 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -60,7 +60,7 @@ unsigned testClean(std::initializer_list<Pair<std::string>> tests)
const std::string& expected = test.second();
fileName cleaned(test.first());
cleaned.clean();
cleaned.clean(); // Remove unneeded ".."
if (cleaned == expected)
{

View File

@ -5,7 +5,8 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -24,11 +25,10 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
fileNameCleanTest
Test-fileNameClean
Description
\*---------------------------------------------------------------------------*/
#include "argList.H"
@ -51,7 +51,7 @@ void printCleaning(fileName& pathName)
Info<< "components = " << flatOutput(pathName.components()) << nl;
Info<< "component 2 = " << pathName.component(2) << nl;
pathName.clean();
pathName.clean(); // Remove unneeded ".."
Info<< "cleaned = " << pathName << nl
<< " path() = " << pathName.path() << nl
@ -94,9 +94,15 @@ int main(int argc, char *argv[])
printCleaning(pathName);
}
for (label argI=1; argI < args.size(); ++argI)
for (label argi=1; argi < args.size(); ++argi)
{
pathName = args[argI];
fileName fn(args[argi], false); // no strip
Info<< "Input = " << fn << nl;
fn.clean(); // Remove unneeded ".."
Info<< "cleaned = " << fn << nl;
Info<< "get = " << args.get<fileName>(argi) << nl;
pathName = fileName::validate(args[argi]);
printCleaning(pathName);
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -81,7 +81,7 @@ int main(int argc, char *argv[])
for (label argi = 1; argi < args.size(); ++argi)
{
const fileName inputName(args[argi]);
const auto inputName = args.get<fileName>(argi);
InfoErr<< "input: " << inputName;

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -53,9 +54,9 @@ int main(int argc, char *argv[])
label ok = 0;
for (label argI=1; argI < args.size(); ++argI)
for (label argi=1; argi < args.size(); ++argi)
{
const string& srcFile = args[argI];
const auto srcFile = args.get<fileName>(argi);
if (args.found("ext"))
{

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -73,7 +73,7 @@ int main(int argc, char *argv[])
for (label argi=1; argi < args.size(); ++argi)
{
IFstream is(args[argi]);
IFstream is(args.get<fileName>(argi));
dictionary dict(is);

View File

@ -375,7 +375,7 @@ int main(int argc, char *argv[])
for (label argi = 1; argi < args.size(); ++argi)
{
IFstream is(args[argi]);
IFstream is(args.get<fileName>(argi));
List<regexTest> tests(is);
Info<< "Test expressions:" << tests << endl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -76,9 +76,9 @@ int main(int argc, char *argv[])
useCatmullRom = true;
}
for (label argI=1; argI < args.size(); ++argI)
for (label argi=1; argi < args.size(); ++argi)
{
const string& srcFile = args[argI];
const auto srcFile = args.get<fileName>(argi);
Info<< nl << "reading " << srcFile << nl;
IFstream ifs(srcFile);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -139,13 +139,13 @@ int main(int argc, char *argv[])
const word outputFile(args.executable() + ".obj");
const fileName surf1Name(args[1]);
const auto surf1Name = args.get<fileName>(1);
triSurface surf1 = loadSurface(runTime, surf1Name, scaleFactor)();
Info<< surf1Name << " statistics:" << endl;
surf1.writeStats(Info);
Info<< endl;
const fileName surf2Name(args[2]);
const auto surf2Name = args.get<fileName>(2);
triSurface surf2 = loadSurface(runTime, surf2Name, scaleFactor)();
Info<< surf2Name << " statistics:" << endl;
surf2.writeStats(Info);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -89,7 +89,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
const fileName importName = args[1];
const auto importName = args.get<fileName>(1);
word ext;
if (!args.readIfPresent("ext", ext))

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -68,8 +68,8 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
const fileName importName = args[1];
const fileName exportName = args[2];
const auto importName = args.get<fileName>(1);
const auto exportName = args.get<fileName>(2);
if (importName == exportName)
{

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -54,7 +54,7 @@ int main(int argc, char *argv[])
for (label argi=1; argi < args.size(); ++argi)
{
const auto& input = args[argi];
const auto input = args.get<fileName>(argi);
Info << "load from " << input << nl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -327,7 +327,7 @@ int main(int argc, char *argv[])
#include "createTime.H"
const fileName ansysFile(args[1]);
const auto ansysFile = args.get<fileName>(1);
std::ifstream ansysStream(ansysFile);
if (!ansysStream)

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -225,7 +225,7 @@ int main(int argc, char *argv[])
}
// CCM reader for reading geometry/solution
ccm::reader reader(args[1], rOpts);
ccm::reader reader(args.get<fileName>(1), rOpts);
// list the geometry information
if (optList)

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -76,7 +76,7 @@ int main(int argc, char *argv[])
#include "createTime.H"
IFstream cfxFile(args[1]);
IFstream cfxFile(args.get<fileName>(1));
// Read the cfx information using a fixed format reader.
// Comments in the file are in C++ style, so the stream parser will remove

View File

@ -66,7 +66,7 @@ int main(int argc, char *argv[])
#include "createTime.H"
std::ifstream plot3dFile(args[1]);
std::ifstream plot3dFile(args.get<fileName>(1));
string line;
std::getline(plot3dFile, line);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -103,7 +103,7 @@ int main(int argc, char *argv[])
fileFormats::FIREMeshReader reader
(
args[1],
args.get<fileName>(1),
// Default no scaling
args.getOrDefault<scalar>("scale", 1)
);

View File

@ -835,7 +835,7 @@ int main(int argc, char *argv[])
#include "createTime.H"
const fileName fluentFile = args[1];
const auto fluentFile = args.get<fileName>(1);
IFstream fluentStream(fluentFile);
if (!fluentStream)

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -912,7 +912,7 @@ int main(int argc, char *argv[])
#include "createTime.H"
const fileName fluentFile = args[1];
const auto fluentFile = args.get<fileName>(1);
std::ifstream fluentStream(fluentFile);
if (!fluentStream)

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -82,7 +82,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
fileName exportName = args[1];
auto exportName = args.get<fileName>(1);
const scalar scaleFactor = args.getOrDefault<scalar>("scale", 0);
const bool doTriangulate = args.found("tri");

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -653,7 +653,7 @@ int main(int argc, char *argv[])
#include "createTime.H"
const fileName gambitFile = args[1];
const auto gambitFile = args.get<fileName>(1);
std::ifstream gambitStream(gambitFile);
if (!gambitStream)

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -1325,7 +1325,7 @@ int main(int argc, char *argv[])
}
const bool keepOrientation = args.found("keepOrientation");
IFstream inFile(args[1]);
IFstream inFile(args.get<fileName>(1));
// Storage for points
pointField points;

View File

@ -666,7 +666,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
#include "createTime.H"
const fileName ideasName = args[1];
const auto ideasName = args.get<fileName>(1);
IFstream inFile(ideasName);
if (!inFile.good())

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -77,7 +78,7 @@ int main(int argc, char *argv[])
#include "createTime.H"
const bool readHex = args.found("hex");
IFstream mshStream(args[1]);
IFstream mshStream(args.get<fileName>(1));
label nCells;
mshStream >> nCells;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -104,7 +104,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
#include "createTime.H"
IFstream str(args[1]);
IFstream str(args.get<fileName>(1));
//
// Read nodes.

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -111,7 +111,7 @@ int main(int argc, char *argv[])
#include "createTime.H"
IFstream plot3dFile(args[1]);
IFstream plot3dFile(args.get<fileName>(1));
// Read the plot3d information using a fixed format reader.
// Comments in the file are in C++ style, so the stream parser will remove

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -108,7 +108,7 @@ int main(int argc, char *argv[])
// Remove extensions and/or trailing '.'
const fileName prefix = fileName(args[1]).lessExt();
const auto prefix = args.get<fileName>(1).lessExt();
fileFormats::STARCDMeshReader reader

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd.
Copyright (C) 2015-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -119,7 +119,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
#include "createTime.H"
const fileName prefix = args[1];
const auto prefix = args.get<fileName>(1);
const bool readFaceFile = !args.found("noFaceFile");
const fileName nodeFile(prefix + ".node");

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -65,7 +66,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
#include "createTime.H"
IFstream mshStream(args[1]);
IFstream mshStream(args.get<fileName>(1));
vtkUnstructuredReader reader(runTime, mshStream);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -289,7 +289,7 @@ void Foam::conformalVoronoiMesh::insertSurfacePointPairs
}
}
if (foamyHexMeshControls().objOutput() && fName != fileName::null)
if (foamyHexMeshControls().objOutput() && !fName.empty())
{
DelaunayMeshTools::writeOBJ(time().path()/fName, pts);
}
@ -324,7 +324,7 @@ void Foam::conformalVoronoiMesh::insertEdgePointGroups
}
}
if (foamyHexMeshControls().objOutput() && fName != fileName::null)
if (foamyHexMeshControls().objOutput() && !fName.empty())
{
DelaunayMeshTools::writeOBJ(time().path()/fName, pts);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -378,7 +378,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
#include "createTime.H"
const fileName exportName = args[1];
const auto exportName = args.get<fileName>(1);
Info<< "Reading surfaces as specified in the foamyHexMeshDict and"
<< " writing a re-sampled surface to " << exportName

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -64,8 +64,8 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
#include "createTime.H"
const labelVector n(args.get<labelVector>(1));
const fileName exportName = args[2];
const auto n = args.get<labelVector>(1);
const auto exportName = args.get<fileName>(2);
Info<< "Reading surfaces as specified in the foamyHexMeshDict and"
<< " writing re-sampled " << n << " to " << exportName

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -97,7 +98,7 @@ int main(int argc, char *argv[])
if (args.found("pointsFile"))
{
mesh.insertPoints(args["pointsFile"]);
mesh.insertPoints(args.get<fileName>("pointsFile"));
}
else
{

View File

@ -541,7 +541,7 @@ void extractSurface
? runTime.globalPath()/outFileName
: runTime.path()/outFileName
);
globalCasePath.clean();
globalCasePath.clean(); // Remove unneeded ".."
Info<< "Writing merged surface to " << globalCasePath << endl;

View File

@ -306,7 +306,7 @@ void Foam::mergeAndWrite
/ mesh.pointsInstance()
/ set.name()
);
outputDir.clean();
outputDir.clean(); // Remove unneeded ".."
mergeAndWrite(mesh, writer, set.name(), setPatch, outputDir);
}
@ -399,7 +399,7 @@ void Foam::mergeAndWrite
/ mesh.pointsInstance()
/ set.name()
);
outputDir.clean();
outputDir.clean(); // Remove unneeded ".."
mergeAndWrite(mesh, writer, set.name(), setPatch, outputDir);
}
@ -498,7 +498,7 @@ void Foam::mergeAndWrite
/ mesh.pointsInstance()
// set.name()
);
outputDir.clean();
outputDir.clean(); // Remove unneeded ".."
mkDir(outputDir);
fileName outputFile(outputDir/writer.getFileName(points, wordList()));

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -66,8 +66,8 @@ int main(int argc, char *argv[])
#include "createTime.H"
#include "createPolyMesh.H"
const fileName surfName = args[1];
const fileName setName = args[2];
const auto surfName = args.get<fileName>(1);
const auto setName = args.get<fileName>(2);
// Read surface
Info<< "Reading surface from " << surfName << endl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -45,7 +45,7 @@ using namespace Foam;
void getRootCase(fileName& casePath)
{
casePath.clean();
casePath.clean(); // Remove unneeded ".."
if (casePath.empty() || casePath == ".")
{
@ -56,7 +56,7 @@ void getRootCase(fileName& casePath)
{
// avoid relative cases ending in '..' - makes for very ugly names
casePath = cwd()/casePath;
casePath.clean();
casePath.clean(); // Remove unneeded ".."
}
}
@ -102,8 +102,8 @@ int main(int argc, char *argv[])
const bool overwrite = args.found("overwrite");
fileName masterCase = args[1];
fileName addCase = args[2];
auto masterCase = args.get<fileName>(1);
auto addCase = args.get<fileName>(2);
const word masterRegion =
args.getOrDefault<word>("masterRegion", polyMesh::defaultRegion);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -123,8 +123,8 @@ int main(int argc, char *argv[])
argList::addArgument("vtk-file", "The output vtk file");
argList args(argc, argv);
const fileName objName = args[1];
const fileName outName = args[2];
const auto objName = args.get<fileName>(1);
const auto outName = args.get<fileName>(2);
std::ifstream OBJfile(objName);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2018 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -793,7 +793,7 @@ int main(int argc, char *argv[])
if (batch)
{
const fileName batchFile = args["batch"];
const auto batchFile = args.get<fileName>("batch");
Info<< "Reading commands from file " << batchFile << endl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -373,7 +373,7 @@ int main(int argc, char *argv[])
}
}
const fileName dictFileName(args[1]);
const auto dictFileName = args.get<fileName>(1);
autoPtr<IFstream> dictFile(new IFstream(dictFileName));
if (!dictFile().good())

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -105,7 +105,7 @@ int main(int argc, char *argv[])
for (int argi = 1; argi < args.size(); ++argi)
{
const fileName libName(fileName::validate(args[argi]));
const auto libName = args.get<fileName>(argi); // with validate
if (libName.empty())
{

View File

@ -77,7 +77,7 @@ int main(int argc, char *argv[])
#include "createNamedMesh.H"
IFstream smapFile(args[1]);
IFstream smapFile(args.get<fileName>(1));
if (!smapFile.good())
{

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -150,7 +150,7 @@ int main(int argc, char *argv[])
args.readIfPresent("visual-length", lumpedPointState::visLength);
const fileName responseFile(args[1]);
const auto responseFile = args.get<fileName>(1);
// ----------------------------------------------------------------------
// Slave mode

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -286,7 +286,7 @@ int main(int argc, char *argv[])
fileName rootDirTarget(args.rootPath());
fileName caseDirTarget(args.globalCaseName());
fileName casePath = args[1];
const auto casePath = args.get<fileName>(1);
const fileName rootDirSource = casePath.path().toAbsolute();
const fileName caseDirSource = casePath.name();

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2018 OpenCFD Ltd.
Copyright (C) 2015-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -214,7 +214,7 @@ int main(int argc, char *argv[])
fileName rootDirTarget(args.rootPath());
fileName caseDirTarget(args.globalCaseName());
const fileName casePath = args[1];
const auto casePath = args.get<fileName>(1);
const fileName rootDirSource = casePath.path();
const fileName caseDirSource = casePath.name();

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -83,9 +83,9 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const fileName inFileName1 = args[1];
const fileName inFileName2 = args[2];
const fileName outFileName = args[3];
const auto inFileName1 = args.get<fileName>(1);
const auto inFileName2 = args.get<fileName>(2);
const auto outFileName = args.get<fileName>(3);
const bool addPoint = args.found("points");
const bool mergeRegions = args.found("mergeRegions");
@ -99,7 +99,7 @@ int main(int argc, char *argv[])
<< nl << endl;
Info<< "Surface : " << inFileName1<< nl
<< "Points : " << args["points"] << nl
<< "Points : " << args.get<fileName>("points") << nl
<< "Writing : " << outFileName << nl << endl;
}
else
@ -145,7 +145,7 @@ int main(int argc, char *argv[])
if (addPoint)
{
IFstream pointsFile(args["points"]);
IFstream pointsFile(args.get<fileName>("points"));
const pointField extraPoints(pointsFile);
Info<< "Additional Points:" << extraPoints.size() << endl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -335,7 +335,7 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const fileName surfFileName = args[1];
const auto surfFileName = args.get<fileName>(1);
const bool checkSelfIntersect = args.found("checkSelfIntersection");
const bool splitNonManifold = args.found("splitNonManifold");
const label outputThreshold =

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -82,10 +82,10 @@ int main(int argc, char *argv[])
);
argList args(argc, argv);
const fileName inFileName = args[1];
const scalar minLen = args.get<scalar>(2);
const scalar minQuality = args.get<scalar>(3);
const fileName outFileName = args[4];
const auto inFileName = args.get<fileName>(1);
const auto minLen = args.get<scalar>(2);
const auto minQuality = args.get<scalar>(3);
const auto outFileName = args.get<fileName>(4);
Info<< "Reading surface " << inFileName << nl
<< "Collapsing all triangles with" << nl

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -92,9 +92,9 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const fileName inFileName = args[1];
const scalar reduction = args.get<scalar>(2);
const fileName outFileName = args[3];
const auto inFileName = args.get<fileName>(1);
const auto reduction = args.get<scalar>(2);
const auto outFileName = args.get<fileName>(3);
if (reduction <= 0 || reduction > 1)
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -159,8 +159,8 @@ int main(int argc, char *argv[])
}
}
const fileName importName(args[1]);
const fileName exportName(args[2]);
const auto importName = args.get<fileName>(1);
const auto exportName = args.get<fileName>(2);
if (importName == exportName)
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd.
Copyright (C) 2015-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -106,8 +106,8 @@ int main(int argc, char *argv[])
argList args(argc, argv);
Time runTime(args.rootPath(), args.caseName());
const fileName importName(args[1]);
const fileName exportName(args[2]);
const auto importName = args.get<fileName>(1);
const auto exportName = args.get<fileName>(2);
// Disable inplace editing
if (importName == exportName)

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -72,7 +72,7 @@ int main(int argc, char *argv[])
Info<< "Reading surf ..." << endl;
meshedSurface surf1(args[1]);
meshedSurface surf1(args.get<fileName>(1));
//
// Nearest vertex

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd.
Copyright (C) 2015-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -88,7 +88,7 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const fileName surfFileName = args[1];
const auto surfFileName = args.get<fileName>(1);
const scalar density = args.getOrDefault<scalar>("density", 1);
vector refPt = Zero;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -609,12 +609,12 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
#include "createTime.H"
const word inputName(args[1]);
const scalar distance(args.get<scalar>(2));
const scalar extendFactor(args.get<scalar>(3));
const auto inputName = args.get<word>(1);
const auto distance = args.get<scalar>(2);
const auto extendFactor = args.get<scalar>(3);
const bool checkSelfIntersect = args.found("checkSelfIntersection");
const label nSmooth = args.getOrDefault<label>("nSmooth", 10);
const scalar featureAngle = args.getOrDefault<scalar>("featureAngle", 180);
const auto nSmooth = args.getOrDefault<label>("nSmooth", 10);
const auto featureAngle = args.getOrDefault<scalar>("featureAngle", 180);
const bool debug = args.found("debug");

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015 OpenCFD Ltd.
Copyright (C) 2015-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -156,11 +156,11 @@ int main(int argc, char *argv[])
);
argList args(argc, argv);
const fileName surfFileName = args[1];
const scalar lambda = args.get<scalar>(2);
const scalar mu = args.get<scalar>(3);
const label iters = args.get<label>(4);
const fileName outFileName = args[5];
const auto surfFileName = args.get<fileName>(1);
const auto lambda = args.get<scalar>(2);
const auto mu = args.get<scalar>(3);
const auto iters = args.get<label>(4);
const auto outFileName = args.get<fileName>(5);
if (lambda < 0 || lambda > 1)
{
@ -192,7 +192,7 @@ int main(int argc, char *argv[])
if (args.found("featureFile"))
{
const fileName featureFileName(args["featureFile"]);
const auto featureFileName = args.get<fileName>("featureFile");
Info<< "Reading features from " << featureFileName << " ..." << endl;
edgeMesh feMesh(featureFileName);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -181,8 +181,8 @@ int main(int argc, char *argv[])
argList args(argc, argv);
Time runTime(args.rootPath(), args.caseName());
const fileName importName(args[1]);
const fileName exportName(args[2]);
const auto importName = args.get<fileName>(1);
const auto exportName = args.get<fileName>(2);
if (importName == exportName)
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -155,8 +155,8 @@ int main(int argc, char *argv[])
argList args(argc, argv);
Time runTime(args.rootPath(), args.caseName());
const fileName exportName(args[1]);
const word importName(args.getOrDefault<word>("name", "default"));
const auto exportName = args.get<fileName>(1);
const auto importName = args.getOrDefault<word>("name", "default");
const word writeFileType
(

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -156,7 +156,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
#include "createTime.H"
const fileName userOutFileName(args[1]);
const auto userOutFileName = args.get<fileName>(1);
if (!userOutFileName.hasExt())
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -167,8 +167,8 @@ int main(int argc, char *argv[])
}
const fileName importName(args[1]);
const word exportName(args.getOrDefault<word>("name", "default"));
const auto importName = args.get<fileName>(1);
const auto exportName = args.getOrDefault<word>("name", "default");
const word readFileType
(

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -107,7 +107,7 @@ int main(int argc, char *argv[])
argList args(argc, argv);
Time runTime(args.rootPath(), args.caseName());
const fileName importName = args[1];
const auto importName = args.get<fileName>(1);
// check that reading is supported
if (!UnsortedMeshedSurface<face>::canRead(importName, true))

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -76,9 +76,9 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const fileName surfFileName = args[1];
const point visiblePoint = args.get<point>(2);
const fileName outFileName = args[3];
const auto surfFileName = args.get<fileName>(1);
const auto visiblePoint = args.get<point>(2);
const auto outFileName = args.get<fileName>(3);
const bool orientInside = args.found("inside");
const bool usePierceTest = args.found("usePierceTest");

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -67,9 +67,9 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const fileName surfFileName = args[1];
const scalar mergeTol = args.get<scalar>(2);
const fileName outFileName = args[3];
const auto surfFileName = args.get<fileName>(1);
const auto mergeTol = args.get<scalar>(2);
const auto outFileName = args.get<fileName>(3);
const scalar scaling = args.getOrDefault<scalar>("scale", -1);

View File

@ -124,8 +124,8 @@ int main(int argc, char *argv[])
#include "createTime.H"
runTime.functionObjects().off();
const fileName surfFileName = args[1];
const word distTypeName = args[2];
const auto surfFileName = args.get<fileName>(1);
const auto distTypeName = args.get<word>(2);
const label distType =
distributedTriSurfaceMesh::distributionTypeNames_[distTypeName];

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -72,8 +72,8 @@ int main(int argc, char *argv[])
);
argList args(argc, argv);
const fileName surfFileName(args[1]);
const fileName outFileName(args[2]);
const auto surfFileName = args.get<fileName>(1);
const auto outFileName = args.get<fileName>(2);
Info<< "Reading surface from " << surfFileName << " ..." << endl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -89,7 +89,7 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const fileName surfName = args[1];
const auto surfName = args.get<fileName>(1);
const fileName surfBase(surfName.lessExt());

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -59,12 +60,12 @@ int main(int argc, char *argv[])
argList::addArgument("output", "The output surface file");
argList args(argc, argv);
fileName surfFileName(args[1]);
const auto surfFileName = args.get<fileName>(1);
Info<< "Reading surface from " << surfFileName << endl;
fileName outFileName(args[2]);
fileName outFileBaseName = outFileName.lessExt();
word outExtension = outFileName.ext();
const auto outFileName = args.get<fileName>(2);
const fileName outFileBaseName = outFileName.lessExt();
const word outExtension = outFileName.ext();
// Load surface
triSurface surf(surfFileName);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -691,8 +691,8 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const fileName inSurfName = args[1];
const fileName outSurfName = args[2];
const auto inSurfName = args.get<fileName>(1);
const auto outSurfName = args.get<fileName>(2);
const bool debug = args.found("debug");
Info<< "Reading surface from " << inSurfName << endl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd.
Copyright (C) 2015-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -67,15 +67,13 @@ int main(int argc, char *argv[])
argList args(argc, argv);
Info<< "Reading dictionary " << args[1] << " ..." << endl;
IFstream dictFile(args[1]);
IFstream dictFile(args.get<fileName>(1));
dictionary meshSubsetDict(dictFile);
Info<< "Reading surface " << args[2] << " ..." << endl;
meshedSurface surf1(args.get<fileName>(2));
meshedSurface surf1(args[2]);
const fileName outFileName(args[3]);
const auto outFileName(args.get<fileName>(3));
Info<< "Original:" << endl;
surf1.writeStats(Info);
@ -217,7 +215,7 @@ int main(int argc, char *argv[])
{
const dictionary& surfDict = meshSubsetDict.subDict("surface");
const fileName surfName(surfDict.get<fileName>("name"));
const auto surfName(surfDict.get<fileName>("name"));
const volumeType::type volType =
(

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -196,7 +196,7 @@ int main(int argc, char *argv[])
#include "createTime.H"
#include "createPolyMesh.H"
const fileName surfName = args[1];
const auto surfName = args.get<fileName>(1);
Info<< "Reading surface from " << surfName << " ..." << endl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -283,8 +283,8 @@ int main(int argc, char *argv[])
}
}
const fileName importName(args[1]);
const fileName exportName(args[2]);
const auto importName = args.get<fileName>(1);
const auto exportName = args.get<fileName>(2);
const word readFileType
(

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -70,7 +71,7 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const fileName controlFileName = args[1];
const auto controlFileName = args.get<fileName>(1);
// Construct control dictionary
IFstream controlFile(controlFileName);

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -76,11 +77,18 @@ int main(int argc, char *argv[])
speciesTable species;
chemkinReader cr(species, args[1], args[3], args[2], newFormat);
chemkinReader cr
(
species,
args.get<fileName>(1), // chemkin fileName
args.get<fileName>(3), // thermo fileName
args.get<fileName>(2), // transport fileName
newFormat
);
{
// output: reactions file
OFstream reactionsFile(args[4]);
OFstream reactionsFile(args.get<fileName>(4));
reactionsFile.writeEntry("elements", cr.elementNames()) << nl;
reactionsFile.writeEntry("species", cr.species()) << nl;
@ -113,7 +121,7 @@ int main(int argc, char *argv[])
// output: thermo file
thermoDict.write(OFstream(args[5])(), false);
thermoDict.write(OFstream(args.get<fileName>(5))(), false);
Info<< "End\n" << endl;

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -73,7 +74,7 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const fileName controlFileName = args[1];
const auto controlFileName = args.get<fileName>(1);
// Construct control dictionary
IFstream controlFile(controlFileName);

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -69,7 +70,7 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const fileName controlFileName(args[1]);
const auto controlFileName = args.get<fileName>(1);
// Construct control dictionary
IFstream controlFile(controlFileName);

View File

@ -154,8 +154,8 @@ bool Foam::IOobject::fileNameComponents
// Convert explicit relative file-system path to absolute file-system path.
if (path.starts_with("./") || path.starts_with("../"))
{
fileName absPath = cwd()/path;
absPath.clean();
fileName absPath(cwd()/path);
absPath.clean(); // Remove unneeded ".."
return fileNameComponents(absPath, instance, local, name);
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -184,7 +184,7 @@ Foam::dictionary::const_searcher Foam::dictionary::csearchSlashScoped
}
else if (slash == 0)
{
// (isAbsolute)
// isAbsolute:
// Ascend to top-level
while (&dictPtr->parent_ != &dictionary::null)
{
@ -385,8 +385,9 @@ const Foam::dictionary* Foam::dictionary::cfindScopedDict
}
const dictionary* dictPtr = this;
if (fileName::isAbsolute(dictPath))
if (dictPath[0] == '/')
{
// isAbsolute:
// Ascend to top-level
while (&dictPtr->parent_ != &dictionary::null)
{
@ -394,10 +395,11 @@ const Foam::dictionary* Foam::dictionary::cfindScopedDict
}
}
fileName path = dictPath.clean();
const wordList cmpts = path.components();
fileName path(dictPath); // Work on copy
path.clean(); // Remove unneeded ".."
const wordList dictCmpts(path.components()); // Split on '/'
for (const word& cmpt : cmpts)
for (const word& cmpt : dictCmpts)
{
if (cmpt == ".")
{
@ -486,8 +488,9 @@ Foam::dictionary* Foam::dictionary::makeScopedDict(const fileName& dictPath)
}
dictionary* dictPtr = this;
if (fileName::isAbsolute(dictPath))
if (dictPath[0] == '/')
{
// isAbsolute:
// Ascend to top-level
while (&dictPtr->parent_ != &dictionary::null)
{
@ -495,14 +498,11 @@ Foam::dictionary* Foam::dictionary::makeScopedDict(const fileName& dictPath)
}
}
// Work on a copy, without any assumptions
std::string path = dictPath;
fileName::clean(path);
std::string path(dictPath); // Work on a copy
fileName::clean(path); // Remove unneeded ".."
auto dictCmpts = stringOps::split(path, '/'); // Split on '/'
// Split on '/'
auto cmpts = stringOps::split(path, '/');
for (const auto& cmpt : cmpts)
for (const auto& cmpt : dictCmpts)
{
if (cmpt == ".")
{

View File

@ -52,7 +52,7 @@ Foam::fileName Foam::functionObjects::writeFile::baseFileDir() const
// Put in undecomposed case
// (Note: gives problems for distributed data running)
fileName baseDir =
fileName baseDir
(
fileObr_.time().globalPath()
/ functionObject::outputPrefix
@ -67,7 +67,6 @@ Foam::fileName Foam::functionObjects::writeFile::baseFileDir() const
baseDir /= mesh.name();
}
}
baseDir.clean(); // Remove unneeded ".."
return baseDir;

View File

@ -715,8 +715,7 @@ void Foam::argList::setCasePaths()
if (optIter.found())
{
caseDir = fileName::validate(optIter.val());
caseDir.clean();
caseDir = fileName::validate(optIter.val()); // includes 'clean'
if (caseDir.empty() || caseDir == ".")
{
@ -1193,7 +1192,7 @@ void Foam::argList::parse
// Could also check for absolute path, but shouldn't be needed
if (adjustOpt)
{
source.clean();
source.clean(); // Remove unneeded ".."
options_.set("decomposeParDict", source);
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -378,6 +378,7 @@ public:
//- Get a value from the argument at index.
// Index 1 is the first (non-option) argument.
// For fileName type, invokes fileName::validate()
template<class T>
inline T get(const label index) const;
@ -388,6 +389,7 @@ public:
//- Get a value from the named option
// The default template parameter is string (ie, no conversion).
// For fileName type, invokes fileName::validate()
template<class T=string>
inline T get(const word& optName) const;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -221,7 +221,7 @@ namespace Foam
template<>
inline fileName argList::get<Foam::fileName>(const label index) const
{
return args_[index];
return fileName::validate(args_[index]);
}
@ -240,7 +240,7 @@ namespace Foam
template<>
inline fileName argList::get<Foam::fileName>(const word& optName) const
{
return options_[optName];
return fileName::validate(options_[optName]);
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -52,72 +52,164 @@ int Foam::fileName::allowSpaceInFileName
const Foam::fileName Foam::fileName::null;
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
Foam::fileName Foam::fileName::validate
namespace
{
// doClean:
// - remove duplicate slashes, "/./" and "/../" components.
//
// checkValid:
// - similar to stripInvalid (but silent)
//
// return True if the content changed
static bool cleanFileName
(
const std::string& s,
const bool doClean
std::string& str,
const bool doClean,
const bool checkValid
)
{
// The logic is very similar to stripInvalid,
// but silently removes bad characters
const auto maxLen = str.length();
std::string::size_type nChar = 0;
fileName out;
out.resize(s.length());
std::string::size_type len = 0;
auto iter = s.cbegin();
#ifdef _WIN32
// Preserve UNC \\server-name\...
if (s.length() > 2 && s[0] == '\\' && s[1] == '\\')
// Preserve UNC \\server\path (windows)
// - MS-windows only, but handle for other systems
// since there is no collision with this pattern
if (maxLen > 2 && str[0] == '\\' && str[1] == '\\')
{
len += 2;
++iter;
++iter;
nChar += 2;
}
#endif
char prev = 0;
for (/*nil*/; iter != s.cend(); ++iter)
auto top = std::string::npos; // Not yet found
bool changed = false;
for (auto src = nChar; src < maxLen; /*nil*/)
{
char c = *iter;
// Treat raw backslash like a path separator. There is no "normal"
// way for these to be there (except for an OS that uses them), but
// could also cause issues when writing strings, shell commands etc.
char c = str[src++];
// Treat raw backslash like a path separator.
// There is no "normal" way for these to be there
// (except for an OS that uses them), but can cause issues
// when writing strings, shell commands etc.
if (c == '\\')
{
c = '/';
str[nChar] = c;
changed = true;
}
else if (checkValid && !Foam::fileName::valid(c))
{
// Ignore invalid chars
// Could explicitly allow space character or rely on
// allowSpaceInFileName via fileName::valid()
continue;
}
// Could explicitly allow space character or rely on
// allowSpaceInFileName via fileName::valid()
if (fileName::valid(c))
if (c == '/' && top == std::string::npos)
{
if (doClean && prev == '/' && c == '/')
// Top-level slash not previously determined
top = (src-1);
}
if (doClean && prev == '/')
{
// Repeated '/' - skip it
if (c == '/')
{
// Avoid repeated '/';
continue;
}
// Only track valid chars
out[len++] = prev = c;
// Could be "/./", "/../" or a trailing "/."
if (c == '.')
{
// Trailing "/." - skip it
if (src >= maxLen)
{
break;
}
// Peek at the next character
const char c1 = str[src];
// Found "/./" - skip over it
if (c1 == '/' || c1 == '\\')
{
++src;
continue;
}
// Trailing "/.." or intermediate "/../"
if
(
c1 == '.'
&&
(
src+1 >= maxLen
|| str[src+1] == '/' || str[src+1] == '\\'
)
)
{
// Backtrack to find the parent directory
// Minimum of 3 characters: '/x/../'
// Strip it, provided it is above the top point
std::string::size_type parent;
if
(
nChar > 2
&& top != std::string::npos
&& (parent = str.rfind('/', nChar-2)) != std::string::npos
&& parent >= top
)
{
nChar = parent + 1; // Retain '/' from the parent
src += 2;
continue;
}
// Bad resolution, eg 'abc/../../'
// Retain the sequence, but move the top to avoid it being
// considered a valid parent later
top = nChar + 2;
}
}
}
str[nChar++] = prev = c;
}
if (doClean && prev == '/' && len > 1)
// Remove trailing '/'
if (doClean && nChar > 1 && str[nChar-1] == '/')
{
// Avoid trailing '/'
--len;
--nChar;
}
out.resize(len);
str.erase(nChar);
return changed || (nChar != maxLen);
}
} // End namespace Foam
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
bool Foam::fileName::clean(std::string& str)
{
return cleanFileName(str, true, false); // clean, checkValid = false
}
Foam::fileName Foam::fileName::validate
(
const std::string& str,
const bool doClean
)
{
fileName out(str, false); // copy, no stripping
cleanFileName(out, doClean, true); // checkValid = true
return out;
}
@ -288,117 +380,19 @@ Foam::fileName& Foam::fileName::toAbsolute()
{
fileName& f = *this;
f = cwd()/f;
f.clean();
f.clean(); // Remove unneeded ".."
}
return *this;
}
bool Foam::fileName::clean(std::string& str)
{
// Start with the top slash found - we are never allowed to go above it
char prev = '/';
auto top = str.find(prev);
// No slashes - nothing to do
if (top == std::string::npos)
{
return false;
}
// Number of output characters
auto nChar = top+1;
const auto maxLen = str.length();
for (auto src = nChar; src < maxLen; /*nil*/)
{
const char c = str[src++];
if (prev == '/')
{
// Repeated '/' - skip it
if (c == '/')
{
continue;
}
// Could be "/./", "/../" or a trailing "/."
if (c == '.')
{
// Trailing "/." - skip it
if (src >= maxLen)
{
break;
}
// Peek at the next character
const char c1 = str[src];
// Found "/./" - skip it
if (c1 == '/')
{
++src;
continue;
}
// Trailing "/.." or intermediate "/../"
if (c1 == '.' && (src+1 >= maxLen || str[src+1] == '/'))
{
string::size_type parent;
// Backtrack to find the parent directory
// Minimum of 3 characters: '/x/../'
// Strip it, provided it is above the top point
if
(
nChar > 2
&& (parent = str.rfind('/', nChar-2)) != string::npos
&& parent >= top
)
{
nChar = parent + 1; // Retain '/' from the parent
src += 2;
continue;
}
// Bad resolution, eg 'abc/../../'
// Retain the sequence, but move the top to avoid it being
// considered a valid parent later
top = nChar + 2;
}
}
}
str[nChar++] = prev = c;
}
// Remove trailing slash
if (nChar > 1 && str[nChar-1] == '/')
{
nChar--;
}
str.resize(nChar);
return (nChar != maxLen);
}
bool Foam::fileName::clean()
{
return fileName::clean(*this);
}
Foam::fileName Foam::fileName::clean() const
{
fileName cleaned(*this);
fileName::clean(cleaned);
return cleaned;
}
std::string Foam::fileName::nameLessExt(const std::string& str)
{
auto beg = str.rfind('/');

View File

@ -151,10 +151,10 @@ public:
//- Is this character valid for a fileName?
inline static bool valid(char c);
//- Construct fileName with no invalid characters, possibly applying
//- Construct fileName without invalid characters, possibly applying
//- other transformations such as changing the path separator,
//- removing duplicate or trailing slashes, etc.
static fileName validate(const std::string& s, const bool doClean=true);
static fileName validate(const std::string&, const bool doClean=true);
//- Join two strings with a path separator ('/' by default).
// No separator is added if either argument is an empty string or
@ -174,44 +174,48 @@ public:
//- Strip invalid characters
inline void stripInvalid();
//- Cleanup filename
//- Cleanup filename string, possibly applies other transformations
//- such as changing the path separator etc.
//
// Removes trailing \c /
// \verbatim
// / --> /
// /abc/ --> /abc
// \endverbatim
// Changes back-slash to forward-slash path separator,
// while preserving windows UNC:
// \verbatim
// \\server\abc\def --> \\server/abc/def
// \endverbatim
//
// Removes repeated slashes
// \verbatim
// /abc////def --> /abc/def
// \endverbatim
// Removes trailing slash:
// \verbatim
// / --> /
// /abc/ --> /abc
// \endverbatim
//
// Removes \c /./ (current directory)
// \verbatim
// /abc/def/./ghi/. --> /abc/def/ghi
// abc/def/./ --> abc/def
// ./abc/ --> ./abc
// \endverbatim
// Removes repeated slashes, but preserves UNC:
// \verbatim
// /abc////def --> /abc/def
// \\server\abc////def --> \\server/abc/def
// \endverbatim
//
// Removes \c /../ (parent directory)
// \verbatim
// /abc/def/../ghi/jkl/nmo/.. --> /abc/ghi/jkl
// abc/../def/ghi/../jkl --> abc/../def/jkl
// \endverbatim
// Removes \c "/./" (current directory), except for leading one:
// \verbatim
// /abc/def/./ghi/. --> /abc/def/ghi
// abc/def/./ --> abc/def
// ./abc/ --> ./abc
// \endverbatim
//
// Removes \c "/../" (parent directory), except for leading one:
// \verbatim
// /abc/def/../ghi/jkl/nmo/.. --> /abc/ghi/jkl
// abc/../def/ghi/../jkl --> abc/../def/jkl
// \endverbatim
// .
//
// \return True if the content changed
static bool clean(std::string& str);
//- Cleanup filename inplace
// \return True if any contents changed
//- Cleanup filename (inplace)
// \return True if the content changed
bool clean();
//- Cleanup filename
// \return cleaned copy of fileName
fileName clean() const;
// Interrogation
@ -223,10 +227,13 @@ public:
// \param checkGzip add an additional test for a gzip FILE
Type type(bool followLink=true, bool checkGzip=false) const;
//- Return true if string starts with a '/'
//- Return true if filename starts with a '/' or '\\'
//- or (windows-only) with a filesystem-root
inline static bool isAbsolute(const std::string& str);
//- Return true if file name is absolute (starts with a '/')
//- Return true if filename is absolute,
//- which means it starts with a '/' or '\\'
//- or (windows-only) with a filesystem-root
inline bool isAbsolute() const;
//- Convert from relative to absolute

View File

@ -135,20 +135,22 @@ inline void Foam::fileName::stripInvalid()
inline bool Foam::fileName::isAbsolute(const std::string& str)
{
return
return !str.empty() &&
(
(!str.empty() && str.front() == '/') // ie, str.starts_with('/')
#ifdef _WIN32
||
(
// Eg, d:/path or \\machine/path
(str.length() > 2) &&
(
(str[1] == ':' && str[2] == '/')
|| (str[0] == '\\' && str[1] == '\\')
)
// Starts with '/', but also accept '\\' since it will be
// converted to a generic '/' or it is part of a (windows)
// UNC '\\server-name\path'
// - accept even on non-windows systems
(str[0] == '/' || str[0] == '\\')
#ifdef _WIN32
// Filesytem root - eg, d:/path or d:\path
|| (
(str.length() > 2 && str[1] == ':')
&& (str[2] == '/' || str[2] == '\\')
)
#endif
#endif
);
}

View File

@ -699,13 +699,13 @@ void Foam::averageNeighbourFvGeometryScheme::movePoints()
// Write current non-ortho
fileName outputDir =
fileName outputDir
(
mesh_.time().globalPath()
/ functionObject::outputPrefix
/ mesh_.pointsInstance()
);
outputDir.clean();
outputDir.clean(); // Remove unneeded ".."
writerPtr = surfaceWriter::New
(
"ensight" //"vtk"

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2020 OpenCFD Ltd.
Copyright (C) 2015-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -90,10 +90,10 @@ Foam::fileName Foam::functionObjects::externalCoupled::groupDir
fileName result
(
commsDir
/regionGroupName
/string::validate<fileName>(groupName)
/ regionGroupName
/ word::validate(groupName)
);
result.clean();
result.clean(); // Remove unneeded ".."
return result;
}

View File

@ -195,7 +195,7 @@ bool Foam::functionObjects::dataCloud::read(const dictionary& dict)
// Standard postProcessing/ naming
directory_ = time_.globalPath()/functionObject::outputPrefix/name();
}
directory_.clean();
directory_.clean(); // Remove unneeded ".."
return true;
}

View File

@ -449,7 +449,7 @@ bool Foam::functionObjects::vtkCloud::read(const dictionary& dict)
// Standard postProcessing/ naming
directory_ = time_.globalPath()/functionObject::outputPrefix/name();
}
directory_.clean();
directory_.clean(); // Remove unneeded ".."
return true;
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -167,11 +167,10 @@ bool Foam::functionObjects::abort::read(const dictionary& dict)
if (dict.readIfPresent("file", file_))
{
file_.expand();
if (!file_.isAbsolute() && file_.size())
if (!file_.empty() && !file_.isAbsolute())
{
file_ = time_.globalPath()/file_;
file_.clean();
file_.clean(); // Remove unneeded ".."
}
}
@ -179,7 +178,7 @@ bool Foam::functionObjects::abort::read(const dictionary& dict)
if (file_.empty())
{
file_ = time_.globalPath()/name();
file_.clean();
file_.clean(); // Remove unneeded ".."
}
triggered_ = false;

View File

@ -175,7 +175,7 @@ bool Foam::functionObjects::ensightWrite::read(const dictionary& dict)
// Standard postProcessing/ naming
outputDir_ = time_.globalPath()/functionObject::outputPrefix/name();
}
outputDir_.clean();
outputDir_.clean(); // Remove unneeded ".."
return true;
}

Some files were not shown because too many files have changed in this diff Show More