H5File.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 H5File_H
  15. #define H5File_H
  16. namespace H5 {
  17. /*! \class H5File
  18. \brief Class H5File represents an HDF5 file and inherits from class Group
  19. as file is a root group.
  20. */
  21. // Inheritance: Group -> CommonFG/H5Object -> H5Location -> IdComponent
  22. class H5_DLLCPP H5File : public Group {
  23. public:
  24. // Creates or opens an HDF5 file.
  25. H5File(const char *name, unsigned int flags,
  26. const FileCreatPropList &create_plist = FileCreatPropList::DEFAULT,
  27. const FileAccPropList & access_plist = FileAccPropList::DEFAULT);
  28. H5File(const H5std_string &name, unsigned int flags,
  29. const FileCreatPropList &create_plist = FileCreatPropList::DEFAULT,
  30. const FileAccPropList & access_plist = FileAccPropList::DEFAULT);
  31. // Open the file
  32. void openFile(const H5std_string &name, unsigned int flags,
  33. const FileAccPropList &access_plist = FileAccPropList::DEFAULT);
  34. void openFile(const char *name, unsigned int flags,
  35. const FileAccPropList &access_plist = FileAccPropList::DEFAULT);
  36. // Close this file.
  37. virtual void close() override;
  38. // Gets a copy of the access property list of this file.
  39. FileAccPropList getAccessPlist() const;
  40. // Gets a copy of the creation property list of this file.
  41. FileCreatPropList getCreatePlist() const;
  42. // Gets general information about this file.
  43. void getFileInfo(H5F_info2_t &file_info) const;
  44. // Returns the amount of free space in the file.
  45. hssize_t getFreeSpace() const;
  46. // Returns the number of opened object IDs (files, datasets, groups
  47. // and datatypes) in the same file.
  48. ssize_t getObjCount(unsigned types = H5F_OBJ_ALL) const;
  49. // Retrieves a list of opened object IDs (files, datasets, groups
  50. // and datatypes) in the same file.
  51. void getObjIDs(unsigned types, size_t max_objs, hid_t *oid_list) const;
  52. // Returns the pointer to the file handle of the low-level file driver.
  53. void getVFDHandle(void **file_handle) const;
  54. void getVFDHandle(const FileAccPropList &fapl, void **file_handle) const;
  55. // void getVFDHandle(FileAccPropList& fapl, void **file_handle) const; // removed from 1.8.18 and 1.10.1
  56. // Returns the file size of the HDF5 file.
  57. hsize_t getFileSize() const;
  58. // Returns the 'file number' of the HDF5 file.
  59. unsigned long getFileNum() const;
  60. // Determines if a file, specified by its name, is in HDF5 format
  61. static bool isHdf5(const char *name);
  62. static bool isHdf5(const H5std_string &name);
  63. // Determines if a file, specified by its name, can be accessed as HDF5
  64. static bool isAccessible(const char * name,
  65. const FileAccPropList &access_plist = FileAccPropList::DEFAULT);
  66. static bool isAccessible(const H5std_string & name,
  67. const FileAccPropList &access_plist = FileAccPropList::DEFAULT);
  68. // Reopens this file.
  69. void reOpen(); // added for better name
  70. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  71. void reopen(); // obsolete in favor of reOpen()
  72. // Creates an H5File using an existing file id. Not recommended
  73. // in applications.
  74. H5File(hid_t existing_id);
  75. #endif // DOXYGEN_SHOULD_SKIP_THIS
  76. ///\brief Returns this class name.
  77. virtual H5std_string
  78. fromClass() const override
  79. {
  80. return ("H5File");
  81. }
  82. // Throw file exception.
  83. virtual void throwException(const H5std_string &func_name, const H5std_string &msg) const override;
  84. // For CommonFG to get the file id.
  85. virtual hid_t getLocId() const override;
  86. // Default constructor
  87. H5File();
  88. // Copy constructor: same as the original H5File.
  89. H5File(const H5File &original);
  90. // Gets the HDF5 file id.
  91. virtual hid_t getId() const override;
  92. // H5File destructor.
  93. virtual ~H5File() override;
  94. protected:
  95. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  96. // Sets the HDF5 file id.
  97. virtual void p_setId(const hid_t new_id) override;
  98. #endif // DOXYGEN_SHOULD_SKIP_THIS
  99. private:
  100. hid_t id; // HDF5 file id
  101. // This function is private and contains common code between the
  102. // constructors taking a string or a char*
  103. void p_get_file(const char *name, unsigned int flags, const FileCreatPropList &create_plist,
  104. const FileAccPropList &access_plist);
  105. }; // end of H5File
  106. } // namespace H5
  107. #endif // H5File_H