bioformats  5.1.6
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ome::bioformats::tiff::Sentry Class Reference

Sentry for saving and restoring libtiff state. More...

#include <ome/bioformats/tiff/Sentry.h>

+ Collaboration diagram for ome::bioformats::tiff::Sentry:

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.
 

Detailed Description

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.

Member Function Documentation

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.

Parameters
messagethe message to set.
Exceptions
anException.

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().

+ Here is the caller graph for this function:

void ome::bioformats::tiff::Sentry::error ( ) const

Throw an Exception.

The latest error message will be set as the message.

Exceptions
anException.
void ome::bioformats::tiff::Sentry::errorHandler ( const char *  module,
const char *  fmt,
va_list  ap 
)
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().

Parameters
modulethe module or file emitting the error.
fmtthe format string for the error.
apadditional parameters.

References message.

Referenced by Sentry().

+ Here is the caller graph for this function:

std::string const & ome::bioformats::tiff::Sentry::getMessage ( ) const

Get the latest error message.

If no error has occured, the message will be empty.

Returns
the message.

References message.

Referenced by ome::bioformats::tiff::TIFF::Impl::close().

+ Here is the caller graph for this function:

void ome::bioformats::tiff::Sentry::setMessage ( std::string const &  message)
private

Set the latest error message.

Any previously stored message will be replaced.

Parameters
messagethe message to set.

References message.


The documentation for this class was generated from the following files: