summaryrefslogtreecommitdiffstats
path: root/c++/src/H5CommonFG.cpp
blob: fb602d933192f6b61d92fb1d89bbccd4b90d7018 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the COPYING file, which can be found at the root of the source code       *
 * distribution tree, or in https://www.hdfgroup.org/licenses.               *
 * If you do not have access to either file, you may request a copy from     *
 * help@hdfgroup.org.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include <string>

#include "H5private.h" // for HDstrcpy
#include "H5Include.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5DataSpace.h"
#include "H5PropList.h"
#include "H5DxferProp.h"
#include "H5OcreatProp.h"
#include "H5DcreatProp.h"
#include "H5LcreatProp.h"
#include "H5LaccProp.h"
#include "H5DaccProp.h"
#include "H5Location.h"
#include "H5Object.h"
#include "H5Alltypes.h"
#include "H5AbstractDs.h"
#include "H5DataSet.h"
#include "H5CommonFG.h"

// There are a few comments that are common to most of the functions
// defined in this file so they are listed here.
// - getLocId is called by all functions, that call a C API, to get
//   the location id, which can be either a file id or a group id.
//   This function is pure virtual and it's up to H5File and Group
//   to call the right getId() - although, as the structure of the
//   library at this time, getId() is basically the IdComponent::getId()
// - when a failure returned by the C API, the functions will call
//   throwException, which is a pure virtual function and is implemented
//   by H5File to throw a FileIException and by Group to throw a
//   GroupIException.
// December 2000

