Expose filesystem errors on Writer.

This commit is contained in:
Jared Boone 2016-05-12 21:57:38 -07:00
parent 8655b6d915
commit 87505f833b
2 changed files with 20 additions and 0 deletions

View File

@ -26,6 +26,9 @@
#include "event_m0.hpp" #include "event_m0.hpp"
#include "file.hpp"
#include "optional.hpp"
#include <cstdint> #include <cstdint>
#include <cstddef> #include <cstddef>
#include <utility> #include <utility>
@ -33,6 +36,7 @@
class Writer { class Writer {
public: public:
virtual bool write(const void* const buffer, const size_t bytes) = 0; virtual bool write(const void* const buffer, const size_t bytes) = 0;
virtual Optional<std::filesystem::filesystem_error> error() const = 0;
virtual ~Writer() = default; virtual ~Writer() = default;
}; };

View File

@ -44,6 +44,14 @@ public:
return file.write(buffer, bytes); return file.write(buffer, bytes);
} }
Optional<std::filesystem::filesystem_error> error() const override {
if( file.bad() ) {
return { file.error() };
} else {
return { };
}
}
private: private:
File file; File file;
}; };
@ -71,6 +79,14 @@ public:
return success; return success;
} }
Optional<std::filesystem::filesystem_error> error() const override {
if( file.bad() ) {
return { file.error() };
} else {
return { };
}
}
private: private:
struct fmt_pcm_t { struct fmt_pcm_t {
constexpr fmt_pcm_t( constexpr fmt_pcm_t(