-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move filesystem namespace alias to os/fs.h, which now includes either…
… boost/filesystem.hpp or the standard one. For now, we only switch on that in VC++ 2017 which ships the std::experimental::filesystem::v1 namespace. Add a few adapter methods for the few routines that are called differently in boost and in std::experimental.
- Loading branch information
1 parent
d08b67a
commit 44ac0a4
Showing
17 changed files
with
97 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,81 @@ | ||
/** | ||
* \file | ||
* Helper header for boost::filesystem. Includes the relevant Boost headers, | ||
* defines the common "fs" namespace alias, and includes some helper functions | ||
* to deal with the transition from Filesystem V2 to V3. | ||
* Helper header for std::filesystem feature set. Includes the relevant headers | ||
* and defines the common "fs" namespace alias. | ||
* If the compiler library supports the C++17 feature std::filesystem, it will | ||
* include the corresponding headers. All other compilers will refer to the | ||
* headers provided by boost::filesystem. | ||
*/ | ||
#pragma once | ||
|
||
// At the time of writing C++17 is still in draft state, but compilers | ||
// provide the features through the std::experimental namespace. | ||
#if _MSC_VER >= 1900 | ||
|
||
// Visual Studio 2015 onwards supplies the experimental/filesystem header | ||
#include <experimental/filesystem> | ||
namespace fs = std::experimental::filesystem::v1; | ||
#define DR_USE_STD_FILESYSTEM | ||
|
||
#else | ||
|
||
// All other compilers will use the boost headers | ||
#include <boost/version.hpp> | ||
#include <boost/filesystem.hpp> | ||
#include <boost/algorithm/string/predicate.hpp> | ||
#define DR_USE_BOOST_FILESYSTEM | ||
|
||
namespace fs = boost::filesystem; | ||
|
||
namespace os | ||
{ | ||
/// Return the string filename of a path object | ||
inline std::string filename_from_path(const fs::path& p) | ||
{ | ||
#if BOOST_VERSION < 104600 | ||
return p.filename(); | ||
#else | ||
return p.filename().string(); | ||
#endif | ||
} | ||
|
||
/// Return a string for the given path in platform-independent format | ||
inline std::string string_from_path(const fs::path& p) | ||
{ | ||
#if BOOST_VERSION < 104600 | ||
return p.string(); // in contrast to file_string() (native format) | ||
#else | ||
return p.generic_string(); // in this case string() is native format | ||
#endif | ||
} | ||
#include <boost/algorithm/string/predicate.hpp> | ||
|
||
namespace os | ||
{ | ||
/// Overload of standardPathWithSlash that accepts a fs::path | ||
inline std::string standardPathWithSlash(const fs::path& p) | ||
{ | ||
std::string genString = string_from_path(p); | ||
std::string genString = p.generic_string(); | ||
|
||
// Just add slash if needed, we don't need to convert intermediate | ||
// slashes since string_from_path will already have done that. | ||
if (!boost::algorithm::ends_with(genString, "/")) | ||
{ | ||
genString += "/"; | ||
} | ||
|
||
return genString; | ||
} | ||
|
||
// Wrapper method to return the depth of a recursive iterator, | ||
// supporting std::experimental::filesystem as well as boost::filesystem | ||
inline int getDepth(fs::recursive_directory_iterator& it) | ||
{ | ||
#ifdef DR_USE_STD_FILESYSTEM | ||
return it.depth(); | ||
#else | ||
return it.level(); | ||
#endif | ||
} | ||
|
||
// Wrapper method to call no_push / disable_recursion_pending on iterators | ||
// Since the C++17 call has been named differently than the boost one, here we go | ||
inline void disableRecursionPending(fs::recursive_directory_iterator& it) | ||
{ | ||
#ifdef DR_USE_STD_FILESYSTEM | ||
it.disable_recursion_pending(); | ||
#else | ||
it.no_push(); | ||
#endif | ||
} | ||
|
||
// Replaces the extension of the given filename with newExt | ||
inline std::string replaceExtension(const std::string& input, const std::string& newExt) | ||
{ | ||
#ifdef DR_USE_STD_FILESYSTEM | ||
return fs::path(input).replace_extension(newExt).string(); | ||
#else | ||
return fs::change_extension(input, newExt).string(); | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.