findInstance for directories

This commit is contained in:
mattijs
2009-02-06 13:11:30 +00:00
parent 07ed75e8e3
commit d7b321bf86
2 changed files with 38 additions and 20 deletions

View File

@ -283,10 +283,11 @@ public:
//- Return the location of "dir" containing the file "name". //- Return the location of "dir" containing the file "name".
// (Used in reading mesh data) // (Used in reading mesh data)
// If name is null search for a directory "dir"
word findInstance word findInstance
( (
const fileName& dir, const fileName& dir,
const word& name, const word& name = word::null,
const IOobject::readOption rOpt = IOobject::MUST_READ const IOobject::readOption rOpt = IOobject::MUST_READ
) const; ) const;

View File

@ -23,7 +23,9 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description Description
Return the location of "directory" containing the file "name". If "name" is empty: return the location of "directory"
If "name" is not empty: return the location of "directory" containing the
file "name".
Used in reading mesh data. Used in reading mesh data.
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -43,15 +45,20 @@ Foam::word Foam::Time::findInstance
// Is the mesh data in the current time directory ? // Is the mesh data in the current time directory ?
if if
( (
file(path()/timeName()/dir/name) (name.empty() && Foam::dir(path()/timeName()/dir))
&& IOobject(name, timeName(), dir, *this).headerOk() ||
(
!name.empty()
&& file(path()/timeName()/dir/name)
&& IOobject(name, timeName(), dir, *this).headerOk()
)
) )
{ {
if (debug) if (debug)
{ {
Info<< "Time::findInstance(const word& dir, const word& name) : " Info<< "Time::findInstance(const word&, const word&) : "
<< "reading " << name << "found " << name
<< " from " << timeName()/dir << " in " << timeName()/dir
<< endl; << endl;
} }
@ -81,16 +88,21 @@ Foam::word Foam::Time::findInstance
{ {
if if
( (
file(path()/ts[j].name()/dir/name) (name.empty() && Foam::dir(path()/ts[j].name()/dir))
&& IOobject(name, ts[j].name(), dir, *this).headerOk() ||
(
!name.empty()
&& file(path()/ts[j].name()/dir/name)
&& IOobject(name, ts[j].name(), dir, *this).headerOk()
)
) )
{ {
if (debug) if (debug)
{ {
Info<< "Time::findInstance(const word& dir, " Info<< "Time::findInstance(const word&, "
<< "const word& name) : " << "const word&) : "
<< "reading " << name << "found " << name
<< " from " << ts[j].name()/dir << " in " << ts[j].name()/dir
<< endl; << endl;
} }
@ -109,16 +121,20 @@ Foam::word Foam::Time::findInstance
if if
( (
file(path()/constant()/dir/name) (name.empty() && Foam::dir(path()/constant()/dir))
&& IOobject(name, constant(), dir, *this).headerOk() || (
!name.empty()
&& file(path()/constant()/dir/name)
&& IOobject(name, constant(), dir, *this).headerOk()
)
) )
{ {
if (debug) if (debug)
{ {
Info<< "Time::findInstance(const word& dir, " Info<< "Time::findInstance(const word&, "
<< "const word& name) : " << "const word&) : "
<< "reading " << name << "found " << name
<< " from " << constant()/dir << " in " << constant()/dir
<< endl; << endl;
} }
@ -127,7 +143,7 @@ Foam::word Foam::Time::findInstance
if (rOpt == IOobject::MUST_READ) if (rOpt == IOobject::MUST_READ)
{ {
FatalErrorIn("Time::findInstance(const word& dir, const word& name)") FatalErrorIn("Time::findInstance(const word&, const word&)")
<< "Cannot find file \"" << name << "\" in directory " << "Cannot find file \"" << name << "\" in directory "
<< constant()/dir << constant()/dir
<< exit(FatalError); << exit(FatalError);
@ -136,4 +152,5 @@ Foam::word Foam::Time::findInstance
return constant(); return constant();
} }
// ************************************************************************* // // ************************************************************************* //