Skip to content

Commit

Permalink
Update to use std::filesystem rather than Boost (#238)
Browse files Browse the repository at this point in the history
This is intended to be a drop-in replacement for the functionality that
is currently in FilesystemBoost, as is demonstrated via no test updates.

Signed-off-by: Michael Carroll <[email protected]>
Co-authored-by: Louise Poubel <[email protected]>
Co-authored-by: Steve Peters <[email protected]>
  • Loading branch information
3 people authored Feb 4, 2022
1 parent 9b790e6 commit fdcb378
Show file tree
Hide file tree
Showing 10 changed files with 325 additions and 1,101 deletions.
2 changes: 1 addition & 1 deletion examples/logging_performance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void WriteToFile(std::string result_filename, std::string content)
std::cerr << "Error writing to " << result_filename << std::endl;
}
out << content << std::flush;
std::cout << content;
//std::cout << content;
}

void MeasurePeakDuringLogWrites(const size_t id, std::vector<uint64_t> &result)
Expand Down
12 changes: 0 additions & 12 deletions include/ignition/common/Filesystem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,6 @@ namespace ignition
/// \param[in] _in Directory to iterate over.
public: explicit DirIter(const std::string &_in);

/// \brief Destructor
public: ~DirIter();

/// \brief Dereference operator; returns current directory record.
/// \return A string representing the entire path of the directory
/// record.
Expand All @@ -282,15 +279,6 @@ namespace ignition
/// \return true if the iterators are equal, false otherwise.
public: bool operator!=(const DirIter &_other) const;

/// \brief Move to the next directory record, skipping . and .. records.
private: void Next();

/// \brief Set the internal variable to the empty string.
private: void SetInternalEmpty();

/// \brief Close an open directory handle.
private: void CloseHandle();

/// \brief Pointer to private data.
IGN_UTILS_IMPL_PTR(dataPtr)
};
Expand Down
13 changes: 0 additions & 13 deletions include/ignition/common/SystemPaths.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@
#ifndef IGNITION_COMMON_SYSTEMPATHS_HH_
#define IGNITION_COMMON_SYSTEMPATHS_HH_

#include <stdio.h>

#ifdef _WIN32
#include <direct.h>
#define GetCurrentDir _getcwd
#else
#include <unistd.h>
#define GetCurrentDir getcwd
#endif

#include <functional>
#include <list>
#include <string>
Expand All @@ -41,9 +31,6 @@ namespace ignition
{
namespace common
{
// Forward declare private data class
class SystemPathsPrivate;

/// \class SystemPaths SystemPaths.hh ignition/common/SystemPaths.hh
/// \brief Functions to handle getting system paths, keeps track of:
/// \li SystemPaths#pluginPaths - plugin library paths
Expand Down
7 changes: 7 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ ign_create_core_library(
SOURCES ${sources}
CXX_STANDARD 17)

if (CMAKE_CXX_COMPILER_ID STREQUAL GNU)
set(CXX_FILESYSTEM_LIBRARIES stdc++fs)
else()
set(CXX_FILESYSTEM_LIBRARIES)
endif()

# Link the libraries that we always need
target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
PRIVATE
${DL_TARGET}
${CXX_FILESYSTEM_LIBRARIES}
PUBLIC
ignition-utils${IGN_UTILS_VER}::ignition-utils${IGN_UTILS_VER}
)
Expand Down
75 changes: 75 additions & 0 deletions src/DirIter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include <filesystem>

#include "ignition/common/Filesystem.hh"

namespace fs = std::filesystem;

namespace ignition
{
namespace common
{

class DirIter::Implementation
{
/// \brief Filesystem iterator that this class is wrapping
public: fs::directory_iterator it;
};

//////////////////////////////////////////////////
DirIter::DirIter():
dataPtr(ignition::utils::MakeImpl<Implementation>())
{
this->dataPtr->it = fs::directory_iterator();
}

//////////////////////////////////////////////////
DirIter::DirIter(const std::string &_in):
DirIter()
{
try
{
this->dataPtr->it = fs::directory_iterator(_in);
}
catch (const fs::filesystem_error &ex)
{
}
}

//////////////////////////////////////////////////
std::string DirIter::operator*() const
{
return this->dataPtr->it->path().string();
}

//////////////////////////////////////////////////
const DirIter &DirIter::operator++()
{
this->dataPtr->it++;
return *this;
}

//////////////////////////////////////////////////
bool DirIter::operator!=(const DirIter &_other) const
{
return (this->dataPtr->it != _other.dataPtr->it);
}

} // namespace common
} // namespace ignition
Loading

0 comments on commit fdcb378

Please sign in to comment.