From c5191cec35caabeb7fbc86dafa38b5272e466273 Mon Sep 17 00:00:00 2001 From: Vladyslav Usenko Date: Tue, 28 Apr 2020 19:35:04 +0200 Subject: [PATCH] fix filesystem warnings --- include/basalt/utils/filesystem.h | 66 +++++++++++++++++++++++++++++++ src/rs_t265_record.cpp | 16 ++++---- src/time_alignment.cpp | 8 ++-- 3 files changed, 79 insertions(+), 11 deletions(-) diff --git a/include/basalt/utils/filesystem.h b/include/basalt/utils/filesystem.h index 4629bf8..27b6d28 100644 --- a/include/basalt/utils/filesystem.h +++ b/include/basalt/utils/filesystem.h @@ -1,4 +1,70 @@ #pragma once +// Check for feature test macro for +#if defined(__cpp_lib_filesystem) +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0 + +// Check for feature test macro for +#elif defined(__cpp_lib_experimental_filesystem) +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 + +// We can't check if headers exist... +// Let's assume experimental to be safe +#elif !defined(__has_include) +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 + +// Check if the header "" exists +#elif __has_include() + +// 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() +#include + +// 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 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 INCLUDE_STD_FILESYSTEM_EXPERIMENTAL +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 +#endif + +// Not on Visual Studio. Let's use the normal version +#else // #ifdef _MSC_VER +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0 +#endif + +// Check if the header "" exists +#elif __has_include() +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 + +// Fail if neither header is available with a nice error message +#else +#error Could not find system header "" or "" +#endif + +// We priously determined that we need the exprimental version +#if INCLUDE_STD_FILESYSTEM_EXPERIMENTAL #include + +namespace basalt { namespace fs = std::experimental::filesystem; +} + +// We have a decent compiler and can use the normal version +#else +#include + +namespace basalt { +namespace fs = std::filesystem; +} + +#endif diff --git a/src/rs_t265_record.cpp b/src/rs_t265_record.cpp index f440008..1569fda 100644 --- a/src/rs_t265_record.cpp +++ b/src/rs_t265_record.cpp @@ -237,13 +237,13 @@ void startRecording(const std::string &dir_path) { dataset_dir = dir_path + "dataset_" + get_date() + "/"; - fs::create_directory(dataset_dir); - fs::create_directory(dataset_dir + "mav0/"); - fs::create_directory(dataset_dir + "mav0/cam0/"); - fs::create_directory(dataset_dir + "mav0/cam0/data/"); - fs::create_directory(dataset_dir + "mav0/cam1/"); - fs::create_directory(dataset_dir + "mav0/cam1/data/"); - fs::create_directory(dataset_dir + "mav0/imu0/"); + basalt::fs::create_directory(dataset_dir); + basalt::fs::create_directory(dataset_dir + "mav0/"); + basalt::fs::create_directory(dataset_dir + "mav0/cam0/"); + basalt::fs::create_directory(dataset_dir + "mav0/cam0/data/"); + basalt::fs::create_directory(dataset_dir + "mav0/cam1/"); + basalt::fs::create_directory(dataset_dir + "mav0/cam1/data/"); + basalt::fs::create_directory(dataset_dir + "mav0/imu0/"); cam_data[0].open(dataset_dir + "mav0/cam0/data.csv"); cam_data[1].open(dataset_dir + "mav0/cam1/data.csv"); @@ -252,7 +252,7 @@ void startRecording(const std::string &dir_path) { imu0_data.open(dataset_dir + "mav0/imu0/data.csv"); if (!manual_exposure) { - fs::create_directory(dataset_dir + "mav0/realsense0/"); + basalt::fs::create_directory(dataset_dir + "mav0/realsense0/"); pose_data.open(dataset_dir + "mav0/realsense0/data.csv"); pose_data << "#timestamp [ns], p_RS_R_x [m], p_RS_R_y [m], p_RS_R_z [m], " "q_RS_w [], q_RS_x [], q_RS_y [], q_RS_z []\n"; diff --git a/src/time_alignment.cpp b/src/time_alignment.cpp index 99e0694..925ca8b 100644 --- a/src/time_alignment.cpp +++ b/src/time_alignment.cpp @@ -414,13 +414,15 @@ int main(int argc, char **argv) { std::string save_button_name = "ui.save_aligned_dataset"; // Disable save_aligned_dataset button if GT data already exists - if (fs::exists(fs::path(dataset_path + "mav0/gt/data.csv"))) { + if (basalt::fs::exists( + basalt::fs::path(dataset_path + "mav0/gt/data.csv"))) { save_button_name += "(disabled)"; } pangolin::Var> save_aligned_dataset( save_button_name, [&]() { - if (fs::exists(fs::path(dataset_path + "mav0/gt/data.csv"))) { + if (basalt::fs::exists( + basalt::fs::path(dataset_path + "mav0/gt/data.csv"))) { std::cout << "Aligned ground-truth data already exists, skipping. " "If you want to run the calibration again delete " << dataset_path << "mav0/gt/ folder." << std::endl; @@ -431,7 +433,7 @@ int main(int argc, char **argv) { // output corrected mocap data Sophus::SE3d T_mark_i; if (use_calib) T_mark_i = mocap_calib.T_i_mark.inverse(); - fs::create_directory(dataset_path + "mav0/gt/"); + basalt::fs::create_directory(dataset_path + "mav0/gt/"); std::ofstream gt_out_stream; gt_out_stream.open(dataset_path + "mav0/gt/data.csv"); gt_out_stream