Line | Count | Source |
1 | | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
2 | | * Copyright by The HDF Group. * |
3 | | * All rights reserved. * |
4 | | * * |
5 | | * This file is part of HDF5. The full HDF5 copyright notice, including * |
6 | | * terms governing use, modification, and redistribution, is contained in * |
7 | | * the LICENSE file, which can be found at the root of the source code * |
8 | | * distribution tree, or in https://www.hdfgroup.org/licenses. * |
9 | | * If you do not have access to either file, you may request a copy from * |
10 | | * help@hdfgroup.org. * |
11 | | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
12 | | |
13 | | /* |
14 | | * Module Info: This module contains the functionality for fixed-point (i.e. |
15 | | * integer) datatypes in the H5T interface. |
16 | | */ |
17 | | |
18 | | #include "H5Tmodule.h" /* This source code file is part of the H5T module */ |
19 | | |
20 | | #include "H5private.h" /*generic functions */ |
21 | | #include "H5Eprivate.h" /*error handling */ |
22 | | #include "H5Iprivate.h" /*ID functions */ |
23 | | #include "H5Tpkg.h" /*data-type functions */ |
24 | | |
25 | | /*------------------------------------------------------------------------- |
26 | | * Function: H5Tget_sign |
27 | | * |
28 | | * Purpose: Retrieves the sign type for an integer type. |
29 | | * |
30 | | * Return: Success: The sign type. |
31 | | * Failure: H5T_SGN_ERROR (Negative) |
32 | | * |
33 | | *------------------------------------------------------------------------- |
34 | | */ |
35 | | H5T_sign_t |
36 | | H5Tget_sign(hid_t type_id) |
37 | 0 | { |
38 | 0 | H5T_t *dt = NULL; |
39 | 0 | H5T_sign_t ret_value; |
40 | |
|
41 | 0 | FUNC_ENTER_API(H5T_SGN_ERROR) |
42 | | |
43 | | /* Check args */ |
44 | 0 | if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) |
45 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_SGN_ERROR, "not an integer datatype"); |
46 | | |
47 | 0 | ret_value = H5T_get_sign(dt); |
48 | |
|
49 | 0 | done: |
50 | 0 | FUNC_LEAVE_API(ret_value) |
51 | 0 | } |
52 | | |
53 | | /*------------------------------------------------------------------------- |
54 | | * Function: H5T_get_sign |
55 | | * |
56 | | * Purpose: Private function for H5Tget_sign. Retrieves the sign type |
57 | | * for an integer type. |
58 | | * |
59 | | * Return: Success: The sign type. |
60 | | * Failure: H5T_SGN_ERROR (Negative) |
61 | | * |
62 | | *------------------------------------------------------------------------- |
63 | | */ |
64 | | H5T_sign_t |
65 | | H5T_get_sign(H5T_t const *dt) |
66 | 0 | { |
67 | 0 | H5T_sign_t ret_value = H5T_SGN_ERROR; /* Return value */ |
68 | |
|
69 | 0 | FUNC_ENTER_NOAPI(H5T_SGN_ERROR) |
70 | |
|
71 | 0 | assert(dt); |
72 | | |
73 | | /* Defer to parent */ |
74 | 0 | while (dt->shared->parent) |
75 | 0 | dt = dt->shared->parent; |
76 | | |
77 | | /* Check args */ |
78 | 0 | if (H5T_INTEGER != dt->shared->type) |
79 | 0 | HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, H5T_SGN_ERROR, "operation not defined for datatype class"); |
80 | | |
81 | | /* Sign */ |
82 | 0 | ret_value = dt->shared->u.atomic.u.i.sign; |
83 | |
|
84 | 0 | done: |
85 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
86 | 0 | } |
87 | | |
88 | | /*------------------------------------------------------------------------- |
89 | | * Function: H5Tset_sign |
90 | | * |
91 | | * Purpose: Sets the sign property for an integer. |
92 | | * |
93 | | * Return: Non-negative on success/Negative on failure |
94 | | * |
95 | | *------------------------------------------------------------------------- |
96 | | */ |
97 | | herr_t |
98 | | H5Tset_sign(hid_t type_id, H5T_sign_t sign) |
99 | 0 | { |
100 | 0 | H5T_t *dt = NULL; |
101 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
102 | |
|
103 | 0 | FUNC_ENTER_API(FAIL) |
104 | | |
105 | | /* Check args */ |
106 | 0 | if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) |
107 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an integer datatype"); |
108 | 0 | if (H5T_STATE_TRANSIENT != dt->shared->state) |
109 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "datatype is read-only"); |
110 | 0 | if (sign < H5T_SGN_NONE || sign >= H5T_NSGN) |
111 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "illegal sign type"); |
112 | 0 | if (H5T_ENUM == dt->shared->type && dt->shared->u.enumer.nmembs > 0) |
113 | 0 | HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after members are defined"); |
114 | 0 | while (dt->shared->parent) |
115 | 0 | dt = dt->shared->parent; /*defer to parent*/ |
116 | 0 | if (H5T_INTEGER != dt->shared->type) |
117 | 0 | HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not defined for datatype class"); |
118 | | |
119 | | /* Commit */ |
120 | 0 | dt->shared->u.atomic.u.i.sign = sign; |
121 | |
|
122 | 0 | done: |
123 | | FUNC_LEAVE_API(ret_value) |
124 | 0 | } |