mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
moved fileName::IOobjectComponents -> IOobject::fileNameComponents
This commit is contained in:
@ -32,6 +32,7 @@ Description
|
|||||||
|
|
||||||
#include "fileName.H"
|
#include "fileName.H"
|
||||||
#include "SubList.H"
|
#include "SubList.H"
|
||||||
|
#include "IOobject.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
#include "OSspecific.H"
|
#include "OSspecific.H"
|
||||||
|
|
||||||
@ -61,7 +62,8 @@ int main()
|
|||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
// try with different combination
|
// try with different combination
|
||||||
for (label start = 0; start < wrdList.size(); ++start)
|
// The final one should emit warnings
|
||||||
|
for (label start = 0; start <= wrdList.size(); ++start)
|
||||||
{
|
{
|
||||||
fileName instance, local;
|
fileName instance, local;
|
||||||
word name;
|
word name;
|
||||||
@ -69,26 +71,28 @@ int main()
|
|||||||
fileName path(SubList<word>(wrdList, wrdList.size()-start, start));
|
fileName path(SubList<word>(wrdList, wrdList.size()-start, start));
|
||||||
fileName path2 = "." / path;
|
fileName path2 = "." / path;
|
||||||
|
|
||||||
path.IOobjectComponents
|
IOobject::fileNameComponents
|
||||||
(
|
(
|
||||||
|
path,
|
||||||
instance,
|
instance,
|
||||||
local,
|
local,
|
||||||
name
|
name
|
||||||
);
|
);
|
||||||
|
|
||||||
Info<< "IOobjectComponents for " << path << nl
|
Info<< "IOobject::fileNameComponents for " << path << nl
|
||||||
<< " instance = " << instance << nl
|
<< " instance = " << instance << nl
|
||||||
<< " local = " << local << nl
|
<< " local = " << local << nl
|
||||||
<< " name = " << name << endl;
|
<< " name = " << name << endl;
|
||||||
|
|
||||||
path2.IOobjectComponents
|
IOobject::fileNameComponents
|
||||||
(
|
(
|
||||||
|
path2,
|
||||||
instance,
|
instance,
|
||||||
local,
|
local,
|
||||||
name
|
name
|
||||||
);
|
);
|
||||||
|
|
||||||
Info<< "IOobjectComponents for " << path2 << nl
|
Info<< "IOobject::fileNameComponents for " << path2 << nl
|
||||||
<< " instance = " << instance << nl
|
<< " instance = " << instance << nl
|
||||||
<< " local = " << local << nl
|
<< " local = " << local << nl
|
||||||
<< " name = " << name << endl;
|
<< " name = " << name << endl;
|
||||||
|
|||||||
@ -35,6 +35,85 @@ namespace Foam
|
|||||||
defineTypeNameAndDebug(IOobject, 0);
|
defineTypeNameAndDebug(IOobject, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
// Return components following the IOobject requirements
|
||||||
|
//
|
||||||
|
// behaviour
|
||||||
|
// input IOobject(instance, local, name)
|
||||||
|
// ----- ------
|
||||||
|
// "foo" ("", "", "foo")
|
||||||
|
// "foo/bar" ("foo", "", "bar")
|
||||||
|
// "/XXX" ERROR - no absolute path
|
||||||
|
// "foo/bar/" ERROR - no name
|
||||||
|
// "foo/xxx/bar" ("foo", "xxx", "bar")
|
||||||
|
// "foo/xxx/yyy/bar" ("foo", "xxx/yyy", "bar")
|
||||||
|
bool Foam::IOobject::IOobject::fileNameComponents
|
||||||
|
(
|
||||||
|
const fileName& path,
|
||||||
|
fileName& instance,
|
||||||
|
fileName& local,
|
||||||
|
word& name
|
||||||
|
)
|
||||||
|
{
|
||||||
|
instance.clear();
|
||||||
|
local.clear();
|
||||||
|
name.clear();
|
||||||
|
|
||||||
|
// called with directory
|
||||||
|
if (::Foam::dir(path))
|
||||||
|
{
|
||||||
|
WarningIn("IOobject::fileNameComponents(const fileName&, ...)")
|
||||||
|
<< " called with directory: " << path << "\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
string::size_type first = path.find('/');
|
||||||
|
|
||||||
|
if (first == 0)
|
||||||
|
{
|
||||||
|
// called with absolute path
|
||||||
|
WarningIn("IOobject::fileNameComponents(const fileName&, ...)")
|
||||||
|
<< "called with absolute path: " << path << "\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (first == string::npos)
|
||||||
|
{
|
||||||
|
// no '/' found - no instance or local
|
||||||
|
|
||||||
|
// check afterwards
|
||||||
|
name.string::operator=(path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
instance = path.substr(0, first);
|
||||||
|
|
||||||
|
string::size_type last = path.rfind('/');
|
||||||
|
if (last > first)
|
||||||
|
{
|
||||||
|
// with local
|
||||||
|
local = path.substr(first+1, last-first-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// check afterwards
|
||||||
|
name.string::operator=(path.substr(last+1));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// check for valid (and stripped) name, regardless of the debug level
|
||||||
|
if (name.empty() || string::stripInvalid<word>(name))
|
||||||
|
{
|
||||||
|
WarningIn("IOobject::fileNameComponents(const fileName&, ...)")
|
||||||
|
<< "has invalid word for name: \"" << name
|
||||||
|
<< "\"\nwhile processing path: " << path << "\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::IOobject::IOobject
|
Foam::IOobject::IOobject
|
||||||
@ -118,7 +197,15 @@ Foam::IOobject::IOobject
|
|||||||
registerObject_(registerObject),
|
registerObject_(registerObject),
|
||||||
objState_(GOOD)
|
objState_(GOOD)
|
||||||
{
|
{
|
||||||
path.IOobjectComponents(instance_, local_, name_);
|
if (!fileNameComponents(path, instance_, local_, name_))
|
||||||
|
{
|
||||||
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"IOobject::IOobject" "(const fileName&, const objectRegistry&, ...)"
|
||||||
|
)
|
||||||
|
<< " invalid path specification\n"
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
if (objectRegistry::debug)
|
if (objectRegistry::debug)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -149,7 +149,6 @@ private:
|
|||||||
//- IOobject state
|
//- IOobject state
|
||||||
objectState objState_;
|
objectState objState_;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// Protected member functions
|
// Protected member functions
|
||||||
@ -168,6 +167,18 @@ public:
|
|||||||
TypeName("IOobject");
|
TypeName("IOobject");
|
||||||
|
|
||||||
|
|
||||||
|
// Static Member Functions
|
||||||
|
|
||||||
|
//- Split path into instance, local, name components
|
||||||
|
static bool fileNameComponents
|
||||||
|
(
|
||||||
|
const fileName& path,
|
||||||
|
fileName& instance,
|
||||||
|
fileName& local,
|
||||||
|
word& name
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from name, instance, registry, io options
|
//- Construct from name, instance, registry, io options
|
||||||
@ -194,6 +205,7 @@ public:
|
|||||||
);
|
);
|
||||||
|
|
||||||
//- Construct from path, registry, io options
|
//- Construct from path, registry, io options
|
||||||
|
// Uses fileNameComponents() to split path into components.
|
||||||
IOobject
|
IOobject
|
||||||
(
|
(
|
||||||
const fileName& path,
|
const fileName& path,
|
||||||
@ -215,7 +227,7 @@ public:
|
|||||||
virtual ~IOobject();
|
virtual ~IOobject();
|
||||||
|
|
||||||
|
|
||||||
// Member functions
|
// Member Functions
|
||||||
|
|
||||||
// General access
|
// General access
|
||||||
|
|
||||||
|
|||||||
@ -212,94 +212,6 @@ Foam::word Foam::fileName::component
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Return components following the IOobject requirements
|
|
||||||
//
|
|
||||||
// behaviour
|
|
||||||
// input IOobject(instance, local, name)
|
|
||||||
// ----- ------
|
|
||||||
// "foo" ("", "", "foo")
|
|
||||||
// "foo/bar" ("foo", "", "bar")
|
|
||||||
// "/XXX" ERROR - no absolute path
|
|
||||||
// "foo/bar/" ERROR - no name
|
|
||||||
// "foo/xxx/bar" ("foo", "xxx", "bar")
|
|
||||||
// "foo/xxx/yyy/bar" ("foo", "xxx/yyy", "bar")
|
|
||||||
bool Foam::fileName::IOobjectComponents
|
|
||||||
(
|
|
||||||
fileName& instance,
|
|
||||||
fileName& local,
|
|
||||||
word& name
|
|
||||||
)
|
|
||||||
const
|
|
||||||
{
|
|
||||||
instance.clear();
|
|
||||||
local.clear();
|
|
||||||
name.clear();
|
|
||||||
|
|
||||||
// called with directory
|
|
||||||
if (::Foam::dir(*this))
|
|
||||||
{
|
|
||||||
std::cerr
|
|
||||||
<< "fileName::IOobjectComponents() called with directory: "
|
|
||||||
<< this->c_str() << std::endl;
|
|
||||||
std::abort();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_type first = find('/');
|
|
||||||
|
|
||||||
if (first == 0)
|
|
||||||
{
|
|
||||||
// called with absolute path
|
|
||||||
std::cerr
|
|
||||||
<< "fileName::IOobjectComponents() called with absolute path: "
|
|
||||||
<< this->c_str() << std::endl;
|
|
||||||
std::abort();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (first == npos)
|
|
||||||
{
|
|
||||||
// no '/' found - no instance or local
|
|
||||||
|
|
||||||
// check afterwards
|
|
||||||
name.string::operator=(*this);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
instance = substr(0, first);
|
|
||||||
|
|
||||||
size_type last = rfind('/');
|
|
||||||
if (last > first)
|
|
||||||
{
|
|
||||||
// with local
|
|
||||||
local = substr(first+1, last-first-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check afterwards
|
|
||||||
name.string::operator=(substr(last+1));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// check for valid (and stripped) name, regardless of the debug level
|
|
||||||
if (name.empty() || string::stripInvalid<word>(name))
|
|
||||||
{
|
|
||||||
std::cerr
|
|
||||||
<< "fileName::IOobjectComponents() has invalid word for name: "
|
|
||||||
<< name.c_str() << "\nwhile processing "
|
|
||||||
<< this->c_str() << std::endl;
|
|
||||||
std::abort();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::fileName::operator=(const fileName& str)
|
void Foam::fileName::operator=(const fileName& str)
|
||||||
|
|||||||
@ -163,15 +163,6 @@ public:
|
|||||||
//- Return a single component of the path
|
//- Return a single component of the path
|
||||||
word component(const size_type, const char delimiter='/') const;
|
word component(const size_type, const char delimiter='/') const;
|
||||||
|
|
||||||
//- Return path as instance, local, name components for IOobject
|
|
||||||
bool IOobjectComponents
|
|
||||||
(
|
|
||||||
fileName& instance,
|
|
||||||
fileName& local,
|
|
||||||
word& name
|
|
||||||
) const;
|
|
||||||
|
|
||||||
|
|
||||||
// Member operators
|
// Member operators
|
||||||
|
|
||||||
// Assignment
|
// Assignment
|
||||||
|
|||||||
Reference in New Issue
Block a user