H5DataSet.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 H5DataSet_H
  15. #define H5DataSet_H
  16. namespace H5 {
  17. /*! \class DataSet
  18. \brief Class DataSet operates on HDF5 datasets.
  19. An datasets has many characteristics similar to an attribute, thus both
  20. Attribute and DataSet are derivatives of AbstractDs. DataSet also
  21. inherits from H5Object because a dataset is an HDF5 object.
  22. */
  23. // Inheritance: multiple H5Object/AbstractDs -> H5Location -> IdComponent
  24. class H5_DLLCPP DataSet : public H5Object, public AbstractDs {
  25. public:
  26. // Close this dataset.
  27. virtual void close() override;
  28. // Extends the dataset with unlimited dimension.
  29. void extend(const hsize_t *size) const;
  30. // Fills a selection in memory with a value
  31. void fillMemBuf(const void *fill, const DataType &fill_type, void *buf, const DataType &buf_type,
  32. const DataSpace &space) const;
  33. // void fillMemBuf(const void *fill, DataType& fill_type, void *buf, DataType& buf_type, DataSpace&
  34. // space); // removed from 1.8.18 and 1.10.1
  35. // Fills a selection in memory with zero
  36. void fillMemBuf(void *buf, const DataType &buf_type, const DataSpace &space) const;
  37. // void fillMemBuf(void *buf, DataType& buf_type, DataSpace& space); // removed from 1.8.18 and 1.10.1
  38. // Gets the creation property list of this dataset.
  39. DSetCreatPropList getCreatePlist() const;
  40. // Gets the access property list of this dataset.
  41. DSetAccPropList getAccessPlist() const;
  42. // Returns the address of this dataset in the file.
  43. haddr_t getOffset() const;
  44. // Gets the dataspace of this dataset.
  45. virtual DataSpace getSpace() const override;
  46. // Determines whether space has been allocated for a dataset.
  47. void getSpaceStatus(H5D_space_status_t &status) const;
  48. // Returns the amount of storage size required for this dataset.
  49. virtual hsize_t getStorageSize() const override;
  50. // Returns the in memory size of this attribute's data.
  51. virtual size_t getInMemDataSize() const override;
  52. // Returns the number of bytes required to store VL data.
  53. hsize_t getVlenBufSize(const DataType &type, const DataSpace &space) const;
  54. // hsize_t getVlenBufSize(DataType& type, DataSpace& space) const; // removed from 1.8.18 and 1.10.1
  55. // Reclaims VL datatype memory buffers.
  56. static void vlenReclaim(const DataType &type, const DataSpace &space,
  57. const DSetMemXferPropList &xfer_plist, void *buf);
  58. static void vlenReclaim(void *buf, const DataType &type, const DataSpace &space = DataSpace::ALL,
  59. const DSetMemXferPropList &xfer_plist = DSetMemXferPropList::DEFAULT);
  60. // Reads the data of this dataset and stores it in the provided buffer.
  61. // The memory and file dataspaces and the transferring property list
  62. // can be defaults.
  63. void read(void *buf, const DataType &mem_type, const DataSpace &mem_space = DataSpace::ALL,
  64. const DataSpace & file_space = DataSpace::ALL,
  65. const DSetMemXferPropList &xfer_plist = DSetMemXferPropList::DEFAULT) const;
  66. void read(H5std_string &buf, const DataType &mem_type, const DataSpace &mem_space = DataSpace::ALL,
  67. const DataSpace & file_space = DataSpace::ALL,
  68. const DSetMemXferPropList &xfer_plist = DSetMemXferPropList::DEFAULT) const;
  69. // Writes the buffered data to this dataset.
  70. // The memory and file dataspaces and the transferring property list
  71. // can be defaults.
  72. void write(const void *buf, const DataType &mem_type, const DataSpace &mem_space = DataSpace::ALL,
  73. const DataSpace & file_space = DataSpace::ALL,
  74. const DSetMemXferPropList &xfer_plist = DSetMemXferPropList::DEFAULT) const;
  75. void write(const H5std_string &buf, const DataType &mem_type, const DataSpace &mem_space = DataSpace::ALL,
  76. const DataSpace & file_space = DataSpace::ALL,
  77. const DSetMemXferPropList &xfer_plist = DSetMemXferPropList::DEFAULT) const;
  78. // Iterates the selected elements in the specified dataspace - not implemented in C++ style yet
  79. int iterateElems(void *buf, const DataType &type, const DataSpace &space, H5D_operator_t op,
  80. void *op_data = NULL);
  81. ///\brief Returns this class name.
  82. virtual H5std_string
  83. fromClass() const override
  84. {
  85. return ("DataSet");
  86. }
  87. // Creates a dataset by way of dereference.
  88. DataSet(const H5Location &loc, const void *ref, H5R_type_t ref_type = H5R_OBJECT,
  89. const PropList &plist = PropList::DEFAULT);
  90. DataSet(const Attribute &attr, const void *ref, H5R_type_t ref_type = H5R_OBJECT,
  91. const PropList &plist = PropList::DEFAULT);
  92. // Default constructor.
  93. DataSet();
  94. // Copy constructor - same as the original DataSet.
  95. DataSet(const DataSet &original);
  96. // Assignment operator
  97. DataSet &operator=(const DataSet &original);
  98. // Creates a copy of an existing DataSet using its id.
  99. DataSet(const hid_t existing_id);
  100. // Gets the dataset id.
  101. virtual hid_t getId() const override;
  102. // Destructor: properly terminates access to this dataset.
  103. virtual ~DataSet() override;
  104. protected:
  105. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  106. // Sets the dataset id.
  107. virtual void p_setId(const hid_t new_id) override;
  108. #endif // DOXYGEN_SHOULD_SKIP_THIS
  109. private:
  110. hid_t id; // HDF5 dataset id
  111. // This function contains the common code that is used by
  112. // getTypeClass and various API functions getXxxType
  113. // defined in AbstractDs for generic datatype and specific
  114. // sub-types
  115. virtual hid_t p_get_type() const override;
  116. // Reads variable or fixed len strings from this dataset.
  117. void p_read_fixed_len(const hid_t mem_type_id, const hid_t mem_space_id, const hid_t file_space_id,
  118. const hid_t xfer_plist_id, H5std_string &strg) const;
  119. void p_read_variable_len(const hid_t mem_type_id, const hid_t mem_space_id, const hid_t file_space_id,
  120. const hid_t xfer_plist_id, H5std_string &strg) const;
  121. // Friend function to set DataSet id. For library use only.
  122. friend void f_DataSet_setId(DataSet *dset, hid_t new_id);
  123. }; // end of DataSet
  124. } // namespace H5
  125. #endif // H5DataSet_H