Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
fe6a83a3
Commit
fe6a83a3
authored
Jan 30, 2009
by
Mark Olesen
Browse files
moved fileName::IOobjectComponents -> IOobject::fileNameComponents
parent
1f6733d9
Changes
5
Hide whitespace changes
Inline
Side-by-side
applications/test/fileName/fileNameTest.C
View file @
fe6a83a3
...
...
@@ -32,6 +32,7 @@ Description
#include
"fileName.H"
#include
"SubList.H"
#include
"IOobject.H"
#include
"IOstreams.H"
#include
"OSspecific.H"
...
...
@@ -61,7 +62,8 @@ int main()
<<
endl
;
// 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
;
word
name
;
...
...
@@ -69,26 +71,28 @@ int main()
fileName
path
(
SubList
<
word
>
(
wrdList
,
wrdList
.
size
()
-
start
,
start
));
fileName
path2
=
"."
/
path
;
path
.
IOobjectComponents
IOobject
::
fileName
Components
(
path
,
instance
,
local
,
name
);
Info
<<
"IOobjectComponents for "
<<
path
<<
nl
Info
<<
"IOobject
::fileName
Components for "
<<
path
<<
nl
<<
" instance = "
<<
instance
<<
nl
<<
" local = "
<<
local
<<
nl
<<
" name = "
<<
name
<<
endl
;
path2
.
IOobjectComponents
IOobject
::
fileName
Components
(
path2
,
instance
,
local
,
name
);
Info
<<
"IOobjectComponents for "
<<
path2
<<
nl
Info
<<
"IOobject
::fileName
Components for "
<<
path2
<<
nl
<<
" instance = "
<<
instance
<<
nl
<<
" local = "
<<
local
<<
nl
<<
" name = "
<<
name
<<
endl
;
...
...
src/OpenFOAM/db/IOobject/IOobject.C
View file @
fe6a83a3
...
...
@@ -35,6 +35,85 @@ namespace Foam
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
<<
"
\"\n
while processing path: "
<<
path
<<
"
\n
"
;
return
false
;
}
return
true
;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam
::
IOobject
::
IOobject
...
...
@@ -118,7 +197,15 @@ Foam::IOobject::IOobject
registerObject_
(
registerObject
),
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
)
{
...
...
src/OpenFOAM/db/IOobject/IOobject.H
View file @
fe6a83a3
...
...
@@ -149,7 +149,6 @@ private:
//- IOobject state
objectState
objState_
;
protected:
// Protected member functions
...
...
@@ -168,6 +167,18 @@ public:
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
//- Construct from name, instance, registry, io options
...
...
@@ -194,6 +205,7 @@ public:
);
//- Construct from path, registry, io options
// Uses fileNameComponents() to split path into components.
IOobject
(
const
fileName
&
path
,
...
...
@@ -215,7 +227,7 @@ public:
virtual
~
IOobject
();
// Member
f
unctions
// Member
F
unctions
// General access
...
...
src/OpenFOAM/primitives/strings/fileName/fileName.C
View file @
fe6a83a3
...
...
@@ -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
()
<<
"
\n
while processing "
<<
this
->
c_str
()
<<
std
::
endl
;
std
::
abort
();
return
false
;
}
return
true
;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void
Foam
::
fileName
::
operator
=
(
const
fileName
&
str
)
...
...
src/OpenFOAM/primitives/strings/fileName/fileName.H
View file @
fe6a83a3
...
...
@@ -163,15 +163,6 @@ public:
//- Return a single component of the path
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
// Assignment
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment