ENH: IOobject: allow absolute instance
This commit is contained in:
parent
e3c9dddd26
commit
d2cfb24ef8
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -40,7 +40,7 @@ defineTypeNameAndDebug(Foam::IOobject, 0);
|
|||||||
// ----- ------
|
// ----- ------
|
||||||
// "foo" ("", "", "foo")
|
// "foo" ("", "", "foo")
|
||||||
// "foo/bar" ("foo", "", "bar")
|
// "foo/bar" ("foo", "", "bar")
|
||||||
// "/XXX" ERROR - no absolute path
|
// "/XXX/bar" ("/XXX", "", "bar")
|
||||||
// "foo/bar/" ERROR - no name
|
// "foo/bar/" ERROR - no name
|
||||||
// "foo/xxx/bar" ("foo", "xxx", "bar")
|
// "foo/xxx/bar" ("foo", "xxx", "bar")
|
||||||
// "foo/xxx/yyy/bar" ("foo", "xxx/yyy", "bar")
|
// "foo/xxx/yyy/bar" ("foo", "xxx/yyy", "bar")
|
||||||
@ -64,14 +64,6 @@ bool Foam::IOobject::IOobject::fileNameComponents
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path.isAbsolute())
|
|
||||||
{
|
|
||||||
// called with absolute path
|
|
||||||
WarningIn("IOobject::fileNameComponents(const fileName&, ...)")
|
|
||||||
<< "called with absolute path: " << path << "\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
string::size_type first = path.find('/');
|
string::size_type first = path.find('/');
|
||||||
|
|
||||||
if (first == string::npos)
|
if (first == string::npos)
|
||||||
@ -81,6 +73,15 @@ bool Foam::IOobject::IOobject::fileNameComponents
|
|||||||
// check afterwards
|
// check afterwards
|
||||||
name.string::operator=(path);
|
name.string::operator=(path);
|
||||||
}
|
}
|
||||||
|
else if (first == 0)
|
||||||
|
{
|
||||||
|
// Leading '/'. Absolute fileName
|
||||||
|
string::size_type last = path.rfind('/');
|
||||||
|
instance = path.substr(0, last);
|
||||||
|
|
||||||
|
// check afterwards
|
||||||
|
name.string::operator=(path.substr(last+1));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
instance = path.substr(0, first);
|
instance = path.substr(0, first);
|
||||||
@ -246,7 +247,14 @@ const Foam::fileName& Foam::IOobject::rootPath() const
|
|||||||
|
|
||||||
Foam::fileName Foam::IOobject::path() const
|
Foam::fileName Foam::IOobject::path() const
|
||||||
{
|
{
|
||||||
|
if (instance().isAbsolute())
|
||||||
|
{
|
||||||
|
return instance();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return rootPath()/caseName()/instance()/db_.dbDir()/local();
|
return rootPath()/caseName()/instance()/db_.dbDir()/local();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -256,12 +264,27 @@ Foam::fileName Foam::IOobject::path
|
|||||||
const fileName& local
|
const fileName& local
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
|
//Note: can only be called with relative instance since is word type
|
||||||
return rootPath()/caseName()/instance/db_.dbDir()/local;
|
return rootPath()/caseName()/instance/db_.dbDir()/local;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::fileName Foam::IOobject::filePath() const
|
Foam::fileName Foam::IOobject::filePath() const
|
||||||
{
|
{
|
||||||
|
if (instance().isAbsolute())
|
||||||
|
{
|
||||||
|
fileName objectPath = instance()/name();
|
||||||
|
if (isFile(objectPath))
|
||||||
|
{
|
||||||
|
return objectPath;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return fileName::null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
fileName path = this->path();
|
fileName path = this->path();
|
||||||
fileName objectPath = path/name();
|
fileName objectPath = path/name();
|
||||||
|
|
||||||
@ -292,7 +315,10 @@ Foam::fileName Foam::IOobject::filePath() const
|
|||||||
|
|
||||||
if (!isDir(path))
|
if (!isDir(path))
|
||||||
{
|
{
|
||||||
word newInstancePath = time().findInstancePath(instant(instance()));
|
word newInstancePath = time().findInstancePath
|
||||||
|
(
|
||||||
|
instant(instance())
|
||||||
|
);
|
||||||
|
|
||||||
if (newInstancePath.size())
|
if (newInstancePath.size())
|
||||||
{
|
{
|
||||||
@ -311,6 +337,7 @@ Foam::fileName Foam::IOobject::filePath() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
return fileName::null;
|
return fileName::null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user