H5Object.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // C++ informative line for the emacs editor: -*- C++ -*-
  2. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  3. * Copyright by The HDF Group. *
  4. * Copyright by the Board of Trustees of the University of Illinois. *
  5. * All rights reserved. *
  6. * *
  7. * This file is part of HDF5. The full HDF5 copyright notice, including *
  8. * terms governing use, modification, and redistribution, is contained in *
  9. * the COPYING file, which can be found at the root of the source code *
  10. * distribution tree, or in https://www.hdfgroup.org/licenses. *
  11. * If you do not have access to either file, you may request a copy from *
  12. * help@hdfgroup.org. *
  13. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  14. #ifndef H5Object_H
  15. #define H5Object_H
  16. namespace H5 {
  17. /*! \class H5Object
  18. \brief Class H5Object is a bridge between H5Location and DataSet, DataType,
  19. and Group.
  20. Modification:
  21. Sept 18, 2012: Added class H5Location in between IdComponent and
  22. H5Object. An H5File now inherits from H5Location. All HDF5
  23. wrappers in H5Object are moved up to H5Location. H5Object
  24. is left mostly empty for future wrappers that are only for
  25. group, dataset, and named datatype. Note that the reason for
  26. adding H5Location instead of simply moving H5File to be under
  27. H5Object is H5File is not an HDF5 object, and renaming H5Object
  28. to H5Location will risk breaking user applications.
  29. -BMR
  30. Apr 2, 2014: Added wrapper getObjName for H5Iget_name
  31. Sep 21, 2016: Rearranging classes (HDFFV-9920) moved H5A wrappers back
  32. into H5Object. This way, C functions that takes attribute id
  33. can be in H5Location and those that cannot take attribute id
  34. can be in H5Object.
  35. */
  36. // Inheritance: H5Location -> IdComponent
  37. // Define the operator function pointer for H5Aiterate().
  38. typedef void (*attr_operator_t)(H5Object &loc, const H5std_string attr_name, void *operator_data);
  39. // Define the operator function pointer for H5Ovisit3().
  40. typedef int (*visit_operator_t)(H5Object &obj, const H5std_string attr_name, const H5O_info2_t *oinfo,
  41. void *operator_data);
  42. // User data for attribute iteration
  43. class UserData4Aiterate {
  44. public:
  45. attr_operator_t op;
  46. void * opData;
  47. H5Object * location; // Consider changing to H5Location
  48. };
  49. // User data for visit iteration
  50. class UserData4Visit {
  51. public:
  52. visit_operator_t op;
  53. void * opData;
  54. H5Object * obj;
  55. };
  56. class H5_DLLCPP H5Object : public H5Location {
  57. public:
  58. // Creates an attribute for the specified object
  59. // PropList is currently not used, so always be default.
  60. Attribute createAttribute(const char *name, const DataType &type, const DataSpace &space,
  61. const PropList &create_plist = PropList::DEFAULT) const;
  62. Attribute createAttribute(const H5std_string &name, const DataType &type, const DataSpace &space,
  63. const PropList &create_plist = PropList::DEFAULT) const;
  64. // Given its name, opens the attribute that belongs to an object at
  65. // this location.
  66. Attribute openAttribute(const char *name) const;
  67. Attribute openAttribute(const H5std_string &name) const;
  68. // Given its index, opens the attribute that belongs to an object at
  69. // this location.
  70. Attribute openAttribute(const unsigned int idx) const;
  71. // Iterate user's function over the attributes of this object.
  72. int iterateAttrs(attr_operator_t user_op, unsigned *idx = NULL, void *op_data = NULL);
  73. // Recursively visit elements reachable from this object.
  74. void visit(H5_index_t idx_type, H5_iter_order_t order, visit_operator_t user_op, void *op_data,
  75. unsigned int fields);
  76. // Returns the object header version of an object
  77. unsigned objVersion() const;
  78. // Determines the number of attributes belong to this object.
  79. int getNumAttrs() const;
  80. // Checks whether the named attribute exists for this object.
  81. bool attrExists(const char *name) const;
  82. bool attrExists(const H5std_string &name) const;
  83. // Renames the named attribute to a new name.
  84. void renameAttr(const char *oldname, const char *newname) const;
  85. void renameAttr(const H5std_string &oldname, const H5std_string &newname) const;
  86. // Removes the named attribute from this object.
  87. void removeAttr(const char *name) const;
  88. void removeAttr(const H5std_string &name) const;
  89. // Returns an identifier.
  90. virtual hid_t getId() const override = 0;
  91. // Gets the name of this HDF5 object, i.e., Group, DataSet, or
  92. // DataType.
  93. ssize_t getObjName(char *obj_name, size_t buf_size = 0) const;
  94. ssize_t getObjName(H5std_string &obj_name, size_t len = 0) const;
  95. H5std_string getObjName() const;
  96. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  97. protected:
  98. // Default constructor
  99. H5Object();
  100. // Sets the identifier of this object to a new value. - this one
  101. // doesn't increment reference count
  102. virtual void p_setId(const hid_t new_id) override = 0;
  103. // Noop destructor.
  104. virtual ~H5Object() override;
  105. #endif // DOXYGEN_SHOULD_SKIP_THIS
  106. }; // end of H5Object
  107. } // namespace H5
  108. #endif // H5Object_H