diff --git a/Core/Tools/FileSystemUtils.cpp b/Core/Tools/FileSystemUtils.cpp index 84d53ad2dac0e4bdeee1420fa62c14fe1ea91c17..66321b8681720067712259a636b9b41d8b4d304d 100644 --- a/Core/Tools/FileSystemUtils.cpp +++ b/Core/Tools/FileSystemUtils.cpp @@ -15,11 +15,10 @@ #include "FileSystemUtils.h" #include "Exceptions.h" #include <boost/filesystem.hpp> -#include <cassert> #include <boost/regex.hpp> +#include <cassert> #include <stdexcept> -//! Returns extension of given filename. std::string FileSystemUtils::extension(const std::string& name) { return boost::filesystem::extension(name.c_str()); @@ -27,31 +26,30 @@ std::string FileSystemUtils::extension(const std::string& name) bool FileSystemUtils::createDirectory(const std::string& dir_name) { - assert(dir_name!=""); + assert(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> ret; if (!boost::filesystem::exists(dir_name)) - throw std::runtime_error( - "FileSystemUtils::filesInDirectory '" + dir_name + "' does not exist"); + throw std::runtime_error("FileSystemUtils::filesInDirectory '" + dir_name + + "' does not exist"); boost::filesystem::directory_iterator end_it; // default construction yields past-the-end - for ( boost::filesystem::directory_iterator it( dir_name ); - it != boost::filesystem::directory_iterator(); ++it ) { - if( !boost::filesystem::is_regular_file( it->status() ) ) + for (boost::filesystem::directory_iterator it(dir_name); + it != boost::filesystem::directory_iterator(); ++it) { + if (!boost::filesystem::is_regular_file(it->status())) continue; - ret.push_back( it->path().filename().string() ); + ret.push_back(it->path().filename().string()); } return ret; } std::string FileSystemUtils::jointPath(const std::string& spath1, const std::string& spath2) { - assert(spath1!=""); - assert(spath2!=""); + assert(spath1 != ""); + assert(spath2 != ""); boost::filesystem::path path1(spath1); boost::filesystem::path path2(spath2); boost::filesystem::path full_path = path1 / path2; @@ -59,17 +57,15 @@ std::string FileSystemUtils::jointPath(const std::string& spath1, const std::str 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) { 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> ret; - for (const std::string& fname: filesInDirectory(dir)) + for (const std::string& fname : filesInDirectory(dir)) if (boost::regex_match(fname, boost::regex(pattern))) ret.push_back(fname); return ret; diff --git a/Core/Tools/FileSystemUtils.h b/Core/Tools/FileSystemUtils.h index 3ed9d3f37ca07e58210e6ff69bf4740f9d57a3c2..3a2b28465c006b7fa3dd48c98b2dcb526c8e1df3 100644 --- a/Core/Tools/FileSystemUtils.h +++ b/Core/Tools/FileSystemUtils.h @@ -23,24 +23,23 @@ namespace FileSystemUtils { - //! Returns extension of given filename. - BA_CORE_API_ std::string extension(const std::string& fname); +//! Returns extension of given filename. +BA_CORE_API_ std::string extension(const std::string& fname); - //! Creates directory in current directory - BA_CORE_API_ bool createDirectory(const std::string& dir_name); +//! Creates directory in current directory +BA_CORE_API_ bool createDirectory(const std::string& dir_name); - //! Returns filenames of files in directory - BA_CORE_API_ std::vector<std::string> filesInDirectory(const std::string& dir_name); +//! Returns filenames of files in directory +BA_CORE_API_ std::vector<std::string> filesInDirectory(const std::string& dir_name); - //! Returns joint path name. - BA_CORE_API_ std::string jointPath(const std::string& spath1, const std::string& spath2); +//! Returns joint path name. +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") - BA_CORE_API_ std::string filename(const std::string& path); +//! Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz") +BA_CORE_API_ std::string filename(const std::string& path); - //! Returns file names that agree with a regex glob pattern. - BA_CORE_API_ std::vector<std::string> glob( - const std::string& dir, const std::string& pattern); +//! Returns file names that agree with a regex glob pattern. +BA_CORE_API_ std::vector<std::string> glob(const std::string& dir, const std::string& pattern); } // namespace FileSystemUtils