Open GPMueller opened 7 years ago
Problematically, the code does not complain when a file cannot be written and just continues running. This is likely undesirable behaviour in most cases.
I think it is OK for the code to continue in case of an error, but maybe an input variable to set the level when the code should stop (i.e. warning, error or severe) would be a good idea?
Also, we could add an ifdef
part which creates a folder using C++17, if available.
https://github.com/gulrak/filesystem could be used. It is absolutely sufficient for the use-cases of spirit and fortunately, it also works with emscripten 👍
If gulrak/filesystem should only be used when std::filesystem is not available, one can use the following code (though I would recommend against it because std::filesystem still requires some compiler flags depending on compiler versions, even in C++17 mode)
#if defined( __cplusplus ) && __cplusplus >= 201703L && defined( __has_include )
#if __has_include( <filesystem>)
#define GHC_USE_STD_FS
#include <filesystem>
namespace fs = std::filesystem;
#endif
#endif
#ifndef GHC_USE_STD_FS
#include <ghc/filesystem.hpp>
namespace fs = ghc::filesystem;
#endif
https://github.com/gulrak/filesystem is already being used by the IMGUI on the feature-imgui
branch. When the corresponding PR #583 is merged, it could be used by both ui-cpp
and core
(as is already done with fmt
.
Improved file reading and writing with commits d1fe9f8909e5ec3169d0eed5a0fe06465b0d9848 and 18bf5d4cdd962389c110dd870ed0112a8b827b9b, respectively. There's now both a FilterFileHandle
and OutFileHandle
, for which it would make sense to use fs::exists
, fs::is_directory
/fs::is_regular_file
, fs::create_directories
.
One could even use fs::is_empty
to detect when a file is being _over_written instead of just written.
Note that fs::current_path
gives the current working directory and that fs::weakly_canonical
can be used for paths that might not exist (it resolves the absolute path as far as possible and keeps the non-existent parts as well).
Maybe this is not so doable currently.
The C++17 Filesystem TS might be a possibility...