PageRenderTime 57ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Utilities/vtkhdf5/c++/src/H5Group.cpp

https://github.com/b3c/VTK-5.8
C++ | 304 lines | 137 code | 18 blank | 149 comment | 4 complexity | dfe4cfcb4c9dcd18e1b730545041130f MD5 | raw file
  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. #ifdef OLD_HEADER_FILENAME
  16. #include <iostream.h>
  17. #else
  18. #include <iostream>
  19. #endif
  20. #include <string>
  21. #include "H5Include.h"
  22. #include "H5Exception.h"
  23. #include "H5IdComponent.h"
  24. #include "H5PropList.h"
  25. #include "H5Object.h"
  26. #include "H5AbstractDs.h"
  27. #include "H5FaccProp.h"
  28. #include "H5FcreatProp.h"
  29. #include "H5DcreatProp.h"
  30. #include "H5DxferProp.h"
  31. #include "H5DataSpace.h"
  32. #include "H5DataSet.h"
  33. #include "H5CommonFG.h"
  34. #include "H5Attribute.h"
  35. #include "H5Group.h"
  36. #include "H5File.h"
  37. #include "H5Alltypes.h"
  38. #ifndef H5_NO_NAMESPACE
  39. namespace H5 {
  40. #ifndef H5_NO_STD
  41. using std::cerr;
  42. using std::endl;
  43. #endif // H5_NO_STD
  44. #endif
  45. //--------------------------------------------------------------------------
  46. // Function: Group default constructor
  47. ///\brief Default constructor: creates a stub Group.
  48. // Programmer Binh-Minh Ribler - 2000
  49. //--------------------------------------------------------------------------
  50. Group::Group() : H5Object(), id(0) {}
  51. //--------------------------------------------------------------------------
  52. // Function: Group copy constructor
  53. ///\brief Copy constructor: makes a copy of the original Group object.
  54. ///\param original - IN: Original group to copy
  55. // Programmer Binh-Minh Ribler - 2000
  56. //--------------------------------------------------------------------------
  57. Group::Group(const Group& original) : H5Object(original)
  58. {
  59. id = original.getId();
  60. incRefCount(); // increment number of references to this id
  61. }
  62. //--------------------------------------------------------------------------
  63. // Function: Group::getLocId
  64. ///\brief Returns the id of this group.
  65. ///\return Id of this group
  66. // Programmer Binh-Minh Ribler - 2000
  67. //--------------------------------------------------------------------------
  68. hid_t Group::getLocId() const
  69. {
  70. return( getId() );
  71. }
  72. //--------------------------------------------------------------------------
  73. // Function: Group overloaded constructor
  74. ///\brief Creates a Group object using the id of an existing group.
  75. ///\param existing_id - IN: Id of an existing group
  76. // Programmer Binh-Minh Ribler - 2000
  77. //--------------------------------------------------------------------------
  78. Group::Group(const hid_t existing_id) : H5Object()
  79. {
  80. id = existing_id;
  81. }
  82. //--------------------------------------------------------------------------
  83. // Function: Group overload constructor - dereference
  84. ///\brief Given a reference, ref, to an hdf5 group, creates a Group object
  85. ///\param obj - IN: Specifying location referenced object is in
  86. ///\param ref - IN: Reference pointer
  87. ///\param ref_type - IN: Reference type - default to H5R_OBJECT
  88. ///\exception H5::ReferenceException
  89. ///\par Description
  90. /// \c obj can be DataSet, Group, or named DataType, that
  91. /// is a datatype that has been named by DataType::commit.
  92. // Programmer Binh-Minh Ribler - Oct, 2006
  93. //--------------------------------------------------------------------------
  94. Group::Group(H5Object& obj, const void* ref, H5R_type_t ref_type) : H5Object()
  95. {
  96. try {
  97. id = p_dereference(obj.getId(), ref, ref_type);
  98. } catch (ReferenceException deref_error) {
  99. throw ReferenceException("Group constructor - located by an H5Object",
  100. deref_error.getDetailMsg());
  101. }
  102. }
  103. //--------------------------------------------------------------------------
  104. // Function: Group overload constructor - dereference
  105. ///\brief Given a reference, ref, to an hdf5 group, creates a Group object
  106. ///\param h5file - IN: Location referenced object is in
  107. ///\param ref - IN: Reference pointer
  108. ///\param ref_type - IN: Reference type - default to H5R_OBJECT
  109. ///\exception H5::ReferenceException
  110. // Programmer Binh-Minh Ribler - Oct, 2006
  111. //--------------------------------------------------------------------------
  112. Group::Group(H5File& h5file, const void* ref, H5R_type_t ref_type) : H5Object()
  113. {
  114. try {
  115. id = p_dereference(h5file.getId(), ref, ref_type);
  116. } catch (ReferenceException deref_error) {
  117. throw ReferenceException("Group constructor - located by an H5File",
  118. deref_error.getDetailMsg());
  119. }
  120. }
  121. //--------------------------------------------------------------------------
  122. // Function: Group overload constructor - dereference
  123. ///\brief Given a reference, ref, to an hdf5 group, creates a Group object
  124. ///\param attr - IN: Specifying location where the referenced object is in
  125. ///\param ref - IN: Reference pointer
  126. ///\param ref_type - IN: Reference type - default to H5R_OBJECT
  127. ///\exception H5::ReferenceException
  128. // Programmer Binh-Minh Ribler - Oct, 2006
  129. //--------------------------------------------------------------------------
  130. Group::Group(Attribute& attr, const void* ref, H5R_type_t ref_type) : H5Object()
  131. {
  132. try {
  133. id = p_dereference(attr.getId(), ref, ref_type);
  134. } catch (ReferenceException deref_error) {
  135. throw ReferenceException("Group constructor - located by an Attribute",
  136. deref_error.getDetailMsg());
  137. }
  138. }
  139. #ifndef H5_NO_DEPRECATED_SYMBOLS
  140. //--------------------------------------------------------------------------
  141. // Function: Group::getObjType
  142. ///\brief Retrieves the type of object that an object reference points to.
  143. ///\param ref - IN: Reference to query
  144. ///\param ref_type - IN: Type of reference to query, valid values are:
  145. /// \li \c H5R_OBJECT - Reference is an object reference.
  146. /// \li \c H5R_DATASET_REGION - Reference is a dataset region reference.
  147. ///\return An object type, which can be one of the following:
  148. /// \li \c H5G_LINK (0) - Object is a symbolic link.
  149. /// \li \c H5G_GROUP (1) - Object is a group.
  150. /// \li \c H5G_DATASET (2) - Object is a dataset.
  151. /// \li \c H5G_TYPE (3) - Object is a named datatype
  152. ///\exception H5::GroupIException
  153. // Programmer Binh-Minh Ribler - May, 2004
  154. //--------------------------------------------------------------------------
  155. H5G_obj_t Group::getObjType(void *ref, H5R_type_t ref_type) const
  156. {
  157. try {
  158. return(p_get_obj_type(ref, ref_type));
  159. }
  160. catch (IdComponentException E) {
  161. throw GroupIException("Group::getObjType", E.getDetailMsg());
  162. }
  163. }
  164. #endif /* H5_NO_DEPRECATED_SYMBOLS */
  165. //--------------------------------------------------------------------------
  166. // Function: Group::getRegion
  167. ///\brief Retrieves a dataspace with the region pointed to selected.
  168. ///\param ref - IN: Reference to get region of
  169. ///\param ref_type - IN: Type of reference to get region of - default
  170. ///\return DataSpace instance
  171. ///\exception H5::GroupIException
  172. // Programmer Binh-Minh Ribler - May, 2004
  173. //--------------------------------------------------------------------------
  174. DataSpace Group::getRegion(void *ref, H5R_type_t ref_type) const
  175. {
  176. try {
  177. DataSpace dataspace(p_get_region(ref, ref_type));
  178. return(dataspace);
  179. }
  180. catch (IdComponentException E) {
  181. throw GroupIException("Group::getRegion", E.getDetailMsg());
  182. }
  183. }
  184. //--------------------------------------------------------------------------
  185. // Function: Group::getId
  186. // Purpose: Get the id of this attribute
  187. // Modification:
  188. // May 2008 - BMR
  189. // Class hierarchy is revised to address bugzilla 1068. Class
  190. // AbstractDS and Attribute are moved out of H5Object. In
  191. // addition, member IdComponent::id is moved into subclasses, and
  192. // IdComponent::getId now becomes pure virtual function.
  193. // Programmer Binh-Minh Ribler - May, 2008
  194. //--------------------------------------------------------------------------
  195. hid_t Group::getId() const
  196. {
  197. return(id);
  198. }
  199. //--------------------------------------------------------------------------
  200. // Function: Group::p_setId
  201. ///\brief Sets the identifier of this object to a new value.
  202. ///
  203. ///\exception H5::IdComponentException when the attempt to close the HDF5
  204. /// object fails
  205. // Description:
  206. // The underlaying reference counting in the C library ensures
  207. // that the current valid id of this object is properly closed.
  208. // Then the object's id is reset to the new id.
  209. // Programmer Binh-Minh Ribler - 2000
  210. //--------------------------------------------------------------------------
  211. void Group::p_setId(const hid_t new_id)
  212. {
  213. // handling references to this old id
  214. try {
  215. close();
  216. }
  217. catch (Exception close_error) {
  218. throw GroupIException("Group::p_setId", close_error.getDetailMsg());
  219. }
  220. // reset object's id to the given id
  221. id = new_id;
  222. }
  223. //--------------------------------------------------------------------------
  224. // Function: Group::close
  225. ///\brief Closes this group.
  226. ///
  227. ///\exception H5::GroupIException
  228. // Programmer Binh-Minh Ribler - Mar 9, 2005
  229. //--------------------------------------------------------------------------
  230. void Group::close()
  231. {
  232. if (p_valid_id(id))
  233. {
  234. herr_t ret_value = H5Gclose( id );
  235. if( ret_value < 0 )
  236. {
  237. throw GroupIException("Group::close", "H5Gclose failed");
  238. }
  239. // reset the id when the group that it represents is no longer
  240. // referenced
  241. if (getCounter() == 0)
  242. id = 0;
  243. }
  244. }
  245. //--------------------------------------------------------------------------
  246. // Function: Group::throwException
  247. ///\brief Throws H5::GroupIException.
  248. ///\param func_name - Name of the function where failure occurs
  249. ///\param msg - Message describing the failure
  250. ///\exception H5::GroupIException
  251. // Description
  252. // This function is used in CommonFG implementation so that
  253. // proper exception can be thrown for file or group. The
  254. // argument func_name is a member of CommonFG and "Group::"
  255. // will be inserted to indicate the function called is an
  256. // implementation of Group.
  257. // Programmer Binh-Minh Ribler - 2000
  258. //--------------------------------------------------------------------------
  259. void Group::throwException(const H5std_string& func_name, const H5std_string& msg) const
  260. {
  261. H5std_string full_name = func_name;
  262. full_name.insert(0, "Group::");
  263. throw GroupIException(full_name, msg);
  264. }
  265. //--------------------------------------------------------------------------
  266. // Function: Group destructor
  267. ///\brief Properly terminates access to this group.
  268. // Programmer Binh-Minh Ribler - 2000
  269. // Modification
  270. // - Replaced resetIdComponent() with decRefCount() to use C
  271. // library ID reference counting mechanism - BMR, Feb 20, 2005
  272. // - Replaced decRefCount with close() to let the C library
  273. // handle the reference counting - BMR, Jun 1, 2006
  274. //--------------------------------------------------------------------------
  275. Group::~Group()
  276. {
  277. try {
  278. close();
  279. }
  280. catch (Exception close_error) {
  281. cerr << "Group::~Group - " << close_error.getDetailMsg() << endl;
  282. }
  283. }
  284. #ifndef H5_NO_NAMESPACE
  285. } // end namespace
  286. #endif