Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-18 09:16:07

0001 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
0002  * Copyright by The HDF Group.                                               *
0003  * All rights reserved.                                                      *
0004  *                                                                           *
0005  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
0006  * terms governing use, modification, and redistribution, is contained in    *
0007  * the COPYING file, which can be found at the root of the source code       *
0008  * distribution tree, or in https://www.hdfgroup.org/licenses.               *
0009  * If you do not have access to either file, you may request a copy from     *
0010  * help@hdfgroup.org.                                                        *
0011  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0012 
0013 /*
0014  * This file contains public declarations for the H5Z (data filter) developer
0015  *      support routines.
0016  */
0017 
0018 #ifndef H5Zdevelop_H
0019 #define H5Zdevelop_H
0020 
0021 /* Include package's public header */
0022 #include "H5Zpublic.h"
0023 
0024 /*****************/
0025 /* Public Macros */
0026 /*****************/
0027 
0028 /**
0029  * Current version of the H5Z_class_t struct
0030  */
0031 #define H5Z_CLASS_T_VERS (1)
0032 
0033 /*******************/
0034 /* Public Typedefs */
0035 /*******************/
0036 
0037 /**
0038  * Structure for filter callback property
0039  */
0040 typedef struct H5Z_cb_t {
0041     H5Z_filter_func_t func;
0042     void             *op_data;
0043 } H5Z_cb_t;
0044 
0045 /**
0046  * \brief This callback determines if a filter can be applied to the dataset
0047  *        with the characteristics provided
0048  *
0049  * \dcpl_id
0050  * \type_id
0051  * \space_id
0052  *
0053  * \return \htri_t
0054  *
0055  * \details Before a dataset gets created, the \ref H5Z_can_apply_func_t
0056  *          callbacks for any filters used in the dataset creation property list
0057  *          are called with the dataset's dataset creation property list, the
0058  *          dataset's datatype and a dataspace describing a chunk (for chunked
0059  *          dataset storage).
0060  *
0061  *          The \ref H5Z_can_apply_func_t callback must determine if the
0062  *          combination of the dataset creation property list setting, the
0063  *          datatype and the dataspace represent a valid combination to apply
0064  *          this filter to.  For example, some cases of invalid combinations may
0065  *          involve the filter not operating correctly on certain datatypes (or
0066  *          certain datatype sizes), or certain sizes of the chunk dataspace.
0067  *
0068  *          The \ref H5Z_can_apply_func_t callback can be the NULL pointer, in
0069  *          which case, the library will assume that it can apply to any
0070  *          combination of dataset creation property list values, datatypes and
0071  *          dataspaces.
0072  *
0073  *          The \ref H5Z_can_apply_func_t callback returns positive a valid
0074  *          combination, zero for an invalid combination and negative for an
0075  *          error.
0076  */
0077 //! <!-- [H5Z_can_apply_func_t_snip] -->
0078 typedef htri_t (*H5Z_can_apply_func_t)(hid_t dcpl_id, hid_t type_id, hid_t space_id);
0079 //! <!-- [H5Z_can_apply_func_t_snip] -->
0080 
0081 /**
0082  * \brief The filter operation callback function, defining a filter's operation
0083  *        on data
0084  *
0085  * \dcpl_id
0086  * \type_id
0087  * \space_id
0088  *
0089  * \return \herr_t
0090  *
0091  * \details After the \ref H5Z_can_apply_func_t callbacks are checked for new
0092  *          datasets, the \ref H5Z_set_local_func_t callbacks for any filters
0093  *          used in the dataset creation property list are called. These
0094  *          callbacks receive the dataset's private copy of the dataset creation
0095  *          property list passed in to H5Dcreate() (i.e. not the actual property
0096  *          list passed in to H5Dcreate()) and the datatype ID passed in to
0097  *          H5Dcreate() (which is not copied and should not be modified) and a
0098  *          dataspace describing the chunk (for chunked dataset storage) (which
0099  *          should also not be modified).
0100  *
0101  *          The \ref H5Z_set_local_func_t callback must set any parameters that
0102  *          are specific to this dataset, based on the combination of the
0103  *          dataset creation property list values, the datatype and the
0104  *          dataspace. For example, some filters perform different actions based
0105  *          on different datatypes (or datatype sizes) or different number of
0106  *          dimensions or dataspace sizes.
0107  *
0108  *          The \ref H5Z_set_local_func_t callback can be the NULL pointer, in
0109  *          which case, the library will assume that there are no
0110  *          dataset-specific settings for this filter.
0111  *
0112  *          The \ref H5Z_set_local_func_t callback must return non-negative on
0113  *          success and negative for an error.
0114  */
0115 //! <!-- [H5Z_set_local_func_t_snip] -->
0116 typedef herr_t (*H5Z_set_local_func_t)(hid_t dcpl_id, hid_t type_id, hid_t space_id);
0117 //! <!-- [H5Z_set_local_func_t_snip] -->
0118 
0119 /**
0120  * \brief The filter operation callback function, defining a filter's operation
0121  *        on data
0122  *
0123  * \param[in] flags Bit vector specifying certain general properties of the filter
0124  * \param[in] cd_nelmts Number of elements in \p cd_values
0125  * \param[in] cd_values Auxiliary data for the filter
0126  * \param[in] nbytes The number of valid bytes in \p buf to be filtered
0127  * \param[in,out] buf_size The size of \p buf
0128  * \param[in,out] buf The filter buffer
0129  *
0130  * \return Returns the number of valid bytes of data contained in \p buf. In the
0131  *         case of failure, the return value is 0 (zero) and all pointer
0132  *         arguments are left unchanged.
0133  *
0134  * \details A filter gets definition flags and invocation flags (defined
0135  *          above), the client data array and size defined when the filter was
0136  *          added to the pipeline, the size in bytes of the data on which to
0137  *          operate, and pointers to a buffer and its allocated size.
0138  *
0139  *          The filter should store the result in the supplied buffer if
0140  *          possible, otherwise it can allocate a new buffer, freeing the
0141  *          original. The allocated size of the new buffer should be returned
0142  *          through the \p buf_size pointer and the new buffer through the \p
0143  *          buf pointer.
0144  *
0145  *          The return value from the filter is the number of bytes in the
0146  *          output buffer. If an error occurs then the function should return
0147  *          zero and leave all pointer arguments unchanged.
0148  *
0149  * \since 1.0.0
0150  *
0151  */
0152 //! <!-- [H5Z_func_t_snip] -->
0153 typedef size_t (*H5Z_func_t)(unsigned int flags, size_t cd_nelmts, const unsigned int cd_values[],
0154                              size_t nbytes, size_t *buf_size, void **buf);
0155 //! <!-- [H5Z_func_t_snip] -->
0156 
0157 /**
0158  * The filter table maps filter identification numbers to structs that
0159  * contain a pointers to the filter function and timing statistics.
0160  */
0161 //! <!-- [H5Z_class2_t_snip] -->
0162 typedef struct H5Z_class2_t {
0163     int                  version;         /**< Version number of the H5Z_class_t struct     */
0164     H5Z_filter_t         id;              /**< Filter ID number                             */
0165     unsigned             encoder_present; /**< Does this filter have an encoder?            */
0166     unsigned             decoder_present; /**< Does this filter have a decoder?             */
0167     const char          *name;            /**< Comment for debugging                        */
0168     H5Z_can_apply_func_t can_apply;       /**< The "can apply" callback for a filter        */
0169     H5Z_set_local_func_t set_local;       /**< The "set local" callback for a filter        */
0170     H5Z_func_t           filter;          /**< The actual filter function                   */
0171 } H5Z_class2_t;
0172 //! <!-- [H5Z_class2_t_snip] -->
0173 
0174 /********************/
0175 /* Public Variables */
0176 /********************/
0177 
0178 /*********************/
0179 /* Public Prototypes */
0180 /*********************/
0181 
0182 #ifdef __cplusplus
0183 extern "C" {
0184 #endif
0185 
0186 /**
0187  * \ingroup H5Z
0188  *
0189  * \brief Registers a new filter with the HDF5 library
0190  *
0191  * \param[in] cls A pointer to a buffer for the struct containing the
0192  *                filter-definition
0193  *
0194  * \return \herr_t
0195  *
0196  * \details H5Zregister() registers a new filter with the HDF5 library.
0197  *
0198  * \details Making a new filter available to an application is a two-step
0199  *          process. The first step is to write the three filter callback
0200  *          functions described below: \c can_apply, \c set_local, and \c
0201  *          filter. This call to H5Zregister(), registering the filter with the
0202  *          library, is the second step. The can_apply and set_local fields can
0203  *          be set to NULL if they are not required for the filter being
0204  *          registered.
0205  *
0206  *          H5Zregister() accepts a single parameter, a pointer to a buffer for
0207  *          the \p cls data structure. That data structure must conform to one
0208  *          of the following definitions:
0209  *          \snippet this H5Z_class1_t_snip
0210  *          or
0211  *          \snippet this H5Z_class2_t_snip
0212  *
0213  *          \c version is a library-defined value reporting the version number
0214  *          of the #H5Z_class_t struct. This currently must be set to
0215  *          #H5Z_CLASS_T_VERS.
0216  *
0217  *          \c id is the identifier for the new filter. This is a user-defined
0218  *          value between #H5Z_FILTER_RESERVED and #H5Z_FILTER_MAX. These
0219  *          values are defined in the HDF5 source file H5Zpublic.h, but the
0220  *          symbols #H5Z_FILTER_RESERVED and #H5Z_FILTER_MAX should always be
0221  *          used instead of the literal values.
0222  *
0223  *          \c encoder_present is a library-defined value indicating whether
0224  *          the filter's encoding capability is available to the application.
0225  *
0226  *          \c decoder_present is a library-defined value indicating whether
0227  *          the filter's encoding capability is available to the application.
0228  *
0229  *          \c name is a descriptive comment used for debugging, may contain a
0230  *          descriptive name for the filter, and may be the null pointer.
0231  *
0232  *          \c can_apply, described in detail below, is a user-defined callback
0233  *          function that determines whether the combination of the dataset
0234  *          creation property list values, the datatype, and the dataspace
0235  *          represent a valid combination to apply this filter to.
0236  *
0237  *          \c set_local, described in detail below, is a user-defined callback
0238  *          function that sets any parameters that are specific to this
0239  *          dataset, based on the combination of the dataset creation property
0240  *          list values, the datatype, and the dataspace.
0241  *
0242  *          \c filter, described in detail below, is a user-defined callback
0243  *          function which performs the action of the filter.
0244  *
0245  *          The statistics associated with a filter are not reset by this
0246  *          function; they accumulate over the life of the library.
0247  *
0248  *          #H5Z_class_t is a macro that maps to either H5Z_class1_t or
0249  *          H5Z_class2_t, depending on the needs of the application. To affect
0250  *          only this macro, H5Z_class_t_vers may be defined as either 1 or 2.
0251  *          Otherwise, it will behave in the same manner as other API
0252  *          compatibility macros. See API Compatibility Macros in HDF5 for more
0253  *          information. H5Z_class1_t matches the #H5Z_class_t structure that is
0254  *          used in the 1.6.x versions of the HDF5 library.
0255  *
0256  *          H5Zregister() will automatically detect which structure type has
0257  *          been passed in, regardless of the mapping of the #H5Z_class_t macro.
0258  *          However, the application must make sure that the fields are filled
0259  *          in according to the correct structure definition if the macro is
0260  *          used to declare the structure.
0261  *
0262  *          \Bold{The callback functions:}\n Before H5Zregister() can link a
0263  *          filter into an application, three callback functions must be
0264  *          defined as described in the HDF5 library header file H5Zpublic.h.
0265  *
0266  *          When a filter is applied to the fractal heap for a group (e.g.,
0267  *          when compressing group metadata) and if they can apply and set local
0268  *          callback functions that have been defined for that filter, HDF5 passes
0269  *          the value -1 for all parameters for those callback functions. This
0270  *          is done to ensure that the filter will not be applied to groups if
0271  *          it relies on these parameters, as they are not applicable to group
0272  *          fractal heaps; to operate on group fractal heaps, a filter must be
0273  *          capable of operating on an opaque block of binary data.
0274  *
0275  *          The \Emph{can-apply} callback function must return a positive value
0276  *          for a valid combination, zero for an invalid combination, and a
0277  *          negative value for an error.
0278  *          \snippet this H5Z_can_apply_func_t_snip
0279  *
0280  *          Before a dataset is created, the \Emph{can apply} callbacks for any
0281  *          filters used in the dataset creation property list are called with
0282  *          the dataset's dataset creation property list, \c dcpl_id, the
0283  *          dataset's datatype, \p type_id, and a dataspace describing a chunk,
0284  *          \p space_id, (for chunked dataset storage).
0285  *
0286  *          This callback must determine whether the combination of the dataset
0287  *          creation property list settings, the datatype, and the dataspace
0288  *          represent a valid combination to which to apply this filter. For
0289  *          example, an invalid combination may involve the filter not
0290  *          operating correctly on certain datatypes, on certain datatype
0291  *          sizes, or on certain sizes of the chunk dataspace. If this filter
0292  *          is enabled through H5Pset_filter() as optional and the can apply
0293  *          function returns 0, the library will skip the filter in the filter
0294  *          pipeline.
0295  *
0296  *          This callback can be the NULL pointer, in which case the library
0297  *          will assume that the filter can be applied to a dataset with any
0298  *          combination of dataset creation property list values, datatypes,
0299  *          and dataspaces.
0300  *
0301  *          The \Emph{set local} callback function is defined as follows:
0302  *          \snippet this H5Z_set_local_func_t_snip
0303  *
0304  *          After the can apply callbacks are checked for a new dataset, the
0305  *          \Emph{set local} callback functions for any filters used in the
0306  *          dataset creation property list are called. These callbacks receive
0307  *          \c dcpl_id, the dataset's private copy of the dataset creation
0308  *          property list passed into H5Dcreate() (i.e. not the actual
0309  *          property list passed into H5Dcreate()); \c type_id, the datatype
0310  *          identifier passed into H5Dcreate(), which is not copied and should
0311  *          not be modified; and \c space_id, a dataspace describing the chunk
0312  *          (for chunked dataset storage), which should also not be modified.
0313  *
0314  *          The set local callback must set any filter parameters that are
0315  *          specific to this dataset, based on the combination of the dataset
0316  *          creation property list values, the datatype, and the dataspace. For
0317  *          example, some filters perform different actions based on different
0318  *          datatypes, datatype sizes, numbers of dimensions, or dataspace
0319  *          sizes.
0320  *
0321  *          The \Emph{set local} callback may be the NULL pointer, in which
0322  *          case, the library will assume that there are no dataset-specific
0323  *          settings for this filter.
0324  *
0325  *          The \Emph{set local} callback function must return a non-negative
0326  *          value on success and a negative value for an error.
0327  *
0328  *          The \Emph{filter operation} callback function, defining the
0329  *          filter's operation on the data, is defined as follows:
0330  *          \snippet this H5Z_func_t_snip
0331  *
0332  *          The parameters \c flags, \c cd_nelmts, and \c cd_values are the
0333  *          same as for the function H5Pset_filter(). The one exception is that
0334  *          an additional flag, #H5Z_FLAG_REVERSE, is set when the filter is
0335  *          called as part of the input pipeline.
0336  *
0337  *          The parameter \c buf points to the input buffer which has a size of
0338  *          \c buf_size bytes, \c nbytes of which are valid data.
0339  *
0340  *          The filter should perform the transformation in place if possible.
0341  *          If the transformation cannot be done in place, then the filter
0342  *          should allocate a new buffer and assign it to \c buf, assigning
0343  *          the allocated size of that buffer to \c buf_size. The old
0344  *          buffer should be freed by the filter.
0345  *
0346  *          Some care must be taken with the functions that allocate and free
0347  *          memory. Standard C library functions like malloc(3) and free(3)
0348  *          will work in many cases, but if there is a mismatch between the
0349  *          memory allocators used in the library and any filter that
0350  *          reallocates a buffer, there could be problems. This is most often
0351  *          the case with Windows and/or when debugging memory allocators are being
0352  *          used. In both cases, the "state" of the memory allocator lies in
0353  *          different libraries and will get corrupted if you allocate in one
0354  *          library and free in another. Windows adds the C standard library
0355  *          via dlls that can vary with Visual Studio version and debug vs.
0356  *          release builds. Static links to the MSVC CRT can also introduce
0357  *          a new memory allocator state.
0358  *
0359  *          The library does provide H5allocate_memory() and H5free_memory()
0360  *          functions that will use the library's allocation and free functions,
0361  *          however using these functions will require linking your filter to
0362  *          a particular version of the library, which may be inconvenient.
0363  *
0364  *          If successful, the \Emph{filter operation} callback function
0365  *          returns the number of valid bytes of data contained in \c buf. In
0366  *          the case of failure, the return value is 0 (zero) and all pointer
0367  *          arguments are left unchanged.
0368  *
0369  * \version 1.8.6 Return type for the \Emph{can apply} callback function,
0370  *                \ref H5Z_can_apply_func_t, changed to \ref htri_t.
0371  * \version 1.8.5 Semantics of the \Emph{can apply} and \Emph{set local}
0372  *                callback functions changed to accommodate the use of filters
0373  *                with group fractal heaps.
0374  * \version 1.8.3 #H5Z_class_t renamed to H5Z_class2_t, H5Z_class1_t structure
0375  *                introduced for backwards compatibility with release 1.6.x,
0376  *                and #H5Z_class_t macro introduced in this release. Function
0377  *                modified to accept either structure type.
0378  * \version 1.8.0 The fields \c version, \c encoder_present, and
0379  *                \c decoder_present were added to the #H5Z_class_t \c struct
0380  *                in this release.
0381  * \version 1.6.0 This function was substantially revised in Release 1.6.0 with
0382  *                a new #H5Z_class_t struct and new set local and can apply
0383  *                callback functions.
0384  *
0385  * \since 1.0.0
0386  *
0387  */
0388 H5_DLL herr_t H5Zregister(const void *cls);
0389 /**
0390  * \ingroup H5Z
0391  *
0392  * \brief Unregisters a filter.
0393  *
0394  * \param[in] id Identifier of the filter to be unregistered.
0395  * \return \herr_t
0396  *
0397  * \details H5Zunregister() unregisters the filter specified in \p id.
0398  *
0399  * \details This function first iterates through all opened datasets and
0400  *          groups. If an open object that uses this filter is found, the
0401  *          function will fail with a message indicating that an object using
0402  *          the filter is still open. All open files are then flushed to make
0403  *          sure that all cached data that may use this filter are written out.
0404  *
0405  *          If the application is a parallel program, all processes that
0406  *          participate in collective data writing should call this function to
0407  *          ensure that all data is flushed.
0408  *
0409  *          After a call to H5Zunregister(), the filter specified in filter
0410  *          will no longer be available to the application.
0411  *
0412  * \version 1.8.12 Function modified to check for open objects using the
0413  *                 filter.
0414  * \since 1.6.0
0415  */
0416 H5_DLL herr_t H5Zunregister(H5Z_filter_t id);
0417 
0418 #ifdef __cplusplus
0419 }
0420 #endif
0421 
0422 /* Symbols defined for compatibility with previous versions of the HDF5 API.
0423  *
0424  * Use of these symbols is deprecated.
0425  */
0426 #ifndef H5_NO_DEPRECATED_SYMBOLS
0427 
0428 /**
0429  * The filter table maps filter identification numbers to structs that
0430  * contain a pointers to the filter function and timing statistics.
0431  */
0432 //! <!-- [H5Z_class1_t_snip] -->
0433 typedef struct H5Z_class1_t {
0434     H5Z_filter_t         id;        /**< Filter ID number                */
0435     const char          *name;      /**< Comment for debugging           */
0436     H5Z_can_apply_func_t can_apply; /**< The "can apply" callback for a filter */
0437     H5Z_set_local_func_t set_local; /**< The "set local" callback for a filter */
0438     H5Z_func_t           filter;    /**< The actual filter function          */
0439 } H5Z_class1_t;
0440 //! <!-- [H5Z_class1_t_snip] -->
0441 
0442 #endif /* H5_NO_DEPRECATED_SYMBOLS */
0443 
0444 #endif /* H5Zdevelop_H */