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

Update to use std::filesystem rather than Boost #238

Merged
merged 22 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
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;
mjcarroll marked this conversation as resolved.
Show resolved Hide resolved
};

//////////////////////////////////////////////////
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)
{
}
mjcarroll marked this conversation as resolved.
Show resolved Hide resolved
}

//////////////////////////////////////////////////
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