Hugin trunk 0.1
Loading...
Searching...
No Matches
FileRAII.h
Go to the documentation of this file.
1
21#include <string>
22#include <cstdio>
23#include <cerrno>
24
25#include <vigra/error.hxx>
26
27namespace vigra_ext
28{
34{
35public:
41 FileRAII(const char *path, const char *mode)
42 {
43 file = std::fopen(path, mode);
44 if (file == 0) {
45 std::string msg("Unable to open file '");
46 msg += path;
47 msg += "'.";
48 vigra_precondition(0, msg.c_str());
49 }
50 }
51
53 {
54 if (file) {
55 errno = 0;
56 if (std::fclose(file)) {
57 // there are several possible errors, handle some of them
58 std::string msg;
59 switch(errno)
60 {
61 case EBADF:
62 msg = "Bad file descriptor.";
63 break;
64 case EIO:
65 msg = "An I/O error occurred while closing the file.";
66 break;
67 default:
68 msg = "An error ocured while closing the file.";
69 break;
70 }
71 vigra_postcondition(0, msg.c_str());
72 }
73 }
74 }
75
80 {
81 return file;
82 }
83
84private:
86
87 // this class should never be copied or assigned
90};
91
92}
Class used for opening files.
Definition FileRAII.h:34
FileRAII(const char *path, const char *mode)
Open the specified file.
Definition FileRAII.h:41
FileRAII & operator=(const FileRAII &)
FILE * get()
Get pointer to opened file.
Definition FileRAII.h:79
FileRAII(const FileRAII &)
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.
Definition threshold.h:41