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
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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 files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <string>
#ifdef OLD_HEADER_FILENAME
#include <iostream.h>
#else
#include <iostream>
#endif
#include "H5Include.h"
#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5Idtemplates.h"
#include "H5PropList.h"
#include "H5Object.h"
#include "H5AbstractDs.h"
#include "H5FaccProp.h"
#include "H5FcreatProp.h"
#include "H5DcreatProp.h"
#include "H5DxferProp.h"
#include "H5DataSpace.h"
#include "H5DataSet.h"
#include "H5CommonFG.h"
#include "H5Group.h"
#include "H5File.h"
#include "H5Alltypes.h"
#ifndef H5_NO_NAMESPACE
namespace H5 {
#endif
//--------------------------------------------------------------------------
// Function: Group default constructor
///\brief Default constructor: Creates a stub group
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
Group::Group() : H5Object() {}
//--------------------------------------------------------------------------
// Function: Group copy constructor
///\brief Copy constructor: makes a copy of the original Group object.
///\param original - IN: Original group to copy
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
Group::Group( const Group& original ) : H5Object( original ) {}
//--------------------------------------------------------------------------
// Function: Group::getLocId
///\brief Returns the id of this group.
///\return Id of this group
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
hid_t Group::getLocId() const
{
return( getId() );
}
//--------------------------------------------------------------------------
// Function: Group overloaded constructor
///\brief Creates a Group object using the id of an existing group.
///\param group_id - IN: Id of an existing group
///\exception H5::GroupIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
Group::Group( const hid_t group_id ) : H5Object( group_id ) {}
//--------------------------------------------------------------------------
// Function: Group::getNumObjs
///\brief Returns the number of objects in this group.
///\exception H5::GroupIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
hsize_t Group::getNumObjs() const
{
hsize_t num_objs;
herr_t ret_value = H5Gget_num_objs(id, &num_objs);
if(ret_value < 0)
{
throwException("getNumObjs", "H5Gget_num_objs failed");
}
return (num_objs);
}
//--------------------------------------------------------------------------
// Function: Group::getObjnameByIdx
///\brief Retrieves the name of an object in this group by giving the
/// object's index.
///\return Object name
///\exception H5::GroupIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
ssize_t Group::getObjnameByIdx(hsize_t idx, string& name, size_t size) const
{
char* name_C = new char[size];
ssize_t name_len = H5Gget_objname_by_idx(id, idx, name_C, size);
if(name_len < 0)
{
throwException("getObjnameByIdx", "H5Gget_objname_by_idx failed");
}
name = string( name_C );
delete [] name_C;
return (name_len);
}
//--------------------------------------------------------------------------
// Function: Group::getObjTypeByIdx
///\brief Returns the type of an object in this group by giving the
/// object's index.
///\return Object type
///\exception H5::GroupIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
int Group::getObjTypeByIdx(hsize_t idx) const
{
int obj_type = H5Gget_objtype_by_idx(id, idx);
if (obj_type == H5G_UNKNOWN)
{
throwException("getObjTypeByIdx", "H5Gget_objtype_by_idx failed");
}
return (obj_type);
}
//--------------------------------------------------------------------------
// Function: Group::getObjTypeByIdx
///\brief This is an overloaded member function, provided for convenience.
/// It differs from the above function because it also provides
/// the returned object type in text.
///\param idx - IN: Index of the object
///\param type_name - IN: Object type in text
///\return Object type
///\exception H5::GroupIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
int Group::getObjTypeByIdx(hsize_t idx, string& type_name) const
{
int obj_type = H5Gget_objtype_by_idx(id, idx);
switch (obj_type)
{
case H5G_GROUP: type_name = string("group"); break;
case H5G_DATASET: type_name = string("dataset"); break;
case H5G_TYPE: type_name = string("datatype"); break;
case H5G_UNKNOWN:
default:
{
throwException("getObjTypeByIdx", "H5Gget_objtype_by_idx failed");
}
}
return (obj_type);
}
//--------------------------------------------------------------------------
// Function: Group::Reference
///\brief Creates a reference to an HDF5 object or a dataset region.
///\param name - IN: Name of the object to be referenced
///\param dataspace - IN: Dataspace with selection
///\param ref_type - IN: Type of reference; default to \c H5R_DATASET_REGION
///\return A reference
///\exception H5::ReferenceIException
// Programmer Binh-Minh Ribler - May, 2004
//--------------------------------------------------------------------------
void* Group::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type) const
{
return(p_reference(name, dataspace.getId(), ref_type));
}
//--------------------------------------------------------------------------
// Function: Group::Reference
///\brief This is an overloaded function, provided for your convenience.
/// It differs from the above function in that it only creates
/// a reference to an HDF5 object, not to a dataset region.
///\param name - IN: Name of the object to be referenced
///\return A reference
///\exception H5::ReferenceIException
///\par Description
// This function passes H5R_OBJECT and -1 to the protected
// function for it to pass to the C API H5Rcreate
// to create a reference to the named object.
// Programmer Binh-Minh Ribler - May, 2004
//--------------------------------------------------------------------------
void* Group::Reference(const char* name) const
{
return(p_reference(name, -1, H5R_OBJECT));
}
//--------------------------------------------------------------------------
// Function: Group::p_close (private)
///\brief Closes this group.
///\exception H5::GroupIException
///\note
/// This function will be obsolete because its functionality
/// is recently handled by the C library layer.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void Group::p_close() const
{
herr_t ret_value = H5Gclose( id );
if( ret_value < 0 )
{
throw GroupIException(0, "H5Gclose failed");
}
}
//--------------------------------------------------------------------------
// Function: Group::getObjType
///\brief Retrieves the type of object that an object reference points to.
///\param ref - IN: Reference to query
///\param ref_type - IN: Type of reference to query
// Return An object type, which can be one of the following:
// H5G_LINK Object is a symbolic link.
// H5G_GROUP Object is a group.
// H5G_DATASET Object is a dataset.
// H5G_TYPE Object is a named datatype
// Exception H5::ReferenceIException
// Programmer Binh-Minh Ribler - May, 2004
//--------------------------------------------------------------------------
H5G_obj_t Group::getObjType(void *ref, H5R_type_t ref_type) const
{
return(p_get_obj_type(ref, ref_type));
}
//--------------------------------------------------------------------------
// Function: Group::getRegion
///\brief Retrieves a dataspace with the region pointed to selected.
///\param ref - IN: Reference to get region of
///\param ref_type - IN: Type of reference to get region of - default
///\return DataSpace instance
///\exception H5::ReferenceIException
// Programmer Binh-Minh Ribler - May, 2004
//--------------------------------------------------------------------------
DataSpace Group::getRegion(void *ref, H5R_type_t ref_type) const
{
DataSpace dataspace(p_get_region(ref, ref_type));
return(dataspace);
}
//--------------------------------------------------------------------------
// Function: Group::throwException
///\brief Throws group exception - initially implemented for CommonFG
///\param func_name - Name of the function where failure occurs
///\param msg - Message describing the failure
///\exception H5::GroupIException
// Description
// This function is used in CommonFG implementation so that
// proper exception can be thrown for file or group. The
// argument func_name is a member of CommonFG and "Group::"
// will be inserted to indicate the function called is an
// implementation of Group.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void Group::throwException(const string func_name, const string msg) const
{
string full_name = func_name;
full_name.insert(0, "Group::");
throw GroupIException(full_name, msg);
}
//--------------------------------------------------------------------------
// Function: Group destructor
///\brief Properly terminates access to this group.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
Group::~Group()
{
// The group id will be closed properly
try {
resetIdComponent( this ); }
catch (Exception close_error) { // thrown by p_close
cerr << "Group::~Group - " << close_error.getDetailMsg() << endl;
}
}
#ifndef H5_NO_NAMESPACE
} // end namespace
#endif
|