From c44d5f06fcea7af11d03f62a2670030c65ad0089 Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Sat, 10 Mar 2018 12:52:52 +0100 Subject: Make sure png file gets closed by wrapping the file descriptor into a class with destructor --- BuddhaTest/include/Helpers.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'BuddhaTest/include/Helpers.h') diff --git a/BuddhaTest/include/Helpers.h b/BuddhaTest/include/Helpers.h index c24e2c7..ad14305 100644 --- a/BuddhaTest/include/Helpers.h +++ b/BuddhaTest/include/Helpers.h @@ -2,6 +2,7 @@ #include #include #include +#include //includes FILE typedef namespace Helpers { @@ -9,4 +10,16 @@ namespace Helpers GLuint LoadComputeShader(const char * compute_file_path); void WriteOutputPNG(const std::vector& data, unsigned int width, unsigned int height); + + /** Wraps around a C file descriptor. Libpng could be taught to use C++ streams, but I'm too lazy and rather wrap this ugly thing up, so it gets cleaned... */ + class ScopedCFileDescriptor + { + public: + ScopedCFileDescriptor(const char *path, const char *mode); + ~ScopedCFileDescriptor(); + FILE * Get() const; + bool IsValid() const; + private: + FILE * Descriptor; + }; } -- cgit v1.2.3