Improve File error handling. Massive effects...

API is somewhat stolen from Rust std::fs::File. Static factories didn't work out so well, though. Move semantics made my head explode.
TODO: Still a lot of places where errors aren't handled, but it's an improvement...
This commit is contained in:
Jared Boone
2016-05-16 14:01:44 -07:00
parent d905c446bf
commit 682a1706a3
18 changed files with 328 additions and 235 deletions

View File

@@ -49,10 +49,14 @@ static constexpr std::array<uint8_t, 12> png_iend { {
0xae, 0x42, 0x60, 0x82, // CRC
} };
PNGWriter::PNGWriter(
Optional<File::Error> PNGWriter::create(
const std::string& filename
) : file { filename, File::openmode::out | File::openmode::binary | File::openmode::trunc }
{
) {
const auto create_error = file.create(filename);
if( create_error.is_valid() ) {
return create_error;
}
file.write(png_file_header);
file.write(png_ihdr_screen_capture);
@@ -63,6 +67,8 @@ PNGWriter::PNGWriter(
constexpr std::array<uint8_t, 2> zlib_header { 0x78, 0x01 }; // Zlib CM, CINFO, FLG.
write_chunk_content(zlib_header);
return { };
}
PNGWriter::~PNGWriter() {