Skip to content

Commit

Permalink
compatability macros for breaking changes in boost::filesystem3
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Mar 10, 2011
1 parent 2c3e236 commit eade7b3
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/cpp/core/FilePath.cpp
Expand Up @@ -17,6 +17,15 @@

#include <boost/filesystem.hpp>

// detect filesystem3 so we can conditionally compile away breaking changes
#if defined(BOOST_FILESYSTEM_VERSION) && BOOST_FILESYSTEM_VERSION != 2
#define BOOST_FS_STRING(str) ((str).string())
#define BOOST_FS_COMPLETE(p, base) boost::filesystem::absolute(p, base)
#else
#define BOOST_FS_STRING(str) str
#define BOOST_FS_COMPLETE(p, base) boost::filesystem::complete(p, base)
#endif

#include <core/StringUtils.hpp>
#include <core/system/System.hpp>

Expand Down Expand Up @@ -169,17 +178,17 @@ uintmax_t FilePath::size() const

std::string FilePath::filename() const
{
return pImpl_->path.filename() ;
return BOOST_FS_STRING(pImpl_->path.filename()) ;
}

std::string FilePath::stem() const
{
return pImpl_->path.stem();
return BOOST_FS_STRING(pImpl_->path.stem());
}

std::string FilePath::extension() const
{
return pImpl_->path.extension() ;
return BOOST_FS_STRING(pImpl_->path.extension()) ;
}

std::string FilePath::extensionLowerCase() const
Expand Down Expand Up @@ -443,7 +452,7 @@ Error FilePath::createDirectory(const std::string& name) const
if (name.empty())
targetDirectory = pImpl_->path ;
else
targetDirectory = boost::filesystem::complete(name, pImpl_->path) ;
targetDirectory = BOOST_FS_COMPLETE(name, pImpl_->path) ;
boost::filesystem::create_directories(targetDirectory) ;
return Success() ;
}
Expand Down Expand Up @@ -475,8 +484,7 @@ FilePath FilePath::complete(const std::string& path) const
// this path is returned)
try
{
return FilePath(boost::filesystem::complete(
path, pImpl_->path).string());
return FilePath(BOOST_FS_COMPLETE(path, pImpl_->path).string());
}
catch(const boost::filesystem::filesystem_error& e)
{
Expand Down

0 comments on commit eade7b3

Please sign in to comment.