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 COPYING file, which can be found at the root of the source code *
9 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
10 * If you do not have access to either file, you may request a copy from *
11 * help@hdfgroup.org. *
12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13
14 #include <string>
15
16 #include "H5Include.h"
17 #include "H5Exception.h"
18 #include "H5IdComponent.h"
19 #include "H5PropList.h"
20 #include "H5StrcreatProp.h"
21 #include "H5LcreatProp.h"
22 #include "H5LaccProp.h"
23 #include "H5Location.h"
24 #include "H5Object.h"
25 #include "H5Alltypes.h"
26 #include "H5AbstractDs.h"
27
28 namespace H5 {
29
30 //--------------------------------------------------------------------------
31 // Function: AbstractDs default constructor
32 ///\brief Default constructor
33 // Programmer Binh-Minh Ribler - 2000
34 //--------------------------------------------------------------------------
AbstractDs()35 AbstractDs::AbstractDs(){}
36
37 //--------------------------------------------------------------------------
38 // Function: AbstractDs default constructor
39 ///\brief Creates an AbstractDs instance using an existing id.
40 // Programmer Binh-Minh Ribler - 2000
41 //
42 // *** Deprecation warning ***
43 // This constructor is no longer appropriate because the data member "id" had
44 // been moved to the sub-classes. It will be removed in 1.10 release. If its
45 // removal does not raise any problems in 1.10, it will be removed from 1.8 in
46 // subsequent releases.
47 //--------------------------------------------------------------------------
48 // Mar 2016 -BMR, AbstractDs::AbstractDs(const hid_t ds_id){}
49
50 //--------------------------------------------------------------------------
51 // Function: AbstractDs::getTypeClass
52 ///\brief Returns the class of the datatype that is used by this
53 /// object, which can be a dataset or an attribute.
54 ///\return Datatype class identifier
55 ///\exception H5::DataTypeIException
56 // Programmer Binh-Minh Ribler - 2000
57 //--------------------------------------------------------------------------
getTypeClass() const58 H5T_class_t AbstractDs::getTypeClass() const
59 {
60 // Gets the datatype used by this dataset or attribute.
61 // p_get_type calls either H5Dget_type or H5Aget_type depending on
62 // which object invokes getTypeClass
63 hid_t datatype_id;
64 try {
65 datatype_id = p_get_type(); // returned value is already validated
66 }
67 catch (DataSetIException& E) {
68 throw DataTypeIException("DataSet::getTypeClass", E.getDetailMsg());
69 }
70 catch (AttributeIException& E) {
71 throw DataTypeIException("Attribute::getTypeClass", E.getDetailMsg());
72 }
73
74 // Gets the class of the datatype and validate it before returning
75 H5T_class_t type_class = H5Tget_class(datatype_id);
76
77 // Close temporary datatype_id
78 herr_t ret_value = H5Tclose(datatype_id);
79 if (ret_value < 0)
80 {
81 if (fromClass() == "DataSet")
82 throw DataTypeIException("DataSet::getTypeClass", "H5Tclose failed");
83 else if (fromClass() == "Attribute")
84 throw DataTypeIException("Attribute::getTypeClass", "H5Tclose failed");
85 }
86
87 // Check on the returned type_class
88 if (type_class == H5T_NO_CLASS)
89 {
90 if (fromClass() == "DataSet")
91 throw DataTypeIException("DataSet::getTypeClass", "H5Tget_class returns H5T_NO_CLASS");
92 else if (fromClass() == "Attribute")
93 throw DataTypeIException("Attribute::getTypeClass", "H5Tget_class returns H5T_NO_CLASS");
94 }
95 return(type_class);
96 }
97
98 //--------------------------------------------------------------------------
99 // Function: AbstractDs::getDataType
100 ///\brief Returns the generic datatype of this abstract dataset, which
101 /// can be a dataset or an attribute.
102 ///\return DataType instance
103 ///\exception H5::DataTypeIException
104 // Programmer Binh-Minh Ribler - 2000
105 //--------------------------------------------------------------------------
getDataType() const106 DataType AbstractDs::getDataType() const
107 {
108 // Gets the id of the datatype used by this dataset or attribute using
109 // p_get_type. p_get_type calls either H5Dget_type or H5Aget_type
110 // depending on which object invokes getDataType. Then, create and
111 // return the DataType object
112 try {
113 DataType datatype;
114 f_DataType_setId(&datatype, p_get_type());
115 return(datatype);
116 }
117 catch (DataSetIException& E) {
118 throw DataTypeIException("DataSet::getDataType", E.getDetailMsg());
119 }
120 catch (AttributeIException& E) {
121 throw DataTypeIException("Attribute::getDataType", E.getDetailMsg());
122 }
123 }
124
125 //--------------------------------------------------------------------------
126 // Function: AbstractDs::getArrayType
127 ///\brief Returns the array datatype of this abstract dataset which
128 /// can be a dataset or an attribute.
129 ///\return ArrayType instance
130 ///\exception H5::DataTypeIException
131 // Programmer Binh-Minh Ribler - Jul, 2005
132 //--------------------------------------------------------------------------
getArrayType() const133 ArrayType AbstractDs::getArrayType() const
134 {
135 // Gets the id of the datatype used by this dataset or attribute using
136 // p_get_type. p_get_type calls either H5Dget_type or H5Aget_type
137 // depending on which object invokes getArrayType. Then, create and
138 // return the ArrayType object
139 try {
140 // Create ArrayType and set values this way to work around the
141 // problem described in the JIRA issue HDFFV-7947
142 ArrayType arraytype;
143 f_DataType_setId(&arraytype, p_get_type());
144 return(arraytype);
145 }
146 catch (DataSetIException& E) {
147 throw DataTypeIException("DataSet::getArrayType", E.getDetailMsg());
148 }
149 catch (AttributeIException& E) {
150 throw DataTypeIException("Attribute::getArrayType", E.getDetailMsg());
151 }
152 }
153
154 //--------------------------------------------------------------------------
155 // Function: AbstractDs::getCompType
156 ///\brief Returns the compound datatype of this abstract dataset which
157 /// can be a dataset or an attribute.
158 ///\return CompType instance
159 ///\exception H5::DataTypeIException
160 // Programmer Binh-Minh Ribler - 2000
161 //--------------------------------------------------------------------------
getCompType() const162 CompType AbstractDs::getCompType() const
163 {
164 // Gets the id of the datatype used by this dataset or attribute using
165 // p_get_type. p_get_type calls either H5Dget_type or H5Aget_type
166 // depending on which object invokes getCompType. Then, create and
167 // return the CompType object
168 try {
169 CompType comptype;
170 f_DataType_setId(&comptype, p_get_type());
171 return(comptype);
172 }
173 catch (DataSetIException& E) {
174 throw DataTypeIException("DataSet::getCompType", E.getDetailMsg());
175 }
176 catch (AttributeIException& E) {
177 throw DataTypeIException("Attribute::getCompType", E.getDetailMsg());
178 }
179 }
180
181 //--------------------------------------------------------------------------
182 // Function: AbstractDs::getEnumType
183 ///\brief Returns the enumeration datatype of this abstract dataset which
184 /// can be a dataset or an attribute.
185 ///\return EnumType instance
186 ///\exception H5::DataTypeIException
187 // Programmer Binh-Minh Ribler - 2000
188 //--------------------------------------------------------------------------
getEnumType() const189 EnumType AbstractDs::getEnumType() const
190 {
191 // Gets the id of the datatype used by this dataset or attribute using
192 // p_get_type. p_get_type calls either H5Dget_type or H5Aget_type
193 // depending on which object invokes getEnumType. Then, create and
194 // return the EnumType object
195 try {
196 EnumType enumtype;
197 f_DataType_setId(&enumtype, p_get_type());
198 return(enumtype);
199 }
200 catch (DataSetIException& E) {
201 throw DataTypeIException("DataSet::getEnumType", E.getDetailMsg());
202 }
203 catch (AttributeIException& E) {
204 throw DataTypeIException("Attribute::getEnumType", E.getDetailMsg());
205 }
206 }
207
208 //--------------------------------------------------------------------------
209 // Function: AbstractDs::getIntType
210 ///\brief Returns the integer datatype of this abstract dataset which
211 /// can be a dataset or an attribute.
212 ///\return IntType instance
213 ///\exception H5::DataTypeIException
214 // Programmer Binh-Minh Ribler - 2000
215 //--------------------------------------------------------------------------
getIntType() const216 IntType AbstractDs::getIntType() const
217 {
218 // Gets the id of the datatype used by this dataset or attribute using
219 // p_get_type. p_get_type calls either H5Dget_type or H5Aget_type
220 // depending on which object invokes getIntType. Then, create and
221 // return the IntType object
222 try {
223 IntType inttype;
224 f_DataType_setId(&inttype, p_get_type());
225 return(inttype);
226 }
227 catch (DataSetIException& E) {
228 throw DataTypeIException("DataSet::getIntType", E.getDetailMsg());
229 }
230 catch (AttributeIException& E) {
231 throw DataTypeIException("Attribute::getIntType", E.getDetailMsg());
232 }
233 }
234
235 //--------------------------------------------------------------------------
236 // Function: AbstractDs::getFloatType
237 ///\brief Returns the floating-point datatype of this abstract dataset,
238 /// which can be a dataset or an attribute.
239 ///\return FloatType instance
240 ///\exception H5::DataTypeIException
241 // Programmer Binh-Minh Ribler - 2000
242 //--------------------------------------------------------------------------
getFloatType() const243 FloatType AbstractDs::getFloatType() const
244 {
245 // Gets the id of the datatype used by this dataset or attribute using
246 // p_get_type. p_get_type calls either H5Dget_type or H5Aget_type
247 // depending on which object invokes getFloatType. Then, create and
248 // return the FloatType object
249 try {
250 FloatType floatype;
251 f_DataType_setId(&floatype, p_get_type());
252 return(floatype);
253 }
254 catch (DataSetIException& E) {
255 throw DataTypeIException("DataSet::getFloatType", E.getDetailMsg());
256 }
257 catch (AttributeIException& E) {
258 throw DataTypeIException("Attribute::getFloatType", E.getDetailMsg());
259 }
260 }
261
262 //--------------------------------------------------------------------------
263 // Function: AbstractDs::getStrType
264 ///\brief Returns the string datatype of this abstract dataset which
265 /// can be a dataset or an attribute.
266 ///\return StrType instance
267 ///\exception H5::DataTypeIException
268 // Programmer Binh-Minh Ribler - 2000
269 //--------------------------------------------------------------------------
getStrType() const270 StrType AbstractDs::getStrType() const
271 {
272 // Gets the id of the datatype used by this dataset or attribute using
273 // p_get_type. p_get_type calls either H5Dget_type or H5Aget_type
274 // depending on which object invokes getStrType. Then, create and
275 // return the StrType object
276 try {
277 StrType strtype;
278 f_DataType_setId(&strtype, p_get_type());
279 return(strtype);
280 }
281 catch (DataSetIException& E) {
282 throw DataTypeIException("DataSet::getStrType", E.getDetailMsg());
283 }
284 catch (AttributeIException& E) {
285 throw DataTypeIException("Attribute::getStrType", E.getDetailMsg());
286 }
287 }
288
289 //--------------------------------------------------------------------------
290 // Function: AbstractDs::getVarLenType
291 ///\brief Returns the floating-point datatype of this abstract dataset,
292 /// which can be a dataset or an attribute.
293 ///\return VarLenType instance
294 ///\exception H5::DataTypeIException
295 // Programmer Binh-Minh Ribler - Jul, 2005
296 //--------------------------------------------------------------------------
getVarLenType() const297 VarLenType AbstractDs::getVarLenType() const
298 {
299 // Gets the id of the datatype used by this dataset or attribute using
300 // p_get_type. p_get_type calls either H5Dget_type or H5Aget_type
301 // depending on which object invokes getVarLenType. Then, create and
302 // return the VarLenType object
303 try {
304 VarLenType varlentype;
305 f_DataType_setId(&varlentype, p_get_type());
306 return(varlentype);
307 }
308 catch (DataSetIException& E) {
309 throw DataTypeIException("DataSet::getVarLenType", E.getDetailMsg());
310 }
311 catch (AttributeIException& E) {
312 throw DataTypeIException("Attribute::getVarLenType", E.getDetailMsg());
313 }
314 }
315
316 //--------------------------------------------------------------------------
317 // Function: AbstractDs destructor
318 ///\brief Noop destructor.
319 // Programmer Binh-Minh Ribler - 2000
320 //--------------------------------------------------------------------------
~AbstractDs()321 AbstractDs::~AbstractDs() {}
322
323 } // end namespace
324