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

View File

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