mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add global (serial) path accessor to IOobject (#3007)
- new methods added to IOobject to ease mixed (serial vs parallel)
file locations. Some redirect to Time, others are defined for
IOobject only.
| "normal" (serial/parallel) | "global" (serial locations) |
| ---------------------------|-----------------------------|
| caseName() | globalCaseName() |
| path() | globalPath() *new* |
| path(...) | globalPath(...) *new* |
| objectPath() | globalObjectPath() *new* |
This commit is contained in:
@ -141,6 +141,31 @@ namespace Foam
|
|||||||
//! \endcond
|
//! \endcond
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
// A file is 'outside' of the case if it has been specified using an
|
||||||
|
// absolute path.
|
||||||
|
//
|
||||||
|
// Like 'fileName::isAbsolute' but with even fewer checks since the
|
||||||
|
// swapping of '\\' with '/' will have already occurred.
|
||||||
|
static inline bool file_isOutsideCase(const std::string& str)
|
||||||
|
{
|
||||||
|
return !str.empty() &&
|
||||||
|
(
|
||||||
|
// Starts with '/'
|
||||||
|
(str[0] == '/')
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
// Filesytem root - eg, d:/path
|
||||||
|
|| (
|
||||||
|
(str.length() > 2 && str[1] == ':')
|
||||||
|
&& (str[2] == '/')
|
||||||
|
)
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
bool Foam::IOobject::fileNameComponents
|
bool Foam::IOobject::fileNameComponents
|
||||||
@ -441,34 +466,28 @@ const Foam::Time& Foam::IOobject::time() const noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const Foam::fileName& Foam::IOobject::rootPath() const
|
const Foam::fileName& Foam::IOobject::rootPath() const noexcept
|
||||||
{
|
{
|
||||||
return time().rootPath();
|
return time().rootPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const Foam::fileName& Foam::IOobject::caseName() const
|
const Foam::fileName& Foam::IOobject::caseName() const noexcept
|
||||||
{
|
{
|
||||||
return time().caseName();
|
return time().caseName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const Foam::fileName& Foam::IOobject::globalCaseName() const noexcept
|
||||||
|
{
|
||||||
|
return time().globalCaseName();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::fileName Foam::IOobject::path() const
|
Foam::fileName Foam::IOobject::path() const
|
||||||
{
|
{
|
||||||
// A file is 'outside' of the case if it has been specified using an
|
if (file_isOutsideCase(instance()))
|
||||||
// absolute path
|
|
||||||
|
|
||||||
const auto first = instance().find('/');
|
|
||||||
|
|
||||||
if
|
|
||||||
(
|
|
||||||
first == 0
|
|
||||||
#ifdef _WIN32
|
|
||||||
|| (first == 2 && instance()[1] == ':') // Eg, d:/path
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
// Absolute path (starts with '/' or 'd:/')
|
|
||||||
return instance();
|
return instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,6 +495,17 @@ Foam::fileName Foam::IOobject::path() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::fileName Foam::IOobject::globalPath() const
|
||||||
|
{
|
||||||
|
if (file_isOutsideCase(instance()))
|
||||||
|
{
|
||||||
|
return instance();
|
||||||
|
}
|
||||||
|
|
||||||
|
return rootPath()/globalCaseName()/instance()/db_.dbDir()/local();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::fileName Foam::IOobject::path
|
Foam::fileName Foam::IOobject::path
|
||||||
(
|
(
|
||||||
const word& instance,
|
const word& instance,
|
||||||
@ -487,22 +517,21 @@ Foam::fileName Foam::IOobject::path
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::fileName Foam::IOobject::globalPath
|
||||||
|
(
|
||||||
|
const word& instance,
|
||||||
|
const fileName& local
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
// Note: can only be called with relative instance since is word type
|
||||||
|
return rootPath()/globalCaseName()/instance/db_.dbDir()/local;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::fileName Foam::IOobject::objectRelPath() const
|
Foam::fileName Foam::IOobject::objectRelPath() const
|
||||||
{
|
{
|
||||||
// A file is 'outside' of the case if it has been specified using an
|
if (file_isOutsideCase(instance()))
|
||||||
// absolute path
|
|
||||||
|
|
||||||
const auto first = instance().find('/');
|
|
||||||
|
|
||||||
if
|
|
||||||
(
|
|
||||||
first == 0
|
|
||||||
#ifdef _WIN32
|
|
||||||
|| (first == 2 && instance()[1] == ':') // Eg, d:/path
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
// Absolute path (starts with '/' or 'd:/')
|
|
||||||
return instance()/name();
|
return instance()/name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -541,10 +541,13 @@ public:
|
|||||||
inline word member() const;
|
inline word member() const;
|
||||||
|
|
||||||
//- Return the Time::rootPath()
|
//- Return the Time::rootPath()
|
||||||
const fileName& rootPath() const;
|
const fileName& rootPath() const noexcept;
|
||||||
|
|
||||||
//- Return the Time::caseName()
|
//- Return the Time::caseName()
|
||||||
const fileName& caseName() const;
|
const fileName& caseName() const noexcept;
|
||||||
|
|
||||||
|
//- Return the Time::globalCaseName()
|
||||||
|
const fileName& globalCaseName() const noexcept;
|
||||||
|
|
||||||
//- Read access to instance path component
|
//- Read access to instance path component
|
||||||
inline const fileName& instance() const noexcept;
|
inline const fileName& instance() const noexcept;
|
||||||
@ -555,9 +558,12 @@ public:
|
|||||||
//- Read access to local path component
|
//- Read access to local path component
|
||||||
inline const fileName& local() const noexcept;
|
inline const fileName& local() const noexcept;
|
||||||
|
|
||||||
//- The complete path
|
//- The complete path for the object (with instance, local,...).
|
||||||
fileName path() const;
|
fileName path() const;
|
||||||
|
|
||||||
|
//- The complete global path for the object (with instance, local,...)
|
||||||
|
fileName globalPath() const;
|
||||||
|
|
||||||
//- The complete path with alternative instance and local
|
//- The complete path with alternative instance and local
|
||||||
fileName path
|
fileName path
|
||||||
(
|
(
|
||||||
@ -565,9 +571,19 @@ public:
|
|||||||
const fileName& local = fileName::null
|
const fileName& local = fileName::null
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
//- The complete global path with alternative instance and local
|
||||||
|
fileName globalPath
|
||||||
|
(
|
||||||
|
const word& instance,
|
||||||
|
const fileName& local = fileName::null
|
||||||
|
) const;
|
||||||
|
|
||||||
//- The complete path + object name
|
//- The complete path + object name
|
||||||
inline fileName objectPath() const;
|
inline fileName objectPath() const;
|
||||||
|
|
||||||
|
//- The complete global path + object name
|
||||||
|
inline fileName globalObjectPath() const;
|
||||||
|
|
||||||
//- The object path relative to the root
|
//- The object path relative to the root
|
||||||
fileName objectRelPath() const;
|
fileName objectRelPath() const;
|
||||||
|
|
||||||
|
|||||||
@ -294,6 +294,12 @@ inline Foam::fileName Foam::IOobject::objectPath() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::fileName Foam::IOobject::globalObjectPath() const
|
||||||
|
{
|
||||||
|
return globalPath()/name();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Error Handling
|
// Error Handling
|
||||||
|
|
||||||
inline bool Foam::IOobject::good() const noexcept
|
inline bool Foam::IOobject::good() const noexcept
|
||||||
|
|||||||
Reference in New Issue
Block a user