H5Attribute.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 H5Attribute_H
  15. #define H5Attribute_H
  16. namespace H5 {
  17. /*! \class Attribute
  18. \brief Class Attribute operates on HDF5 attributes.
  19. An attribute has many characteristics similar to a dataset, thus both
  20. Attribute and DataSet are derivatives of AbstractDs. Attribute also
  21. inherits from H5Location because an attribute can be used to specify
  22. a location.
  23. */
  24. // Inheritance: multiple H5Location/AbstractDs -> IdComponent
  25. class H5_DLLCPP Attribute : public AbstractDs, public H5Location {
  26. public:
  27. // Copy constructor: same as the original Attribute.
  28. Attribute(const Attribute &original);
  29. // Default constructor
  30. Attribute();
  31. // Creates a copy of an existing attribute using the attribute id
  32. Attribute(const hid_t attr_id);
  33. // Closes this attribute.
  34. virtual void close() override;
  35. // Gets the name of this attribute.
  36. ssize_t getName(char *attr_name, size_t buf_size = 0) const;
  37. H5std_string getName(size_t len) const;
  38. H5std_string getName() const;
  39. ssize_t getName(H5std_string &attr_name, size_t len = 0) const;
  40. // The overloaded function below is replaced by the one above and it
  41. // is kept for backward compatibility purpose.
  42. ssize_t getName(size_t buf_size, H5std_string &attr_name) const;
  43. // Gets a copy of the dataspace for this attribute.
  44. virtual DataSpace getSpace() const override;
  45. // Returns the amount of storage size required for this attribute.
  46. virtual hsize_t getStorageSize() const override;
  47. // Returns the in memory size of this attribute's data.
  48. virtual size_t getInMemDataSize() const override;
  49. // Reads data from this attribute.
  50. void read(const DataType &mem_type, void *buf) const;
  51. void read(const DataType &mem_type, H5std_string &strg) const;
  52. // Writes data to this attribute.
  53. void write(const DataType &mem_type, const void *buf) const;
  54. void write(const DataType &mem_type, const H5std_string &strg) const;
  55. ///\brief Returns this class name.
  56. virtual H5std_string
  57. fromClass() const override
  58. {
  59. return ("Attribute");
  60. }
  61. // Gets the attribute id.
  62. virtual hid_t getId() const override;
  63. // Destructor: properly terminates access to this attribute.
  64. virtual ~Attribute() override;
  65. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  66. protected:
  67. // Sets the attribute id.
  68. virtual void p_setId(const hid_t new_id) override;
  69. #endif // DOXYGEN_SHOULD_SKIP_THIS
  70. private:
  71. hid_t id; // HDF5 attribute id
  72. // This function contains the common code that is used by
  73. // getTypeClass and various API functions getXxxType
  74. // defined in AbstractDs for generic datatype and specific
  75. // sub-types
  76. virtual hid_t p_get_type() const override;
  77. // Reads variable or fixed len strings from this attribute.
  78. void p_read_variable_len(const DataType &mem_type, H5std_string &strg) const;
  79. void p_read_fixed_len(const DataType &mem_type, H5std_string &strg) const;
  80. // Friend function to set Attribute id. For library use only.
  81. friend void f_Attribute_setId(Attribute *attr, hid_t new_id);
  82. }; // end of Attribute
  83. } // namespace H5
  84. #endif // H5Attribute_H