Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of boost::filesystem and boost::optional #1648

Merged
merged 5 commits into from
Jan 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Added spdlog support as underlying logging framework: [#1633](https://github.com/dartsim/dart/pull/1633)
* Added custom memory allocators: [#1636](https://github.com/dartsim/dart/pull/1636), [#1637](https://github.com/dartsim/dart/pull/1637), [#1639](https://github.com/dartsim/dart/pull/1639), [#1645](https://github.com/dartsim/dart/pull/1645), [#1646](https://github.com/dartsim/dart/pull/1646)
* Added Stopwatch class to replace Timer: [#1638](https://github.com/dartsim/dart/pull/1638)
* Removed use of boos::filesystem and boost::optional: [#1648](https://github.com/dartsim/dart/pull/1648)

* Dynamics

Expand Down
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
112 changes: 112 additions & 0 deletions dart/common/Filesystem.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (c) 2011-2022, 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.
*/

#ifndef DART_COMMON_FILESYSTEM_HPP_
#define DART_COMMON_FILESYSTEM_HPP_

#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

#endif // #ifndef DART_COMMON_FILESYSTEM_HPP_
12 changes: 2 additions & 10 deletions dart/common/Optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,14 @@
#ifndef DART_COMMON_OPTIONAL_HPP_
#define DART_COMMON_OPTIONAL_HPP_

#if __cplusplus >= 201703L
#include <optional>
#else
#include <boost/optional.hpp>
#endif
#include <optional>

namespace dart {
namespace common {

#if __cplusplus >= 201703L
/// \deprecated Use std::optional instead
template <class T>
using optional = std::optional<T>;
#else
template <class T>
using optional = boost::optional<T>;
#endif

} // namespace common
} // namespace dart
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(
meshPath.parent_path() / relativeImagePath, ec);

if (ec)
{
Expand Down
2 changes: 1 addition & 1 deletion dart/utils/mjcf/detail/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace detail {
//==============================================================================
Errors Body::read(
tinyxml2::XMLElement* element,
const common::optional<Size>& size,
const std::optional<Size>& size,
const Defaults& defaults,
const Default* currentDefault)
{
Expand Down
2 changes: 1 addition & 1 deletion dart/utils/mjcf/detail/Body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Body final
friend class Worldbody;
Errors read(
tinyxml2::XMLElement* element,
const common::optional<Size>& size,
const std::optional<Size>& size,
const Defaults& defaults,
const Default* currentDefault);

Expand Down
2 changes: 1 addition & 1 deletion dart/utils/mjcf/detail/BodyAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace detail {
Errors appendBodyAttributes(
BodyAttributes& attributes,
tinyxml2::XMLElement* element,
const common::optional<Size>& size)
const std::optional<Size>& size)
{
Errors errors;

Expand Down
Loading