[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

| HDF5Handle [Import/Export of Images and Arrays in HDF5 Format] |

Wrapper for hid_t objects. More...

`#include <vigra/hdf5impex.hxx>`

List of all members.

## Public Member Functions

herr_t | close ()
| Explicitly call the stored function (if one has been stored within this object) for the contained handle and set the handle to NULL.
hid_t | get () const
| Get a temporary hid_t object for the contained handle. Do not call a close function on the return value - a crash will be likely otherwise.
| HDF5Handle (HDF5Handle const &h)
| Copy constructor. Hands over ownership of the RHS handle (analogous to std::auto_ptr).
| HDF5Handle (hid_t h, Destructor destructor, const char *error_message)
| Create a wrapper for a hid_t object.
| HDF5Handle ()
| Default constuctor. Creates a NULL handle.
| operator hid_t () const
| Convert to a plain hid_t object.
bool | operator!= (hid_t h) const
| Unequality comparison of the contained handle.
bool | operator!= (HDF5Handle const &h) const
| Unequality comparison of the contained handle.
HDF5Handle & | operator= (HDF5Handle const &h)
| Assignment. Calls close() for the LHS handle and hands over ownership of the RHS handle (analogous to std::auto_ptr).
bool | operator== (hid_t h) const
| Equality comparison of the contained handle.
bool | operator== (HDF5Handle const &h) const
| Equality comparison of the contained handle.
| ~HDF5Handle ()
| Destreuctor. Calls close() for the contained handle.

## Detailed Description

Wrapper for hid_t objects.

Newly created or opened HDF5 handles are usually stored as objects of type 'hid_t'. When the handle is no longer needed, the appropriate close function must be called. However, if a function is aborted by an exception, this is difficult to ensure. Class HDF5Handle is a smart pointer that solves this problem by calling the close function in the destructor (This is analogous to how std::auto_ptr calls 'delete' on the contained pointer). A pointer to the close function must be passed to the constructor, along with an error message that is raised when creation/opening fails.

Since HDF5Handle objects are convertible to hid_t, they can be used in the code in place of the latter.

Usage:

        HDF5Handle file_id(H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT),
                           &H5Fclose,
                           "Error message.");

        ... // use file_id in the same way as a plain hid_t object

#include <vigra/hdf5impex.hxx>
Namespace: vigra

## Constructor & Destructor Documentation

HDF5Handle | ( | hid_t | h,
|  | Destructor | destructor,
|  | const char * | error_message |
| ) |  |  |

Create a wrapper for a hid_t object.

The hid_t object h is assumed to be the return value of an open or create function. It will be closed with the given close function destructor as soon as this HDF5Handle is destructed, except when destructor is a NULL pointer (in which case nothing happens at destruction time). If h has a value that indicates failed opening or creation (by HDF5 convention, this means if it is a negative number), an exception is raised by calling `vigra_fail(error_message)`.

Usage:

            HDF5Handle file_id(H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT),
                               &H5Fclose,
                               "Error message.");

            ... // use file_id in the same way

## Member Function Documentation

operator hid_t | ( |  | ) | const

Convert to a plain hid_t object.

This function ensures that hid_t objects can be transparently replaced with HDF5Handle objects in user code. Do not call a close function on the return value - a crash will be likely otherwise.

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

- vigra/hdf5impex.hxx

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.7.1 (3 Dec 2010)