Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
iwr
dune-gmsh4
Commits
eaed36c2
Commit
eaed36c2
authored
Aug 17, 2020
by
Praetorius, Simon
Browse files
renamed path to Path and use camelCase names
parent
0bf4fa59
Changes
3
Hide whitespace changes
Inline
Side-by-side
dune/gmsh4/reader.hh
View file @
eaed36c2
...
...
@@ -134,6 +134,7 @@ namespace Dune
void
readString
(
std
::
istream
&
stream
,
std
::
string
&
name
)
{
DUNE_THROW
(
Dune
::
NotImplemented
,
"Method readString() not yet implemented"
);
name
=
"Hallo"
;
}
...
...
dune/gmsh4/utility/filesystem.cc
View file @
eaed36c2
...
...
@@ -21,174 +21,171 @@
template
<
class
...
Args
>
void
inline
_ignore_
(
Args
&&
...)
{}
namespace
Dune
namespace
Dune
{
namespace
Gmsh4
{
std
::
string
Path
::
string
()
const
{
namespace
Gmsh4
{
if
(
empty
())
return
"."
;
std
::
string
Path
::
string
()
const
{
if
(
empty
())
return
"."
;
auto
it
=
begin
();
auto
result
=
*
it
;
for
(
++
it
;
it
!=
end
();
++
it
)
result
+=
preferredSeparator
+
*
it
;
return
result
;
}
auto
it
=
begin
();
auto
result
=
*
it
;
for
(
++
it
;
it
!=
end
();
++
it
)
result
+=
preferred_separator
+
*
it
;
return
result
;
}
void
Path
::
split
(
std
::
string
p
)
{
std
::
string
separators
=
"/
\\
"
;
bool
relative
=
true
;
void
Path
::
split
(
std
::
string
p
)
{
std
::
string
separators
=
"/
\\
"
;
bool
relative
=
true
;
Gmsh4
::
trim
(
p
);
Gmsh4
::
split
(
p
.
begin
(),
p
.
end
(),
separators
.
begin
(),
separators
.
end
(),
[
this
,
&
relative
](
auto
first
,
auto
end
)
{
auto
token
=
std
::
string
(
first
,
end
);
if
((
!
token
.
empty
()
&&
token
!=
"."
&&
token
!=
".."
)
||
(
token
.
empty
()
&&
this
->
empty
()))
{
this
->
push_back
(
token
);
relative
=
false
;
}
else
if
(
token
==
".."
)
{
if
(
relative
||
this
->
empty
())
{
this
->
push_back
(
token
);
}
else
{
this
->
pop_back
();
}
}
});
}
Path
Path
::
stem
()
const
trim
(
p
);
Dune
::
Vtk
::
split
(
p
.
begin
(),
p
.
end
(),
separators
.
begin
(),
separators
.
end
(),
[
this
,
&
relative
](
auto
first
,
auto
end
)
{
auto
f
=
filename
().
string
();
auto
pos
=
f
.
find_last_of
(
'.'
);
if
(
f
==
"."
||
f
==
".."
||
pos
==
std
::
string
::
npos
)
return
{
f
};
else
return
{
f
.
substr
(
0
,
pos
)};
}
auto
token
=
std
::
string
(
first
,
end
);
if
((
!
token
.
empty
()
&&
token
!=
"."
&&
token
!=
".."
)
||
(
token
.
empty
()
&&
this
->
empty
()))
{
this
->
push_back
(
token
);
relative
=
false
;
}
else
if
(
token
==
".."
)
{
if
(
relative
||
this
->
empty
())
{
this
->
push_back
(
token
);
}
else
{
this
->
pop_back
();
}
}
});
}
Path
Path
::
extension
()
const
{
auto
f
=
filename
().
string
();
auto
pos
=
f
.
find_last_of
(
'.'
);
if
(
f
==
"."
||
f
==
".."
||
pos
==
std
::
string
::
npos
)
return
{};
else
return
{
f
.
substr
(
pos
)};
}
Path
Path
::
stem
()
const
{
auto
f
=
filename
().
string
();
auto
pos
=
f
.
find_last_of
(
'.'
);
if
(
f
==
"."
||
f
==
".."
||
pos
==
std
::
string
::
npos
)
return
{
f
};
else
return
{
f
.
substr
(
0
,
pos
)};
}
bool
Path
::
is_absolute
(
std
::
string
p
)
{
if
(
p
[
0
]
==
'/'
)
return
true
;
Path
Path
::
extension
()
const
{
auto
f
=
filename
().
string
();
auto
pos
=
f
.
find_last_of
(
'.'
);
if
(
f
==
"."
||
f
==
".."
||
pos
==
std
::
string
::
npos
)
return
{};
else
return
{
f
.
substr
(
pos
)};
}
// c:\ or z:/
if
(
std
::
isalpha
(
p
[
0
])
&&
p
[
1
]
==
':'
&&
(
p
[
2
]
==
'/'
||
p
[
2
]
==
'\\'
))
return
true
;
return
false
;
}
bool
Path
::
isAbsolute
(
std
::
string
p
)
{
if
(
p
[
0
]
==
'/'
)
return
true
;
// c:\ or z:/
if
(
std
::
isalpha
(
p
[
0
])
&&
p
[
1
]
==
':'
&&
(
p
[
2
]
==
'/'
||
p
[
2
]
==
'\\'
))
return
true
;
Path
&
Path
::
operator
/=
(
Path
const
&
p
)
{
insert
(
end
(),
p
.
begin
(),
p
.
end
());
original
+=
preferred_separator
+
p
.
original
;
return
*
this
;
}
return
false
;
}
bool
Path
::
is_file
()
const
{
std
::
string
p
=
this
->
string
(
);
struct
stat
info
;
return
stat
(
p
.
c_str
(),
&
info
)
==
0
&&
(
info
.
st_mode
&
S_IFREG
)
!=
0
;
}
Path
&
Path
::
operator
/=
(
Path
const
&
p
)
{
insert
(
end
(),
p
.
begin
(),
p
.
end
()
);
original
+=
preferredSeparator
+
p
.
original
;
return
*
this
;
}
bool
Path
::
is
_directory
()
const
{
std
::
string
p
=
this
->
string
();
struct
stat
info
;
return
stat
(
p
.
c_str
(),
&
info
)
==
0
&&
(
info
.
st_mode
&
S_IF
DIR
)
!=
0
;
}
bool
Path
::
is
File
()
const
{
std
::
string
p
=
this
->
string
();
struct
stat
info
;
return
stat
(
p
.
c_str
(),
&
info
)
==
0
&&
(
info
.
st_mode
&
S_IF
REG
)
!=
0
;
}
Path
current_path
()
{
char
cwd_
[
FILENAME_MAX
];
_ignore_
(
GET_CURRENT_DIR
(
cwd_
,
sizeof
(
cwd_
)));
std
::
string
cwd
(
cwd_
);
return
{
Gmsh4
::
trim
(
cwd
)
};
}
bool
Path
::
isDirectory
()
const
{
std
::
string
p
=
this
->
string
();
struct
stat
info
;
return
stat
(
p
.
c_str
(),
&
info
)
==
0
&&
(
info
.
st_mode
&
S_IFDIR
)
!=
0
;
}
bool
exists
(
Path
const
&
p
)
{
return
p
.
is_file
()
||
p
.
is_directory
();
}
Path
currentPath
()
{
char
cwd_
[
FILENAME_MAX
];
_ignore_
(
GET_CURRENT_DIR
(
cwd_
,
sizeof
(
cwd_
)));
std
::
string
cwd
(
cwd_
);
return
{
trim
(
cwd
)
};
}
bool
create_directories
(
Path
const
&
p
)
{
if
(
p
.
is_directory
())
return
true
;
auto
parent
=
p
.
parent_path
();
if
(
!
parent
.
empty
()
&&
!
parent
.
is_directory
())
create_directories
(
parent
);
#ifdef _WIN32
int
ret
=
_mkdir
(
p
.
string
().
c_str
());
#else
mode_t
mode
=
0755
;
int
ret
=
mkdir
(
p
.
string
().
c_str
(),
mode
);
#endif
if
(
ret
==
0
)
return
true
;
switch
(
errno
)
{
case
ENOENT
:
std
::
cerr
<<
"parent didn't exist. Should not happen, since parent directory created before!
\n
"
;
std
::
abort
();
return
false
;
break
;
case
EEXIST
:
return
true
;
break
;
default:
return
false
;
}
}
bool
exists
(
Path
const
&
p
)
{
return
p
.
isFile
()
||
p
.
isDirectory
();
}
Path
relative
(
Path
const
&
a
,
Path
const
&
b
)
{
// find common base path
auto
a_it
=
a
.
begin
();
auto
b_it
=
b
.
begin
();
for
(;
a_it
!=
a
.
end
()
&&
b_it
!=
b
.
end
();
++
a_it
,
++
b_it
)
{
if
(
*
a_it
!=
*
b_it
)
break
;
}
// combine remaining parts of a to result path
Path
rel
(
"."
);
for
(;
a_it
!=
a
.
end
();
++
a_it
)
rel
/=
*
a_it
;
bool
createDirectories
(
Path
const
&
p
)
{
if
(
p
.
isDirectory
())
return
true
;
auto
parent
=
p
.
parentPath
();
if
(
!
parent
.
empty
()
&&
!
parent
.
isDirectory
())
createDirectories
(
parent
);
return
rel
;
}
#ifdef _WIN32
int
ret
=
_mkdir
(
p
.
string
().
c_str
());
#else
mode_t
mode
=
0755
;
int
ret
=
mkdir
(
p
.
string
().
c_str
(),
mode
);
#endif
if
(
ret
==
0
)
return
true
;
}
// end namespace Gmsh4
}
// end namespace Dune
switch
(
errno
)
{
case
ENOENT
:
std
::
cerr
<<
"parent didn't exist. Should not happen, since parent directory created before!
\n
"
;
std
::
abort
();
return
false
;
break
;
case
EEXIST
:
return
true
;
break
;
default:
return
false
;
}
}
Path
relative
(
Path
const
&
a
,
Path
const
&
b
)
{
// find common base path
auto
a_it
=
a
.
begin
();
auto
b_it
=
b
.
begin
();
for
(;
a_it
!=
a
.
end
()
&&
b_it
!=
b
.
end
();
++
a_it
,
++
b_it
)
{
if
(
*
a_it
!=
*
b_it
)
break
;
}
// combine remaining parts of a to result path
Path
rel
(
"."
);
for
(;
a_it
!=
a
.
end
();
++
a_it
)
rel
/=
*
a_it
;
return
rel
;
}
}
}
// end namespace Dune::Gmsh4
dune/gmsh4/utility/filesystem.hh
View file @
eaed36c2
...
...
@@ -9,7 +9,6 @@ namespace Dune
{
namespace
Gmsh4
{
// A minimalistic filesystem class
class
Path
:
public
std
::
vector
<
std
::
string
>
...
...
@@ -20,9 +19,9 @@ namespace Dune
public:
#ifdef _WIN32
static
constexpr
char
preferred
_s
eparator
=
'\\'
;
static
constexpr
char
preferred
S
eparator
=
'\\'
;
#else
static
constexpr
char
preferred
_s
eparator
=
'/'
;
static
constexpr
char
preferred
S
eparator
=
'/'
;
#endif
public:
...
...
@@ -49,14 +48,14 @@ namespace Dune
{}
/// Removes filename path component
Path
&
remove
_f
ilename
()
Path
&
remove
F
ilename
()
{
this
->
pop_back
();
return
*
this
;
}
/// Returns the path of the parent path
Path
parent
_p
ath
()
const
Path
parent
P
ath
()
const
{
return
empty
()
?
Path
()
:
Path
(
begin
(),
--
end
());
}
...
...
@@ -80,17 +79,17 @@ namespace Dune
/** In Linux, test whether the path starts with `/`, in Windows whether it starts
* with `[a-z]:\\`.
**/
static
bool
is
_a
bsolute
(
std
::
string
p
);
static
bool
is
A
bsolute
(
std
::
string
p
);
bool
is
_a
bsolute
()
const
{
return
is
_a
bsolute
(
original
);
}
bool
is
A
bsolute
()
const
{
return
is
A
bsolute
(
original
);
}
bool
is
_r
elative
()
const
{
return
!
is
_a
bsolute
();
}
bool
is
R
elative
()
const
{
return
!
is
A
bsolute
();
}
/// Check whether path is a regular file
bool
is
_f
ile
()
const
;
bool
is
F
ile
()
const
;
/// Check whether path is a regular file
bool
is
_d
irectory
()
const
;
bool
is
D
irectory
()
const
;
/// Lexicographically compares two paths
bool
operator
==
(
Path
const
&
p
)
...
...
@@ -123,10 +122,10 @@ namespace Dune
bool
exists
(
Path
const
&
);
/// Create directory and non existing parent directories.
bool
create
_d
irectories
(
Path
const
&
);
bool
create
D
irectories
(
Path
const
&
);
/// Returns the current path
Path
current
_p
ath
();
Path
current
P
ath
();
/// Find the path of `a` relative to directory of `b`
Path
relative
(
Path
const
&
a
,
Path
const
&
b
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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