namespace H5 {

//--------------------------------------------------------------------------
// Function:    CommonFG::openDataType
///\brief       Opens the named generic datatype at this location.
///\param       name  - IN: Name of the datatype to open
///\return      DataType instance
///\exception   H5::FileIException or H5::GroupIException
// Programmer   Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
DataType
CommonFG::openDataType(const char *name) const
{
    // Call C function H5Topen2 to open the named datatype in this group,
    // given either the file or group id
    hid_t type_id = H5Topen2(getLocId(), name, H5P_DEFAULT);

    // If the datatype's opening failed, throw an exception
    if (type_id < 0)
        throwException("openDataType", "H5Topen2 failed");

    // No failure, create and return the DataType object
    DataType data_type;
    f_DataType_setId(&data_type, type_id);
    return (data_type);
}

//--------------------------------------------------------------------------
// Function:    CommonFG::openDataType
///\brief       This is an overloaded member function, provided for convenience.
///             It differs from the above function in that it takes an
///             \c H5std_string for \a name.
// Programmer   Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
DataType
CommonFG::openDataType(const H5std_string &name) const
{
    return (openDataType(name.c_str()));
}

//--------------------------------------------------------------------------
// Function:    CommonFG::openArrayType
///\brief       Opens the named array datatype at this location.
///\param       name  - IN: Name of the array datatype to open
///\return      ArrayType instance
///\exception   H5::FileIException or H5::GroupIException
// Programmer   Binh-Minh Ribler - Jul, 2005
//--------------------------------------------------------------------------
ArrayType
CommonFG::openArrayType(const char *name) const
{
    // Call C function H5Topen2 to open the named datatype in this group,
    // given either the file or group id
    hid_t type_id = H5Topen2(getLocId(), name, H5P_DEFAULT);

    // If the datatype's opening failed, throw an exception
    if (type_id < 0)
        throwException("openArrayType", "H5Topen2 failed");

    // No failure, create and return the ArrayType object
    ArrayType array_type;
    f_DataType_setId(&array_type, type_id);
    return (array_type);
}

//--------------------------------------------------------------------------
// Function:    CommonFG::openArrayType
///\brief       This is an overloaded member function, provided for convenience.
///             It differs from the above function in that it takes an
///             \c H5std_string for \a name.
// Programmer   Binh-Minh Ribler - Jul, 2005
//--------------------------------------------------------------------------
ArrayType
CommonFG::openArrayType(const H5std_string &name) const
{
    return (openArrayType(name.c_str()));
}

//--------------------------------------------------------------------------
// Function:    CommonFG::openCompType
///\brief       Opens the named compound datatype at this location.
///\param       name  - IN: Name of the compound datatype to open
///\return      CompType instance
///\exception   H5::FileIException or H5::GroupIException
// Programmer   Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
CompType
CommonFG::openCompType(const char *name) const
{
    // Call C function H5Topen2 to open the named datatype in this group,
    // given either the file or group id
    hid_t type_id = H5Topen2(getLocId(), name, H5P_DEFAULT);

    // If the datatype's opening failed, throw an exception
    if (type_id < 0)
        throwException("openCompType", "H5Topen2 failed");

    // No failure, create and return the CompType object
    CompType comp_type;
    f_DataType_setId(&comp_type, type_id);
    return (comp_type);
}

//--------------------------------------------------------------------------
// Function:    CommonFG::openCompType
///\brief       This is an overloaded member function, provided for convenience.
///             It differs from the above function in that it takes an
///             \c H5std_string for \a name.
// Programmer   Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
CompType
CommonFG::openCompType(const H5std_string &name) const
{
    return (openCompType(name.c_str()));
}

//--------------------------------------------------------------------------
// Function:    CommonFG::openEnumType
///\brief       Opens the named enumeration datatype at this location.
///\param       name  - IN: Name of the enumeration datatype to open
///\return      EnumType instance
///\exception   H5::FileIException or H5::GroupIException
// Programmer   Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
EnumType
CommonFG::openEnumType(const char *name) const
{
    // Call C function H5Topen2 to open the named datatype in this group,
    // given either the file or group id
    hid_t type_id = H5Topen2(getLocId(), name, H5P_DEFAULT);

    // If the datatype's opening failed, throw an exception
    if (type_id < 0)
        throwException("openEnumType", "H5Topen2 failed");

    // No failure, create and return the EnumType object
    EnumType enum_type;
    f_DataType_setId(&enum_type, type_id);
    return (enum_type);
}

//--------------------------------------------------------------------------
// Function:    CommonFG::openEnumType
///\brief       This is an overloaded member function, provided for convenience.
///             It differs from the above function in that it takes an
///             \c H5std_string for \a name.
// Programmer   Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
EnumType
CommonFG::openEnumType(const H5std_string &name) const
{
    return (openEnumType(name.c_str()));
}

//--------------------------------------------------------------------------
// Function:    CommonFG::openIntType
///\brief       Opens the named integer datatype at this location.
///\param       name  - IN: Name of the integer datatype to open
///\return      IntType instance
///\exception   H5::FileIException or H5::GroupIException
// Programmer   Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
IntType
CommonFG::openIntType(const char *name) const
{
    // Call C function H5Topen2 to open the named datatype in this group,
    // given either the file or group id
    hid_t type_id = H5Topen2(getLocId(), name, H5P_DEFAULT);

    // If the datatype's opening failed, throw an exception
    if (type_id < 0)
        throwException("openIntType", "H5Topen2 failed");

    // No failure, create and return the IntType object
    IntType int_type;
    f_DataType_setId(&int_type, type_id);
    return (int_type);
}

//--------------------------------------------------------------------------
// Function:    CommonFG::openIntType
///\brief       This is an overloaded member function, provided for convenience.
///             It differs from the above function in that it takes an
///             \c H5std_string for \a name.
// Programmer   Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
IntType
CommonFG::openIntType(const H5std_string &name) const
{
    return (openIntType(name.c_str()));
}

//--------------------------------------------------------------------------
// Function:    CommonFG::openFloatType
///\brief       Opens the named floating-point datatype at this location.
///\param       name  - IN: Name of the floating-point datatype to open
///\return      FloatType instance
///\exception   H5::FileIException or H5::GroupIException
// Programmer   Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
FloatType
CommonFG::openFloatType(const char *name) const
{
    // Call C function H5Topen2 to open the named datatype in this group,
    // given either the file or group id
    hid_t type_id = H5Topen2(getLocId(), name, H5P_DEFAULT);

    // If the datatype's opening failed, throw an exception
    if (type_id < 0)
        throwException("openFloatType", "H5Topen2 failed");

    // No failure, create and return the FloatType object
    FloatType float_type;
    f_DataType_setId(&float_type, type_id);
    return (float_type);
}

//--------------------------------------------------------------------------
// Function:    CommonFG::openFloatType
///\brief       This is an overloaded member function, provided for convenience.
///             It differs from the above function in that it takes an
///             \c H5std_string for \a name.
// Programmer   Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
FloatType
CommonFG::openFloatType(const H5std_string &name) const
{
    return (openFloatType(name.c_str()));
}

//--------------------------------------------------------------------------
// Function:    CommonFG::openStrType
///\brief       Opens the named string datatype at this location.
///\param       name  - IN: Name of the string datatype to open
///\return      StrType instance
///\exception   H5::FileIException or H5::GroupIException
// Programmer   Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
StrType
CommonFG::openStrType(const char *name) const
{
    // Call C function H5Topen2 to open the named datatype in this group,
    // given either the file or group id
    hid_t type_id = H5Topen2(getLocId(), name, H5P_DEFAULT);

    // If the datatype's opening failed, throw an exception
    if (type_id < 0)
        throwException("openStrType", "H5Topen2 failed");

    // No failure, create and return the StrType object
    StrType str_type;
    f_DataType_setId(&str_type, type_id);
    return (str_type);
}

//--------------------------------------------------------------------------
// Function:    CommonFG::openStrType
///\brief       This is an overloaded member function, provided for convenience.
///             It differs from the above function in that it takes an
///             \c H5std_string for \a name.
// Programmer   Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
StrType
CommonFG::openStrType(const H5std_string &name) const
{
    return (openStrType(name.c_str()));
}

//--------------------------------------------------------------------------
// Function:    CommonFG::openVarLenType
///\brief       Opens the named variable length datatype at this location.
///\param       name  - IN: Name of the variable length datatype to open
///\return      VarLenType instance
///\exception   H5::FileIException or H5::GroupIException
// Programmer   Binh-Minh Ribler - Jul, 2005
//--------------------------------------------------------------------------
VarLenType
CommonFG::openVarLenType(const char *name) const
{
    // Call C function H5Topen2 to open the named datatype in this group,
    // given either the file or group id
    hid_t type_id = H5Topen2(getLocId(), name, H5P_DEFAULT);

    // If the datatype's opening failed, throw an exception
    if (type_id < 0)
        throwException("openVarLenType", "H5Topen2 failed");

    // No failure, create and return the VarLenType object
    VarLenType varlen_type;
    f_DataType_setId(&varlen_type, type_id);
    return (varlen_type);
}

//--------------------------------------------------------------------------
// Function:    CommonFG::openVarLenType
///\brief       This is an overloaded member function, provided for convenience.
///             It differs from the above function in that it takes an
///             \c H5std_string for \a name.
// Programmer   Binh-Minh Ribler - Jul, 2005
//--------------------------------------------------------------------------
VarLenType
CommonFG::openVarLenType(const H5std_string &name) const
{
    return (openVarLenType(name.c_str()));
}

#ifndef DOXYGEN_SHOULD_SKIP_THIS
//--------------------------------------------------------------------------
// Function:    CommonFG default constructor
///\brief       Default constructor.
// Programmer   Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
CommonFG::CommonFG()
{
}

//--------------------------------------------------------------------------
// Function:    CommonFG destructor
///\brief       Noop destructor.
// Programmer   Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
CommonFG::~CommonFG()
{
}

//--------------------------------------------------------------------------
// Function:    f_DataType_setId - friend
// Purpose:     This function is friend to class H5::DataType so that it
//              can set DataType::id in order to work around a problem
//              described in the JIRA issue HDFFV-7947.
//              Applications shouldn't need to use it.
// param        dtype   - IN/OUT: DataType object to be changed
// param        new_id - IN: New id to set
// Programmer   Binh-Minh Ribler - 2015
//--------------------------------------------------------------------------
void
f_DataType_setId(DataType *dtype, hid_t new_id)
{
    dtype->p_setId(new_id);
}

//--------------------------------------------------------------------------
// Function:    f_DataSet_setId - friend
// Purpose:     This function is friend to class H5::DataSet so that it
//              can set DataSet::id in order to work around a problem
//              described in the JIRA issue HDFFV-7947.
//              Applications shouldn't need to use it.
// param        dset   - IN/OUT: DataSet object to be changed
// param        new_id - IN: New id to set
// Programmer   Binh-Minh Ribler - 2015
//--------------------------------------------------------------------------
void
f_DataSet_setId(DataSet *dset, hid_t new_id)
{
    dset->p_setId(new_id);
}

#endif // DOXYGEN_SHOULD_SKIP_THIS

} // namespace H5