bioformats
5.1.8
|
Sentry for saving and restoring libtiff state. More...
#include <ome/bioformats/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 | |
boost::lock_guard< boost::recursive_mutex > | lock |
Acquired lock on tiff_lock. | |
std::string | message |
Last error message. | |
Static Private Attributes | |
static boost::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::bioformats::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::bioformats::tiff::TIFF::Impl::close(), ome::bioformats::tiff::TIFF::getDirectoryByIndex(), ome::bioformats::tiff::TIFF::getDirectoryByOffset(), ome::bioformats::tiff::IFD::getRawField(), ome::bioformats::tiff::TIFF::Impl::Impl(), ome::bioformats::tiff::IFD::makeCurrent(), ome::bioformats::tiff::IFD::openIndex(), ome::bioformats::tiff::TIFF::registerImageJTags(), ome::bioformats::tiff::IFD::setRawField(), and ome::bioformats::tiff::TIFF::writeCurrentDirectory().
void ome::bioformats::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::bioformats::tiff::Sentry::getMessage | ( | ) | const |
Get the latest error message.
If no error has occured, the message will be empty.
References message.
Referenced by ome::bioformats::tiff::TIFF::Impl::close().
|
private |
Set the latest error message.
Any previously stored message will be replaced.
message | the message to set. |
References message.