Skip to content

Commit bccfcbe

Browse files
committed
feat: Update to c++17 (std::filesystem)
1 parent 5d0d203 commit bccfcbe

File tree

17 files changed

+71
-73
lines changed

17 files changed

+71
-73
lines changed

.github/workflows/build_and_test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ on:
99
jobs:
1010
build:
1111

12-
runs-on: ubuntu-16.04
12+
runs-on: ubuntu-20.04
1313

1414
steps:
1515
- uses: actions/checkout@v2
1616
- name: Install Dependencies
17-
run: sudo apt install cmake libboost-filesystem-dev libboost-test-dev gcc
17+
run: sudo apt install cmake libboost-all-dev libboost-test-dev gcc
1818
- name: Print System Information
1919
run: |
2020
cmake --version

.github/workflows/example.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ on:
99
jobs:
1010
build:
1111

12-
runs-on: ubuntu-16.04
12+
runs-on: ubuntu-20.04
1313

1414
steps:
1515
- uses: actions/checkout@v2
1616
- name: Install Dependencies
17-
run: sudo apt install cmake libboost-filesystem-dev libboost-test-dev gcc
17+
run: sudo apt install cmake libboost-all-dev gcc
1818
- name: Print System Information
1919
run: |
2020
cmake --version
@@ -25,7 +25,7 @@ jobs:
2525
export CXX=g++
2626
export CC=gcc
2727
mkdir build && cd build
28-
cmake ..
28+
cmake .. -DBUILD_TEST=OFF
2929
cmake --build . --target inotify_example
3030
- name: Run example
3131
run: |

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ test/unit/testDirectory/
99
install_manifest.txt
1010
.idea/
1111
**/build/
12-
cmake-build-debug/
12+
cmake-build-debug/
13+
.vscode

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ the implementation of a simple filesystem event watcher for the commandline.
1111
```c++
1212
#include <inotify-cpp/NotifierBuilder.h>
1313

14-
#include <boost/filesystem.hpp>
14+
#include <filesystem>
1515

1616
#include <iostream>
1717
#include <thread>
@@ -27,7 +27,7 @@ int main(int argc, char** argv)
2727
}
2828

2929
// Parse the directory to watch
30-
boost::filesystem::path path(argv[1]);
30+
std::filesystem::path path(argv[1]);
3131

3232
// Set the event handler which will be used to process particular events
3333
auto handleNotification = [&](Notification notification) {
@@ -98,7 +98,7 @@ cmake --build . --target inotify_example
9898
## Dependencies ##
9999
+ lib
100100
+ boost 1.54.0
101-
+ c++11
101+
+ c++17
102102
+ linux 2.6.13
103103
+ build
104104
+ cmake 3.8

example/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ endif()
1313
###############################################################################
1414
find_package(
1515
Boost 1.54.0
16-
COMPONENTS unit_test_framework system filesystem
16+
COMPONENTS unit_test_framework system
1717
REQUIRED
1818
)
1919

@@ -26,10 +26,8 @@ find_package(Threads)
2626
# Target
2727
###############################################################################
2828
add_executable(inotify_example main.cpp)
29+
target_compile_features(inotify_example PRIVATE cxx_std_17)
2930
target_link_libraries(inotify_example
3031
PRIVATE
3132
inotify-cpp::inotify-cpp
32-
Boost::unit_test_framework
33-
Boost::system
34-
Boost::filesystem
3533
${CMAKE_THREAD_LIBS_INIT})

example/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <inotify-cpp/NotifierBuilder.h>
22

3-
#include <boost/filesystem.hpp>
3+
#include <filesystem>
44

55
#include <iostream>
66
#include <thread>
@@ -16,7 +16,7 @@ int main(int argc, char** argv)
1616
}
1717

1818
// Parse the directory to watch
19-
boost::filesystem::path path(argv[1]);
19+
std::filesystem::path path(argv[1]);
2020

2121
// Set the event handler which will be used to process particular events
2222
auto handleNotification = [&](Notification notification) {

src/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ include(GNUInstallDirs)
1515
# dependencies
1616
find_package(
1717
Boost 1.54.0
18-
COMPONENTS system filesystem
1918
REQUIRED
2019
)
2120

@@ -40,8 +39,7 @@ macro(configure_target target)
4039
target_include_directories(${target} PUBLIC
4140
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
4241
$<INSTALL_INTERFACE:include>)
43-
target_link_libraries(${target}
44-
INTERFACE Boost::system Boost::filesystem)
42+
target_compile_features(${target} PRIVATE cxx_std_17)
4543
endmacro(configure_target target)
4644

4745
# library definition

src/FileSystemEvent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace inotify {
66
FileSystemEvent::FileSystemEvent(
77
const int wd,
88
uint32_t mask,
9-
const boost::filesystem::path& path,
9+
const std::filesystem::path& path,
1010
const std::chrono::steady_clock::time_point& eventTime)
1111
: wd(wd)
1212
, mask(mask)

src/Inotify.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11

22
#include <inotify-cpp/Inotify.h>
33

4+
#include <iostream>
5+
#include <optional>
46
#include <string>
57
#include <vector>
6-
#include <iostream>
78

89
#include <sys/epoll.h>
910
#include <fcntl.h>
1011
#include <unistd.h>
1112

12-
namespace fs = boost::filesystem;
13+
namespace fs = std::filesystem;
1314

1415
namespace inotify {
1516

@@ -97,14 +98,15 @@ Inotify::~Inotify()
9798
*/
9899
void Inotify::watchDirectoryRecursively(fs::path path)
99100
{
100-
std::vector<boost::filesystem::path> paths;
101+
std::vector<std::filesystem::path> paths;
101102

102103
if (fs::exists(path)) {
103104
paths.push_back(path);
104105

105106
if (fs::is_directory(path)) {
106-
boost::system::error_code ec;
107-
fs::recursive_directory_iterator it(path, fs::symlink_option::recurse, ec);
107+
std::error_code ec;
108+
fs::recursive_directory_iterator it(
109+
path, fs::directory_options::follow_directory_symlink, ec);
108110
fs::recursive_directory_iterator end;
109111

110112
for (; it != end; it.increment(ec)) {
@@ -234,7 +236,7 @@ void Inotify::setEventTimeout(
234236
* @return A new FileSystemEvent
235237
*
236238
*/
237-
boost::optional<FileSystemEvent> Inotify::getNextEvent()
239+
std::optional<FileSystemEvent> Inotify::getNextEvent()
238240
{
239241
std::vector<FileSystemEvent> newEvents;
240242

@@ -245,7 +247,7 @@ boost::optional<FileSystemEvent> Inotify::getNextEvent()
245247
}
246248

247249
if (mStopped) {
248-
return boost::none;
250+
return std::nullopt;
249251
}
250252

251253
auto event = mEventQueue.front();

src/Notification.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace inotify {
44

55
Notification::Notification(
66
const Event& event,
7-
const boost::filesystem::path& path,
7+
const std::filesystem::path& path,
88
std::chrono::steady_clock::time_point time)
99
: event(event)
1010
, path(path)

0 commit comments

Comments
 (0)