ome-files
0.5.0
|
Sentry for saving and restoring libtiff state. More...
#include <ome/files/tiff/Sentry.h>
Public Member Functions | |
Sentry () | |
Constructor. | |
~Sentry () | |
Destructor. | |
std::string const & | getMessage () const |
Get the latest error message. More... | |
void | error (const std::string &message) const |
Throw an Exception. More... | |
void | error () const |
Throw an Exception. More... | |
Private Member Functions | |
void | setMessage (std::string const &message) |
Set the latest error message. More... | |
Static Private Member Functions | |
static void | errorHandler (const char *module, const char *fmt, va_list ap) |
libtiff error handler. More... | |
Private Attributes | |
std::lock_guard< std::recursive_mutex > | lock |
Acquired lock on tiff_lock. | |
std::string | message |
Last error message. | |
Static Private Attributes | |
static std::recursive_mutex | tiff_mutex |
Mutex to lock libtiff access. | |
Sentry for saving and restoring libtiff state.
This acts primarily to save the state of the global error and warning handlers, which are configured to work with the currently active TIFF/IFD. The original state is restored when destroyed. Note that this exclusively locks all TIFF and IFD methods calling into libtiff, so will potentially block other threads.
This class also hooks into the global libtiff error handling to capture any errors which occur. The latest error will be available using getMessage().
This class should be used at block scope so that instances will only exist transiently until the block ends.
void ome::files::tiff::Sentry::error | ( | const std::string & | message | ) | const |
Throw an Exception.
The latest error message will be set as the message. If no error message has been set, the provided message will be used. This is to cater for the cases where libtiff fails but does not provide any indication of why.
message | the message to set. |
an | Exception. |
Referenced by ome::files::tiff::TIFF::Impl::close(), ome::files::tiff::IFD::getRawField(), ome::files::tiff::IFD::getRawFieldDefaulted(), ome::files::tiff::TIFF::Impl::Impl(), ome::files::tiff::IFD::makeCurrent(), ome::files::tiff::IFD::openIndex(), ome::files::tiff::TIFF::registerImageJTags(), ome::files::tiff::IFD::setRawField(), and ome::files::tiff::TIFF::writeCurrentDirectory().
void ome::files::tiff::Sentry::error | ( | ) | const |
|
staticprivate |
libtiff error handler.
The error message received will be converted to a string and saved in the current Sentry for later retrieval with getMessage().
module | the module or file emitting the error. |
fmt | the format string for the error. |
ap | additional parameters. |
References message.
Referenced by Sentry().
std::string const & ome::files::tiff::Sentry::getMessage | ( | ) | const |
Get the latest error message.
If no error has occured, the message will be empty.
References message.
Referenced by ome::files::tiff::TIFF::Impl::close().
|
private |
Set the latest error message.
Any previously stored message will be replaced.
message | the message to set. |
References message.