Skip to content
Snippets Groups Projects
Commit 20e23e19 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Merge branch 'feature/stdfs' into 'master'

use std::filesystem

See merge request nicolas.pope/ftl!334
parents 423c33db 723e581e
No related branches found
No related tags found
1 merge request!334use std::filesystem
Pipeline #29137 passed
......@@ -12,6 +12,7 @@ set(COMMONSRC
src/timer.cpp
src/profiler.cpp
src/exception.cpp
src/file.cpp
src/utility/base64.cpp
)
......@@ -27,7 +28,11 @@ target_include_directories(ftlcommon PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE src)
target_link_libraries(ftlcommon Threads::Threads Eigen3::Eigen ${OS_LIBS} ${OpenCV_LIBS} ${URIPARSER_LIBRARIES} ${CUDA_LIBRARIES})
# for gcc < 9, not required for newer versions
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CXX_FILESYSTEM_LIBRARIES "stdc++fs")
endif()
target_link_libraries(ftlcommon Threads::Threads Eigen3::Eigen ${OS_LIBS} ${OpenCV_LIBS} ${URIPARSER_LIBRARIES} ${CUDA_LIBRARIES} ${CXX_FILESYSTEM_LIBRARIES})
target_precompile_headers(ftlcommon
PRIVATE include/ftl/cuda_common.hpp
......
......@@ -20,7 +20,6 @@ extern std::string branch_name;
class Configurable;
bool is_directory(const std::string &path);
bool is_file(const std::string &path);
bool create_directory(const std::string &path);
bool is_video(const std::string &file);
std::vector<std::string> directory_listing(const std::string &path);
......
#ifndef _FTL_FILES_HPP_
#define _FTL_FILES_HPP_
#if defined(__GNUC__) && __GNUC__ < 8
#include <experimental/filesystem>
namespace std {
namespace filesystem = experimental::filesystem;
}
#else
#include <filesystem>
#endif
namespace ftl {
namespace file {
std::filesystem::path home_dir();
std::filesystem::path config_dir();
std::filesystem::path config_dir(const std::filesystem::path& subdirectory);
bool is_file(const std::filesystem::path &path);
}
}
#endif
\ No newline at end of file
......@@ -23,6 +23,7 @@
#include <ftl/threads.hpp>
#include <ftl/timer.hpp>
#include <ftl/cuda_common.hpp>
#include <ftl/file.hpp>
#include <ftl/profiler.hpp>
......@@ -39,7 +40,10 @@ using std::string;
using std::map;
using std::vector;
using std::optional;
using ftl::is_file;
using ftl::file::is_file;
using ftl::file::config_dir;
using ftl::is_directory;
using ftl::Configurable;
......@@ -77,21 +81,6 @@ bool ftl::is_directory(const std::string &path) {
#endif
}
bool ftl::is_file(const std::string &path) {
#ifdef WIN32
DWORD attrib = GetFileAttributesA(path.c_str());
if (attrib == INVALID_FILE_ATTRIBUTES) return false;
else return !(attrib & FILE_ATTRIBUTE_DIRECTORY);
#else
struct stat s;
if (::stat(path.c_str(), &s) == 0) {
return S_ISREG(s.st_mode);
} else {
return false;
}
#endif
}
std::vector<std::string> ftl::directory_listing(const std::string &path) {
std::vector<std::string> res;
......@@ -125,7 +114,7 @@ std::vector<std::string> ftl::directory_listing(const std::string &path) {
}
static bool endsWith(const string &s, const string &e) {
return s.size() >= e.size() &&
return s.size() >= e.size() &&
s.compare(s.size() - e.size(), e.size(), e) == 0;
}
......@@ -155,7 +144,7 @@ optional<string> ftl::config::locateFile(const string &name) {
if (is_file(name)) return name;
auto paths = rootCFG->getConfig()["paths"];
if (paths.is_array()) {
vector<string> vpaths = paths.get<vector<string>>();
for (string p : vpaths) {
......@@ -163,16 +152,16 @@ optional<string> ftl::config::locateFile(const string &name) {
if (is_file(p+"/"+name)) {
return p+"/"+name;
}
} else if (p.size() >= name.size() &&
} else if (p.size() >= name.size() &&
p.compare(p.size() - name.size(), name.size(), name) == 0 &&
is_file(p)) {
return p;
}
}
}
if (is_file("./"+name)) return "./"+name;
if (is_file(string(FTL_LOCAL_CONFIG_ROOT) +"/"+ name)) return string(FTL_LOCAL_CONFIG_ROOT) +"/"+ name;
if (is_file(config_dir("ftl") / name)) return (ftl::file::config_dir("ftl") / name).string();
if (is_file(string(FTL_GLOBAL_CONFIG_ROOT) +"/"+ name)) return string(FTL_GLOBAL_CONFIG_ROOT) +"/"+ name;
return {};
}
......@@ -287,7 +276,7 @@ ftl::Configurable *ftl::config::find(const std::string &uri) {
}
SHARED_LOCK(mutex, lk);
auto ix = config_instance.find(actual_uri);
if (ix == config_instance.end()) {
auto ix = config_alias.find(actual_uri);
......@@ -512,7 +501,7 @@ json_t &ftl::config::resolve(json_t &j) {
static bool findConfiguration(const string &file, const vector<string> &paths) {
bool f = false;
bool found = false;
if (file.length() > 0) {
f = mergeConfig(file.substr(1,file.length()-2));
found |= f;
......@@ -546,7 +535,7 @@ static bool findConfiguration(const string &file, const vector<string> &paths) {
f = mergeConfig("./config.jsonc");
found |= f;
if (f) LOG(INFO) << "Loaded config: " << "./config.jsonc";
for (auto p : paths) {
if (is_directory(p)) {
f = mergeConfig(p+"/config.json");
......@@ -648,8 +637,8 @@ static void signalIntHandler( int signum ) {
if (sig_int_called) quick_exit(-1);
sig_int_called = true;
// cleanup and close up stuff here
// terminate program
// cleanup and close up stuff here
// terminate program
ftl::running = false;
}
......@@ -871,7 +860,7 @@ Configurable *ftl::config::configure(int argc, char **argv, const std::string &r
// Process Arguments
auto options = ftl::config::read_options(&argv, &argc);
vector<string> paths(argc);
while (argc-- > 0) {
paths.push_back(argv[0]);
......
#include "ftl/file.hpp"
#include <cstdlib>
using std::filesystem::path;
namespace ftl {
namespace file {
path home_dir() {
char* home;
#if defined(_MSC_VER)
home = std::getenv("HOMEPATH");
#elif defined(__GNUC__)
home = std::getenv("HOME");
#else
static_assert(false, "unsupported compiler");
#endif
return std::filesystem::absolute(path(home));
}
path config_dir(const path& subdir) {
#if defined(_MSC_VER)
return path(std::getenv("APPDATA")) / subdir;
#elif defined(__GNUC__)
return home_dir() / ".config";
#else
static_assert(false, "unsupported compiler");
#endif
}
path config_dir() {
return config_dir(path());
}
bool is_file(const path& p) {
return std::filesystem::is_regular_file(p);
}
}
}
#include <loguru.hpp>
#include <ftl/file.hpp>
#include <ftl/rgbd/source.hpp>
#include "basesource.hpp"
#include <ftl/threads.hpp>
......@@ -29,6 +31,8 @@ using ftl::rgbd::detail::ScreenCapture;
using ftl::codecs::Channel;
using ftl::rgbd::Camera;
using ftl::file::is_file;
Source::Source(ftl::config::json_t &cfg) : Configurable(cfg) {
impl_ = nullptr;
stream_ = 0;
......@@ -57,7 +61,7 @@ static ftl::rgbd::BaseSourceImpl *createFileImpl(const ftl::URI &uri, Source *ho
if (eix == string::npos) {
// Might be a directory
if (ftl::is_directory(path)) {
if (ftl::is_file(path + "/video.mp4")) {
if (is_file(path + "/video.mp4")) {
return new StereoVideoSource(host, path);
// } else if (ftl::is_file(path + "/im0.png")) {
// return new MiddleburySource(this, path);
......@@ -67,7 +71,7 @@ static ftl::rgbd::BaseSourceImpl *createFileImpl(const ftl::URI &uri, Source *ho
} else {
return nullptr;
}
} else if (ftl::is_file(path)) {
} else if (is_file(path)) {
string ext = path.substr(eix+1);
if (ext == "ftl") {
......@@ -81,7 +85,7 @@ static ftl::rgbd::BaseSourceImpl *createFileImpl(const ftl::URI &uri, Source *ho
} else if (ext == "mp4") {
return new StereoVideoSource(host, path);
} else {
LOG(WARNING) << "Unrecognised file type: " << path;
LOG(WARNING) << "Unrecognised file type: " << path;
}
} else {
LOG(WARNING) << "File does not exist: " << path;
......
#include <loguru.hpp>
#include <ftl/file.hpp>
#include <unordered_set>
#include <Eigen/Eigen>
......@@ -42,6 +44,7 @@ using ftl::codecs::Channel;
using std::string;
using ftl::rgbd::Capability;
using ftl::file::config_dir;
static cv::Mat rmat(const cv::Vec3d &rvec) {
cv::Mat R(cv::Size(3, 3), CV_64FC1);
......@@ -165,10 +168,12 @@ void StereoVideoSource::init(const string &file) {
}
else {
fname_calib_ = fname_config ? *fname_config :
string(FTL_LOCAL_CONFIG_ROOT) + "/"
+ std::string("calibration.yml");
(config_dir() / "ftl" / "calibration.yml").string();
LOG(ERROR) << "No calibration file found, calibration will be saved to " + fname;
LOG(ERROR) << "No calibration file found in "
<< fname_calib_
<< ". Calibration will be saved to "
<< fname;
}
// Generate camera parameters for next frame
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment