ENH: IOobject: allow absolute instance

This commit is contained in:
mattijs 2012-12-05 12:06:50 +00:00
parent e3c9dddd26
commit d2cfb24ef8

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -40,7 +40,7 @@ defineTypeNameAndDebug(Foam::IOobject, 0);
// ----- ------
// "foo" ("", "", "foo")
// "foo/bar" ("foo", "", "bar")
// "/XXX" ERROR - no absolute path
// "/XXX/bar" ("/XXX", "", "bar")
// "foo/bar/" ERROR - no name
// "foo/xxx/bar" ("foo", "xxx", "bar")
// "foo/xxx/yyy/bar" ("foo", "xxx/yyy", "bar")
@ -64,14 +64,6 @@ bool Foam::IOobject::IOobject::fileNameComponents
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('/');
if (first == string::npos)
@ -81,6 +73,15 @@ bool Foam::IOobject::IOobject::fileNameComponents
// check afterwards
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
{
instance = path.substr(0, first);
@ -245,9 +246,16 @@ const Foam::fileName& Foam::IOobject::rootPath() const
Foam::fileName Foam::IOobject::path() const
{
if (instance().isAbsolute())
{
return instance();
}
else
{
return rootPath()/caseName()/instance()/db_.dbDir()/local();
}
}
Foam::fileName Foam::IOobject::path
@ -256,11 +264,26 @@ Foam::fileName Foam::IOobject::path
const fileName& local
) const
{
//Note: can only be called with relative instance since is word type
return rootPath()/caseName()/instance/db_.dbDir()/local;
}
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 objectPath = path/name();
@ -292,7 +315,10 @@ Foam::fileName Foam::IOobject::filePath() const
if (!isDir(path))
{
word newInstancePath = time().findInstancePath(instant(instance()));
word newInstancePath = time().findInstancePath
(
instant(instance())
);
if (newInstancePath.size())
{
@ -312,6 +338,7 @@ Foam::fileName Foam::IOobject::filePath() const
return fileName::null;
}
}
Foam::Istream* Foam::IOobject::objectStream()