open image files on demand rather than keeping them open: bug #393

This commit is contained in:
brad
2004-10-29 06:30:59 +00:00
parent 134d57c220
commit 58f7d669dc
5 changed files with 128 additions and 166 deletions
+24
View File
@@ -153,6 +153,30 @@ namespace Exiv2 {
byte* pData_;
}; // class DataBuf
/*!
@brief Utility class that closes a file stream pointer upon destruction.
Its primary use is to be a stack variable in functions that need
to ensure files get closed. Useful when functions return errors
from many locations.
*/
class FileCloser {
// Not implemented
//! Copy constructor
FileCloser(const FileCloser&);
//! Assignment operator
FileCloser& operator=(const FileCloser&);
public:
//! Default constructor
FileCloser() : fp_(0) {}
//! Constructor with an initial buffer size
FileCloser(FILE *fp) : fp_(fp) {}
//! Destructor, deletes the allocated buffer
~FileCloser() { close(); }
void close() { if (fp_) fclose(fp_); fp_ = 0; }
//! The file stream pointer
FILE *fp_;
}; // class FileCloser
// *****************************************************************************
// free functions