Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
d86d8d27
Commit
d86d8d27
authored
7 years ago
by
Pospelov, Gennady
Browse files
Options
Downloads
Patches
Plain Diff
Code beautification in FileSystemUtils
parent
1c748664
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Core/Tools/FileSystemUtils.cpp
+11
-15
11 additions, 15 deletions
Core/Tools/FileSystemUtils.cpp
Core/Tools/FileSystemUtils.h
+12
-13
12 additions, 13 deletions
Core/Tools/FileSystemUtils.h
with
23 additions
and
28 deletions
Core/Tools/FileSystemUtils.cpp
+
11
−
15
View file @
d86d8d27
...
@@ -15,11 +15,10 @@
...
@@ -15,11 +15,10 @@
#include
"FileSystemUtils.h"
#include
"FileSystemUtils.h"
#include
"Exceptions.h"
#include
"Exceptions.h"
#include
<boost/filesystem.hpp>
#include
<boost/filesystem.hpp>
#include
<cassert>
#include
<boost/regex.hpp>
#include
<boost/regex.hpp>
#include
<cassert>
#include
<stdexcept>
#include
<stdexcept>
//! Returns extension of given filename.
std
::
string
FileSystemUtils
::
extension
(
const
std
::
string
&
name
)
std
::
string
FileSystemUtils
::
extension
(
const
std
::
string
&
name
)
{
{
return
boost
::
filesystem
::
extension
(
name
.
c_str
());
return
boost
::
filesystem
::
extension
(
name
.
c_str
());
...
@@ -27,31 +26,30 @@ std::string FileSystemUtils::extension(const std::string& name)
...
@@ -27,31 +26,30 @@ std::string FileSystemUtils::extension(const std::string& name)
bool
FileSystemUtils
::
createDirectory
(
const
std
::
string
&
dir_name
)
bool
FileSystemUtils
::
createDirectory
(
const
std
::
string
&
dir_name
)
{
{
assert
(
dir_name
!=
""
);
assert
(
dir_name
!=
""
);
return
boost
::
filesystem
::
create_directory
(
dir_name
);
return
boost
::
filesystem
::
create_directory
(
dir_name
);
}
}
//! Returns filenames of files in directory
std
::
vector
<
std
::
string
>
FileSystemUtils
::
filesInDirectory
(
const
std
::
string
&
dir_name
)
std
::
vector
<
std
::
string
>
FileSystemUtils
::
filesInDirectory
(
const
std
::
string
&
dir_name
)
{
{
std
::
vector
<
std
::
string
>
ret
;
std
::
vector
<
std
::
string
>
ret
;
if
(
!
boost
::
filesystem
::
exists
(
dir_name
))
if
(
!
boost
::
filesystem
::
exists
(
dir_name
))
throw
std
::
runtime_error
(
throw
std
::
runtime_error
(
"FileSystemUtils::filesInDirectory '"
+
dir_name
"FileSystemUtils::filesInDirectory '"
+
dir_name
+
"' does not exist"
);
+
"' does not exist"
);
boost
::
filesystem
::
directory_iterator
end_it
;
// default construction yields past-the-end
boost
::
filesystem
::
directory_iterator
end_it
;
// default construction yields past-the-end
for
(
boost
::
filesystem
::
directory_iterator
it
(
dir_name
);
for
(
boost
::
filesystem
::
directory_iterator
it
(
dir_name
);
it
!=
boost
::
filesystem
::
directory_iterator
();
++
it
)
{
it
!=
boost
::
filesystem
::
directory_iterator
();
++
it
)
{
if
(
!
boost
::
filesystem
::
is_regular_file
(
it
->
status
()
)
)
if
(
!
boost
::
filesystem
::
is_regular_file
(
it
->
status
()
)
)
continue
;
continue
;
ret
.
push_back
(
it
->
path
().
filename
().
string
()
);
ret
.
push_back
(
it
->
path
().
filename
().
string
());
}
}
return
ret
;
return
ret
;
}
}
std
::
string
FileSystemUtils
::
jointPath
(
const
std
::
string
&
spath1
,
const
std
::
string
&
spath2
)
std
::
string
FileSystemUtils
::
jointPath
(
const
std
::
string
&
spath1
,
const
std
::
string
&
spath2
)
{
{
assert
(
spath1
!=
""
);
assert
(
spath1
!=
""
);
assert
(
spath2
!=
""
);
assert
(
spath2
!=
""
);
boost
::
filesystem
::
path
path1
(
spath1
);
boost
::
filesystem
::
path
path1
(
spath1
);
boost
::
filesystem
::
path
path2
(
spath2
);
boost
::
filesystem
::
path
path2
(
spath2
);
boost
::
filesystem
::
path
full_path
=
path1
/
path2
;
boost
::
filesystem
::
path
full_path
=
path1
/
path2
;
...
@@ -59,17 +57,15 @@ std::string FileSystemUtils::jointPath(const std::string& spath1, const std::str
...
@@ -59,17 +57,15 @@ std::string FileSystemUtils::jointPath(const std::string& spath1, const std::str
return
full_path
.
string
();
return
full_path
.
string
();
}
}
//! Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")
std
::
string
FileSystemUtils
::
filename
(
const
std
::
string
&
path
)
std
::
string
FileSystemUtils
::
filename
(
const
std
::
string
&
path
)
{
{
return
boost
::
filesystem
::
path
(
path
).
filename
().
string
();
return
boost
::
filesystem
::
path
(
path
).
filename
().
string
();
}
}
//! Returns file names that agree with a regex glob pattern.
std
::
vector
<
std
::
string
>
FileSystemUtils
::
glob
(
const
std
::
string
&
dir
,
const
std
::
string
&
pattern
)
std
::
vector
<
std
::
string
>
FileSystemUtils
::
glob
(
const
std
::
string
&
dir
,
const
std
::
string
&
pattern
)
{
{
std
::
vector
<
std
::
string
>
ret
;
std
::
vector
<
std
::
string
>
ret
;
for
(
const
std
::
string
&
fname
:
filesInDirectory
(
dir
))
for
(
const
std
::
string
&
fname
:
filesInDirectory
(
dir
))
if
(
boost
::
regex_match
(
fname
,
boost
::
regex
(
pattern
)))
if
(
boost
::
regex_match
(
fname
,
boost
::
regex
(
pattern
)))
ret
.
push_back
(
fname
);
ret
.
push_back
(
fname
);
return
ret
;
return
ret
;
...
...
This diff is collapsed.
Click to expand it.
Core/Tools/FileSystemUtils.h
+
12
−
13
View file @
d86d8d27
...
@@ -23,24 +23,23 @@
...
@@ -23,24 +23,23 @@
namespace
FileSystemUtils
{
namespace
FileSystemUtils
{
//! Returns extension of given filename.
//! Returns extension of given filename.
BA_CORE_API_
std
::
string
extension
(
const
std
::
string
&
fname
);
BA_CORE_API_
std
::
string
extension
(
const
std
::
string
&
fname
);
//! Creates directory in current directory
//! Creates directory in current directory
BA_CORE_API_
bool
createDirectory
(
const
std
::
string
&
dir_name
);
BA_CORE_API_
bool
createDirectory
(
const
std
::
string
&
dir_name
);
//! Returns filenames of files in directory
//! Returns filenames of files in directory
BA_CORE_API_
std
::
vector
<
std
::
string
>
filesInDirectory
(
const
std
::
string
&
dir_name
);
BA_CORE_API_
std
::
vector
<
std
::
string
>
filesInDirectory
(
const
std
::
string
&
dir_name
);
//! Returns joint path name.
//! Returns joint path name.
BA_CORE_API_
std
::
string
jointPath
(
const
std
::
string
&
spath1
,
const
std
::
string
&
spath2
);
BA_CORE_API_
std
::
string
jointPath
(
const
std
::
string
&
spath1
,
const
std
::
string
&
spath2
);
//! Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")
//! Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")
BA_CORE_API_
std
::
string
filename
(
const
std
::
string
&
path
);
BA_CORE_API_
std
::
string
filename
(
const
std
::
string
&
path
);
//! Returns file names that agree with a regex glob pattern.
//! Returns file names that agree with a regex glob pattern.
BA_CORE_API_
std
::
vector
<
std
::
string
>
glob
(
BA_CORE_API_
std
::
vector
<
std
::
string
>
glob
(
const
std
::
string
&
dir
,
const
std
::
string
&
pattern
);
const
std
::
string
&
dir
,
const
std
::
string
&
pattern
);
}
// namespace FileSystemUtils
}
// namespace FileSystemUtils
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment