Skip to content

Commit

Permalink
Remove use of boost::filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 committed Jan 14, 2022
1 parent 05158f8 commit 49b7b0e
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 32 deletions.
5 changes: 5 additions & 0 deletions dart/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ endif()
if(TARGET octomap)
target_link_libraries(dart PUBLIC octomap)
endif()

# C++ standard settings
target_compile_features(dart PUBLIC cxx_std_17)
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
target_link_libraries(dart PUBLIC "stdc++fs")
endif()

# Build DART with all available SIMD instructions
if(DART_ENABLE_SIMD)
Expand Down
109 changes: 109 additions & 0 deletions dart/common/Filesystem.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright (c) 2011-2021, The DART development contributors:
* https://github.com/dartsim/dart/blob/main/LICENSE
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include "dart/common/Platform.hpp"

#if !defined(DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL)

// Check for feature test macro for <filesystem>
#if defined(__cpp_lib_filesystem)
#define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0

// Check for feature test macro for <experimental/filesystem>
#elif defined(__cpp_lib_experimental_filesystem)
#define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1

// We can't check if headers exist...
// Let's assume experimental to be safe
#elif !defined(__has_include)
#define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1

// Check if the header "<filesystem>" exists
#elif __has_include(<filesystem>)

// If we're compiling on Visual Studio and are not compiling with C++17, we
// need to use experimental
#ifdef _MSC_VER

// Check and include header that defines "_HAS_CXX17"
#if __has_include(<yvals_core.h>)
#include <yvals_core.h>

// Check for enabled C++17 support
#if defined(_HAS_CXX17) && _HAS_CXX17
// We're using C++17, so let's use the normal version
#define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0
#endif
#endif

// If the marco isn't defined yet, that means any of the other VS specific
// checks failed, so we need to use experimental
#ifndef DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
#define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1
#endif

// Not on Visual Studio. Let's use the normal version
#else // #ifdef _MSC_VER
#define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0
#endif

// Check if the header "<filesystem>" exists
#elif __has_include(<experimental/filesystem>)
#define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1

// Fail if neither header is available with a nice error message
#else
#error Could not find system header "<filesystem>" or "<experimental/filesystem>"
#endif

// We priously determined that we need the exprimental version
#if DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
// Include it
#include <experimental/filesystem>

namespace dart::common {

namespace filesystem = ::std::experimental::filesystem;
using error_code = ::std::error_code;

} // namespace dart::common

// We have a decent compiler and can use the normal version
#else
// Include it
#include <filesystem>

namespace dart::common {
namespace filesystem = ::std::filesystem;
using error_code = ::std::error_code;
} // namespace dart::common

#endif

#endif // #ifndef DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
3 changes: 0 additions & 3 deletions dart/common/Optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,11 @@

#include <optional>

#include "dart/common/Deprecated.hpp"

namespace dart {
namespace common {

/// \deprecated Use std::optional instead
template <class T>
DART_DEPRECATED(6.13)
using optional = std::optional<T>;

} // namespace common
Expand Down
6 changes: 3 additions & 3 deletions dart/common/SharedLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace common {

//==============================================================================
std::shared_ptr<SharedLibrary> SharedLibrary::create(
const boost::filesystem::path& path)
const common::filesystem::path& path)
{
return create(path.string());
}
Expand All @@ -70,7 +70,7 @@ std::shared_ptr<SharedLibrary> SharedLibrary::create(const std::string& path)

//==============================================================================
SharedLibrary::SharedLibrary(
ProtectedConstructionTag, const boost::filesystem::path& canonicalPath)
ProtectedConstructionTag, const common::filesystem::path& canonicalPath)
: SharedLibrary(ProtectedConstruction, canonicalPath.string())
{
// Do nothing
Expand Down Expand Up @@ -104,7 +104,7 @@ SharedLibrary::~SharedLibrary()
}

//==============================================================================
const boost::filesystem::path& SharedLibrary::getCanonicalPath() const
const common::filesystem::path& SharedLibrary::getCanonicalPath() const
{
return mCanonicalPath;
}
Expand Down
12 changes: 6 additions & 6 deletions dart/common/SharedLibrary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@
#include <memory>
#include <string>

#include <boost/filesystem.hpp>

#include "dart/common/Deprecated.hpp"
#include "dart/common/Filesystem.hpp"
#include "dart/common/Platform.hpp"

#if DART_OS_LINUX
Expand Down Expand Up @@ -115,7 +114,7 @@ class SharedLibrary
/// instead.
DART_DEPRECATED(6.10)
static std::shared_ptr<SharedLibrary> create(
const boost::filesystem::path& path);
const common::filesystem::path& path);

/// Creates a SharedLibrary from a path to the shared library.
///
Expand Down Expand Up @@ -145,7 +144,7 @@ class SharedLibrary
/// SharedLibrary(ProtectedConstructionTag, const std::string&) instead.
DART_DEPRECATED(6.10)
explicit SharedLibrary(
ProtectedConstructionTag, const boost::filesystem::path& path);
ProtectedConstructionTag, const common::filesystem::path& path);

/// Constructs from a path to the shared library.
///
Expand All @@ -164,7 +163,7 @@ class SharedLibrary
virtual ~SharedLibrary();

/// Returns the path to the shared library file.
const boost::filesystem::path& getCanonicalPath() const;
const common::filesystem::path& getCanonicalPath() const;

/// Returns the path to the shared library file.
const std::string& path() const;
Expand All @@ -185,7 +184,8 @@ class SharedLibrary
/// Canonical path to the shared library where a canonical path is an absolute
/// path that has no elements which are symbolic links, and no dot or dot dot
/// elements such as "/path/../to/yourfile".
boost::filesystem::path mCanonicalPath;
/// \deprecated Use mCanonicalPath2 instead.
common::filesystem::path mCanonicalPath;
// TODO(JS): Remove in DART 7.

/// Canonical path to the shared library where a canonical path is an absolute
Expand Down
4 changes: 2 additions & 2 deletions dart/common/detail/SharedLibraryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace detail {

//==============================================================================
std::shared_ptr<SharedLibrary> SharedLibraryManager::load(
const boost::filesystem::path& path)
const common::filesystem::path& path)
{
return load(path.string());
}
Expand All @@ -62,7 +62,7 @@ std::shared_ptr<SharedLibrary> SharedLibraryManager::load(
}

// Convert the given path to the canonical path
const auto canonicalPath = boost::filesystem::canonical(path).string();
const auto canonicalPath = common::filesystem::canonical(path).string();

const auto iter = mSharedLibraries.find(canonicalPath);

Expand Down
14 changes: 6 additions & 8 deletions dart/common/detail/SharedLibraryManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,18 @@
#include <string>
#include <unordered_map>

#include <boost/filesystem.hpp>
#include <boost/functional/hash.hpp>

#include "dart/common/Deprecated.hpp"
#include "dart/common/Filesystem.hpp"
#include "dart/common/Singleton.hpp"

namespace std {

template <>
struct hash<boost::filesystem::path>
struct hash<::dart::common::filesystem::path>
{
size_t operator()(const boost::filesystem::path& p) const
size_t operator()(const ::dart::common::filesystem::path& p) const
{
return boost::filesystem::hash_value(p);
return ::dart::common::filesystem::hash_value(p);
}
};

Expand All @@ -77,7 +75,7 @@ class SharedLibraryManager final : public Singleton<SharedLibraryManager>
/// \deprecated Deprecated in 6.10. Please use load(const std::string&)
/// instead.
DART_DEPRECATED(6.10)
std::shared_ptr<SharedLibrary> load(const boost::filesystem::path& path);
std::shared_ptr<SharedLibrary> load(const common::filesystem::path& path);

/// Loads the shared library with the specified path.
///
Expand All @@ -94,7 +92,7 @@ class SharedLibraryManager final : public Singleton<SharedLibraryManager>

protected:
/// Map from library path to the library instances.
std::unordered_map<boost::filesystem::path, std::weak_ptr<SharedLibrary>>
std::unordered_map<common::filesystem::path, std::weak_ptr<SharedLibrary>>
mLibraries;
// TODO(JS): Remove this in DART 7.

Expand Down
15 changes: 7 additions & 8 deletions dart/gui/osg/render/MeshShapeNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

#include <map>

#include <boost/filesystem.hpp>
#include <osg/CullFace>
#include <osg/Depth>
#include <osg/Geode>
Expand All @@ -43,6 +42,7 @@
#include <osgDB/ReadFile>

#include "dart/common/Console.hpp"
#include "dart/common/Filesystem.hpp"
#include "dart/dynamics/MeshShape.hpp"
#include "dart/dynamics/SimpleFrame.hpp"
#include "dart/gui/osg/Utils.hpp"
Expand Down Expand Up @@ -228,8 +228,6 @@ bool checkSpecularSanity(const aiColor4D& c)
//==============================================================================
void MeshShapeNode::extractData(bool firstTime)
{
namespace bf = boost::filesystem;

const aiScene* scene = mMeshShape->getMesh();
const aiNode* root = scene->mRootNode;

Expand Down Expand Up @@ -302,7 +300,7 @@ void MeshShapeNode::extractData(bool firstTime)
textureImageArray.reserve(count);

aiString imagePath;
boost::system::error_code ec;
std::error_code ec;
for (auto j = 0u; j < count; ++j)
{
if ((textureTypeAndCount.first == aiTextureType_NONE)
Expand All @@ -313,10 +311,11 @@ void MeshShapeNode::extractData(bool firstTime)
else
{
aiMat->GetTexture(type, j, &imagePath);
const bf::path meshPath = mMeshShape->getMeshPath();
const bf::path relativeImagePath = imagePath.C_Str();
const bf::path absoluteImagePath
= bf::canonical(relativeImagePath, meshPath.parent_path(), ec);
const common::filesystem::path meshPath = mMeshShape->getMeshPath();
const common::filesystem::path relativeImagePath = imagePath.C_Str();
const common::filesystem::path absoluteImagePath
= common::filesystem::canonical(
relativeImagePath, meshPath.parent_path(), ec);

if (ec)
{
Expand Down
2 changes: 0 additions & 2 deletions dart/utils/mjcf/detail/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

#include "dart/utils/mjcf/detail/Compiler.hpp"

#include <boost/filesystem.hpp>

#include "dart/utils/XmlHelpers.hpp"

namespace dart {
Expand Down

0 comments on commit 49b7b0e

Please sign in to comment.