ome-files  0.5.0
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ome::files::tiff::Sentry Class Reference

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

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

+ Collaboration diagram for ome::files::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

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.
 

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

◆ error() [1/2]

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.

Parameters
messagethe message to set.
Exceptions
anException.

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

+ Here is the caller graph for this function:

◆ error() [2/2]

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

Throw an Exception.

The latest error message will be set as the message.

Exceptions
anException.

◆ errorHandler()

void ome::files::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:

◆ getMessage()

std::string const & ome::files::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::files::tiff::TIFF::Impl::close().

+ Here is the caller graph for this function:

◆ setMessage()

void ome::files::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: