mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: adjust fileName methods for similarity to std::filesystem::path
- stem(), replace_name(), replace_ext(), remove_ext() etc
- string::contains() method - similar to C++23 method
Eg,
if (keyword.contains('/')) ...
vs
if (keyword.find('/') != std::string::npos) ...
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -201,11 +201,11 @@ Foam::fileFormats::ABAQUSCore::abaqusToFoamFaceAddr()
|
||||
|
||||
|
||||
Foam::fileFormats::ABAQUSCore::shapeType
|
||||
Foam::fileFormats::ABAQUSCore::getElementType(const std::string& elemTypeName)
|
||||
Foam::fileFormats::ABAQUSCore::getElementType(const string& elemTypeName)
|
||||
{
|
||||
// Check for element-type
|
||||
#undef checkElemType
|
||||
#define checkElemType(test) (elemTypeName.find(test) != std::string::npos)
|
||||
// Check for element-type.
|
||||
#undef checkElemType
|
||||
#define checkElemType(Name) elemTypeName.contains(Name)
|
||||
|
||||
if
|
||||
(
|
||||
|
||||
@ -76,8 +76,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef ABAQUSCore_H
|
||||
#define ABAQUSCore_H
|
||||
#ifndef Foam_ABAQUSCore_H
|
||||
#define Foam_ABAQUSCore_H
|
||||
|
||||
#include "Fstream.H"
|
||||
#include "Enum.H"
|
||||
@ -121,7 +121,7 @@ public:
|
||||
//- Classify named element type (eg, S4R) to known/supported
|
||||
//- element types.
|
||||
// The input string must be Uppercase!
|
||||
static shapeType getElementType(const std::string& elemTypeName);
|
||||
static shapeType getElementType(const string& elemTypeName);
|
||||
|
||||
//- The number of points associated with the element type
|
||||
inline static int nPoints(shapeType tag)
|
||||
|
||||
@ -48,7 +48,7 @@ Foam::ensightReadFile::detectBinaryHeader(const fileName& pathname)
|
||||
istream& iss = is.stdStream();
|
||||
|
||||
// Binary string is *exactly* 80 characters
|
||||
std::string buf(size_t(80), '\0');
|
||||
string buf(size_t(80), '\0');
|
||||
iss.read(&buf[0], 80);
|
||||
|
||||
if (!iss)
|
||||
@ -64,12 +64,8 @@ Foam::ensightReadFile::detectBinaryHeader(const fileName& pathname)
|
||||
buf.erase(endp);
|
||||
}
|
||||
|
||||
// Contains "C Binary" ?
|
||||
if
|
||||
(
|
||||
(buf.find("Binary") == std::string::npos)
|
||||
&& (buf.find("binary") == std::string::npos)
|
||||
)
|
||||
// ASCII if it does not contain "C Binary"
|
||||
if (!buf.contains("Binary") && !buf.contains("binary"))
|
||||
{
|
||||
fmt = IOstreamOption::ASCII;
|
||||
}
|
||||
|
||||
@ -161,8 +161,8 @@ void Foam::glTF::scene::addToAnimation
|
||||
|
||||
void Foam::glTF::scene::write(const fileName& outputFile)
|
||||
{
|
||||
fileName jsonFile(outputFile.lessExt());
|
||||
jsonFile.ext("gltf");
|
||||
fileName jsonFile(outputFile);
|
||||
jsonFile.replace_ext("gltf");
|
||||
|
||||
// Note: called on master only
|
||||
|
||||
@ -178,8 +178,8 @@ void Foam::glTF::scene::write(const fileName& outputFile)
|
||||
|
||||
void Foam::glTF::scene::write(Ostream& os)
|
||||
{
|
||||
fileName binFile(os.name().lessExt());
|
||||
binFile.ext("bin");
|
||||
fileName binFile(os.name());
|
||||
binFile.replace_ext("bin");
|
||||
|
||||
// Write binary file
|
||||
// Note: using stdStream
|
||||
|
||||
@ -78,8 +78,8 @@ void Foam::glTF::sceneWriter::open(const fileName& outputFile)
|
||||
{
|
||||
close();
|
||||
|
||||
fileName jsonFile(outputFile.lessExt());
|
||||
jsonFile.ext("gltf");
|
||||
fileName jsonFile(outputFile);
|
||||
jsonFile.replace_ext("gltf");
|
||||
|
||||
// Note: called on master only
|
||||
if (!isDir(jsonFile.path()))
|
||||
|
||||
@ -72,7 +72,7 @@ bool Foam::fileFormats::STLCore::isBinaryName
|
||||
return
|
||||
(
|
||||
format == STLFormat::UNKNOWN
|
||||
? filename.hasExt("stlb")
|
||||
? filename.has_ext("stlb")
|
||||
: format == STLFormat::BINARY
|
||||
);
|
||||
}
|
||||
@ -236,7 +236,7 @@ void Foam::fileFormats::STLCore::writeBinaryHeader
|
||||
char header[STLHeaderSize];
|
||||
sprintf(header, "STL binary file %u facets", nTris);
|
||||
|
||||
// avoid trailing junk
|
||||
// Fill trailing with zeroes (to avoid writing junk)
|
||||
for (size_t i = strlen(header); i < STLHeaderSize; ++i)
|
||||
{
|
||||
header[i] = 0;
|
||||
|
||||
@ -334,16 +334,15 @@ bool Foam::vtk::fileWriter::open(const fileName& file, bool parallel)
|
||||
if
|
||||
(
|
||||
legacy()
|
||||
? outputFile_.hasExt(vtk::fileExtension[contentType_])
|
||||
: outputFile_.hasExt(vtk::legacy::fileExtension)
|
||||
? outputFile_.has_ext(vtk::fileExtension[contentType_])
|
||||
: outputFile_.has_ext(vtk::legacy::fileExtension)
|
||||
)
|
||||
{
|
||||
// Inappropriate extension. Legacy instead of xml, or vice versa.
|
||||
|
||||
outputFile_.removeExt();
|
||||
outputFile_.remove_ext();
|
||||
}
|
||||
|
||||
if (!outputFile_.hasExt(ext()))
|
||||
if (!outputFile_.has_ext(ext()))
|
||||
{
|
||||
// Add extension if required
|
||||
outputFile_.ext(ext());
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -162,7 +162,7 @@ Foam::Ostream& Foam::vtk::seriesWriter::print
|
||||
// stem = "file"
|
||||
// ext = ".vtm"
|
||||
|
||||
const word stem = base.nameLessExt();
|
||||
const word stem = base.stem();
|
||||
const word ext = "." + base.ext();
|
||||
|
||||
// Begin file-series (JSON)
|
||||
@ -240,7 +240,7 @@ void Foam::vtk::seriesWriter::write
|
||||
|
||||
autoPtr<OFstream> osPtr =
|
||||
(
|
||||
seriesName.hasExt("series")
|
||||
seriesName.has_ext("series")
|
||||
? autoPtr<OFstream>::New(seriesName)
|
||||
: autoPtr<OFstream>::New(seriesName + ".series")
|
||||
);
|
||||
@ -260,7 +260,7 @@ void Foam::vtk::seriesWriter::write
|
||||
|
||||
autoPtr<OFstream> osPtr =
|
||||
(
|
||||
seriesName.hasExt("series")
|
||||
seriesName.has_ext("series")
|
||||
? autoPtr<OFstream>::New(seriesName)
|
||||
: autoPtr<OFstream>::New(seriesName + ".series")
|
||||
);
|
||||
@ -372,7 +372,7 @@ Foam::label Foam::vtk::seriesWriter::load
|
||||
clear();
|
||||
|
||||
fileName seriesFile(seriesName);
|
||||
if (!seriesFile.hasExt("series"))
|
||||
if (!seriesFile.has_ext("series"))
|
||||
{
|
||||
seriesFile.ext("series");
|
||||
}
|
||||
@ -597,12 +597,12 @@ Foam::label Foam::vtk::seriesWriter::scan
|
||||
|
||||
fileName seriesFile(seriesName);
|
||||
|
||||
if (seriesName.hasExt("series"))
|
||||
if (seriesName.has_ext("series"))
|
||||
{
|
||||
seriesFile.removeExt();
|
||||
seriesFile.remove_ext();
|
||||
}
|
||||
|
||||
const word stem = seriesFile.nameLessExt();
|
||||
const word stem = seriesFile.stem();
|
||||
const word ext = seriesFile.ext();
|
||||
|
||||
// Accept "fileN.ext", "fileNN.ext", but reject "file.ext"
|
||||
@ -614,7 +614,7 @@ Foam::label Foam::vtk::seriesWriter::scan
|
||||
return
|
||||
(
|
||||
minLen < file.length()
|
||||
&& file.hasExt(ext) && file.starts_with(stem)
|
||||
&& file.has_ext(ext) && file.starts_with(stem)
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -56,7 +56,7 @@ inline bool Foam::vtk::seriesWriter::append(const fileNameInstant& inst)
|
||||
inline bool Foam::vtk::seriesWriter::append(fileNameInstant&& inst)
|
||||
{
|
||||
// Strip out path before saving
|
||||
inst.name().removePath();
|
||||
inst.name().remove_path();
|
||||
|
||||
return appendCheck(inst);
|
||||
}
|
||||
@ -80,7 +80,7 @@ inline bool Foam::vtk::seriesWriter::append
|
||||
)
|
||||
{
|
||||
// Strip out path before saving
|
||||
file.removePath();
|
||||
file.remove_path();
|
||||
|
||||
return appendCheck(fileNameInstant(timeValue, std::move(file)));
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -421,7 +421,7 @@ bool Foam::vtk::vtmWriter::append(const fileName& file)
|
||||
{
|
||||
if (autoName_)
|
||||
{
|
||||
return append(fileName::nameLessExt(file), file);
|
||||
return append(fileName::stem(file), file);
|
||||
}
|
||||
|
||||
return append(word::null, file);
|
||||
@ -436,7 +436,7 @@ bool Foam::vtk::vtmWriter::append
|
||||
{
|
||||
if (autoName_)
|
||||
{
|
||||
return append(fileName::nameLessExt(file), file, contentType);
|
||||
return append(fileName::stem(file), file, contentType);
|
||||
}
|
||||
|
||||
return append(word::null, file, contentType);
|
||||
@ -471,7 +471,7 @@ bool Foam::vtk::vtmWriter::append
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file.hasExt(vtk::fileExtension[contentType]))
|
||||
if (file.has_ext(vtk::fileExtension[contentType]))
|
||||
{
|
||||
entries_.append(vtmEntry::entry(name, file));
|
||||
}
|
||||
@ -582,7 +582,7 @@ Foam::label Foam::vtk::vtmWriter::write(const fileName& file)
|
||||
|
||||
mkDir(file.path());
|
||||
|
||||
if (file.hasExt(ext()))
|
||||
if (file.has_ext(ext()))
|
||||
{
|
||||
os_.open(file);
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -256,7 +256,7 @@ Foam::vtk::formatter& Foam::vtk::formatter::DataSet
|
||||
{
|
||||
if (autoName)
|
||||
{
|
||||
xmlAttr("name", fileName::nameLessExt(file));
|
||||
xmlAttr("name", fileName::stem(file));
|
||||
}
|
||||
xmlAttr("file", file);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user