aboutsummaryrefslogtreecommitdiff
path: root/BuddhaTest/include
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2018-03-10 12:52:52 +0100
committerAndreas Grois <andi@grois.info>2018-03-10 12:52:52 +0100
commitc44d5f06fcea7af11d03f62a2670030c65ad0089 (patch)
tree0c6142932a66e95ff3553466f21c8bc9e5445a6d /BuddhaTest/include
parentf1a53b120ee5ebfdcd13d178c459188ea8451ee8 (diff)
Make sure png file gets closed by wrapping the file descriptor into a
class with destructor
Diffstat (limited to 'BuddhaTest/include')
-rw-r--r--BuddhaTest/include/Helpers.h13
1 files changed, 13 insertions, 0 deletions
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 <glad/glad.h>
#include <GLFW/glfw3.h>
#include <vector>
+#include <stdio.h> //includes FILE typedef
namespace Helpers
{
@@ -9,4 +10,16 @@ namespace Helpers
GLuint LoadComputeShader(const char * compute_file_path);
void WriteOutputPNG(const std::vector<uint32_t>& 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;
+ };
}