1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright by The HDF Group. *
3 * Copyright by the Board of Trustees of the University of Illinois. *
4 * All rights reserved. *
5 * *
6 * This file is part of HDF5. The full HDF5 copyright notice, including *
7 * terms governing use, modification, and redistribution, is contained in *
8 * the files COPYING and Copyright.html. COPYING can be found at the root *
9 * of the source code distribution tree; Copyright.html can be found at the *
10 * root level of an installed copy of the electronic HDF5 document set and *
11 * is linked from the top-level documents page. It can also be found at *
12 * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
13 * access to either file, you may request a copy from help@hdfgroup.org. *
14 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15
16 /*
17 * Module Info: This module contains the functionality for setting & querying
18 * the datatype padding for the H5T interface.
19 */
20
21 #define H5T_PACKAGE /*suppress error about including H5Tpkg */
22
23 /* Interface initialization */
24 #define H5_INTERFACE_INIT_FUNC H5T_init_pad_interface
25
26
27 #include "H5private.h" /* Generic Functions */
28 #include "H5Eprivate.h" /* Error handling */
29 #include "H5Iprivate.h" /* IDs */
30 #include "H5Tpkg.h" /* Datatypes */
31
32
33 /*--------------------------------------------------------------------------
34 NAME
35 H5T_init_pad_interface -- Initialize interface-specific information
36 USAGE
37 herr_t H5T_init_pad_interface()
38
39 RETURNS
40 Non-negative on success/Negative on failure
41 DESCRIPTION
42 Initializes any interface-specific data or routines. (Just calls
43 H5T_init_iterface currently).
44
45 --------------------------------------------------------------------------*/
46 static herr_t
H5T_init_pad_interface(void)47 H5T_init_pad_interface(void)
48 {
49 FUNC_ENTER_NOAPI_NOINIT_NOERR
50
51 FUNC_LEAVE_NOAPI(H5T_init())
52 } /* H5T_init_pad_interface() */
53
54
55 /*-------------------------------------------------------------------------
56 * Function: H5Tget_pad
57 *
58 * Purpose: Gets the least significant pad type and the most significant
59 * pad type and returns their values through the LSB and MSB
60 * arguments, either of which may be the null pointer.
61 *
62 * Return: Non-negative on success/Negative on failure
63 *
64 * Programmer: Robb Matzke
65 * Friday, January 9, 1998
66 *
67 * Modifications:
68 * Robb Matzke, 22 Dec 1998
69 * Also works with derived data types.
70 *
71 *-------------------------------------------------------------------------
72 */
73 herr_t
H5Tget_pad(hid_t type_id,H5T_pad_t * lsb,H5T_pad_t * msb)74 H5Tget_pad(hid_t type_id, H5T_pad_t *lsb/*out*/, H5T_pad_t *msb/*out*/)
75 {
76 H5T_t *dt = NULL;
77 herr_t ret_value=SUCCEED; /* Return value */
78
79 FUNC_ENTER_API(FAIL)
80 H5TRACE3("e", "ixx", type_id, lsb, msb);
81
82 /* Check args */
83 if (NULL == (dt = H5I_object_verify(type_id,H5I_DATATYPE)))
84 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
85 while (dt->shared->parent)
86 dt = dt->shared->parent; /*defer to parent*/
87 if (!H5T_IS_ATOMIC(dt->shared))
88 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "operation not defined for specified data type")
89
90 /* Get values */
91 if (lsb)
92 *lsb = dt->shared->u.atomic.lsb_pad;
93 if (msb)
94 *msb = dt->shared->u.atomic.msb_pad;
95
96 done:
97 FUNC_LEAVE_API(ret_value)
98 }
99
100
101 /*-------------------------------------------------------------------------
102 * Function: H5Tset_pad
103 *
104 * Purpose: Sets the LSB and MSB pad types.
105 *
106 * Return: Non-negative on success/Negative on failure
107 *
108 * Programmer: Robb Matzke
109 * Friday, January 9, 1998
110 *
111 * Modifications:
112 * Robb Matzke, 22 Dec 1998
113 * Also works with derived data types.
114 *
115 *-------------------------------------------------------------------------
116 */
117 herr_t
H5Tset_pad(hid_t type_id,H5T_pad_t lsb,H5T_pad_t msb)118 H5Tset_pad(hid_t type_id, H5T_pad_t lsb, H5T_pad_t msb)
119 {
120 H5T_t *dt = NULL;
121 herr_t ret_value=SUCCEED; /* Return value */
122
123 FUNC_ENTER_API(FAIL)
124 H5TRACE3("e", "iTpTp", type_id, lsb, msb);
125
126 /* Check args */
127 if (NULL == (dt = H5I_object_verify(type_id,H5I_DATATYPE)))
128 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
129 if (H5T_STATE_TRANSIENT!=dt->shared->state)
130 HGOTO_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "data type is read-only")
131 if (lsb < H5T_PAD_ZERO || lsb >= H5T_NPAD || msb < H5T_PAD_ZERO || msb >= H5T_NPAD)
132 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid pad type")
133 if (H5T_ENUM==dt->shared->type && dt->shared->u.enumer.nmembs>0)
134 HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after members are defined")
135 while (dt->shared->parent)
136 dt = dt->shared->parent; /*defer to parent*/
137 if (!H5T_IS_ATOMIC(dt->shared))
138 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "operation not defined for specified data type")
139
140 /* Commit */
141 dt->shared->u.atomic.lsb_pad = lsb;
142 dt->shared->u.atomic.msb_pad = msb;
143
144 done:
145 FUNC_LEAVE_API(ret_value)
146 }
147
148