My Project  1.12.0
H5File.h
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://support.hdfgroup.org/ftp/HDF5/releases. *
11  * If you do not have access to either file, you may request a copy from *
12  * help@hdfgroup.org. *
13  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
14 
15 #ifndef __H5File_H
16 #define __H5File_H
17 
18 namespace H5 {
19 
24 // Inheritance: Group -> CommonFG/H5Object -> H5Location -> IdComponent
25 class H5_DLLCPP H5File : public Group {
26  public:
27  // Creates or opens an HDF5 file.
28  H5File(const char* name, unsigned int flags,
29  const FileCreatPropList& create_plist = FileCreatPropList::DEFAULT,
30  const FileAccPropList& access_plist = FileAccPropList::DEFAULT);
31  H5File(const H5std_string& name, unsigned int flags,
32  const FileCreatPropList& create_plist = FileCreatPropList::DEFAULT,
33  const FileAccPropList& access_plist = FileAccPropList::DEFAULT);
34 
35  // Open the file
36  void openFile(const H5std_string& name, unsigned int flags,
37  const FileAccPropList& access_plist = FileAccPropList::DEFAULT);
38  void openFile(const char* name, unsigned int flags,
39  const FileAccPropList& access_plist = FileAccPropList::DEFAULT);
40 
41  // Close this file.
42  virtual void close();
43 
44  // Gets a copy of the access property list of this file.
45  FileAccPropList getAccessPlist() const;
46 
47  // Gets a copy of the creation property list of this file.
48  FileCreatPropList getCreatePlist() const;
49 
50  // Gets general information about this file.
51  void getFileInfo(H5F_info2_t& file_info) const;
52 
53  // Returns the amount of free space in the file.
54  hssize_t getFreeSpace() const;
55 
56  // Returns the number of opened object IDs (files, datasets, groups
57  // and datatypes) in the same file.
58  ssize_t getObjCount(unsigned types = H5F_OBJ_ALL) const;
59 
60  // Retrieves a list of opened object IDs (files, datasets, groups
61  // and datatypes) in the same file.
62  void getObjIDs(unsigned types, size_t max_objs, hid_t *oid_list) const;
63 
64  // Returns the pointer to the file handle of the low-level file driver.
65  void getVFDHandle(void **file_handle) const;
66  void getVFDHandle(const FileAccPropList& fapl, void **file_handle) const;
67  //void getVFDHandle(FileAccPropList& fapl, void **file_handle) const; // removed from 1.8.18 and 1.10.1
68 
69  // Returns the file size of the HDF5 file.
70  hsize_t getFileSize() const;
71 
72  // Returns the 'file number' of the HDF5 file.
73  unsigned long getFileNum() const;
74 
75  // Determines if a file, specified by its name, is in HDF5 format
76  static bool isHdf5(const char* name);
77  static bool isHdf5(const H5std_string& name);
78 
79  // Determines if a file, specified by its name, can be accessed as HDF5
80  static bool isAccessible(const char* name, const FileAccPropList& access_plist = FileAccPropList::DEFAULT);
81  static bool isAccessible(const H5std_string& name, const FileAccPropList& access_plist = FileAccPropList::DEFAULT);
82 
83  // Reopens this file.
84  void reOpen(); // added for better name
85 
86 #ifndef DOXYGEN_SHOULD_SKIP_THIS
87  void reopen(); // obsolete in favor of reOpen()
88 
89  // Creates an H5File using an existing file id. Not recommended
90  // in applications.
91  H5File(hid_t existing_id);
92 
93 #endif // DOXYGEN_SHOULD_SKIP_THIS
94 
96  virtual H5std_string fromClass () const { return("H5File"); }
97 
98  // Throw file exception.
99  virtual void throwException(const H5std_string& func_name, const H5std_string& msg) const;
100 
101  // For CommonFG to get the file id.
102  virtual hid_t getLocId() const;
103 
104  // Default constructor
105  H5File();
106 
107  // Copy constructor: same as the original H5File.
108  H5File(const H5File& original);
109 
110  // Gets the HDF5 file id.
111  virtual hid_t getId() const;
112 
113  // H5File destructor.
114  virtual ~H5File();
115 
116  protected:
117 #ifndef DOXYGEN_SHOULD_SKIP_THIS
118  // Sets the HDF5 file id.
119  virtual void p_setId(const hid_t new_id);
120 #endif // DOXYGEN_SHOULD_SKIP_THIS
121 
122  private:
123  hid_t id; // HDF5 file id
124 
125  // This function is private and contains common code between the
126  // constructors taking a string or a char*
127  void p_get_file(const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist);
128 
129 }; // end of H5File
130 } // namespace H5
131 
132 #endif // __H5File_H
133 
H5::Exception
Exception provides wrappers of HDF5 error handling functions.
Definition: H5Exception.h:32
H5::H5File::getFileInfo
void getFileInfo(H5F_info2_t &file_info) const
Retrieves the general information of this file.
Definition: H5File.cpp:401
H5::H5File::close
virtual void close()
Closes this HDF5 file.
Definition: H5File.cpp:684
H5::H5File::getVFDHandle
void getVFDHandle(void **file_handle) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: H5File.cpp:552
H5::H5File::getAccessPlist
FileAccPropList getAccessPlist() const
Returns a copy of the access property list of this file.
Definition: H5File.cpp:374
H5::IdComponent::incRefCount
void incRefCount() const
Increment reference counter for the id of this object.
Definition: H5IdComponent.cpp:53
H5::H5File::reOpen
void reOpen()
Reopens this file.
Definition: H5File.cpp:327
H5::H5File::openFile
void openFile(const H5std_string &name, unsigned int flags, const FileAccPropList &access_plist=FileAccPropList::DEFAULT)
This is an overloaded member function, provided for convenience. It takes an H5std_string for name.
Definition: H5File.cpp:306
H5::H5File::isHdf5
static bool isHdf5(const char *name)
Determines whether a file in HDF5 format. (Static)
Definition: H5File.cpp:193
H5::FileIException
Definition: H5Exception.h:95
H5::FileAccPropList::DEFAULT
static const FileAccPropList & DEFAULT
Default file access property list.
Definition: H5FaccProp.h:28
H5::H5File::isAccessible
static bool isAccessible(const char *name, const FileAccPropList &access_plist=FileAccPropList::DEFAULT)
Determines whether a file can be accessed as HDF5. (Static)
Definition: H5File.cpp:231
H5::H5File::getId
virtual hid_t getId() const
Get the id of this file.
Definition: H5File.cpp:615
H5::Group
Class Group represents an HDF5 group.
Definition: H5Group.h:24
H5::H5File::getFreeSpace
hssize_t getFreeSpace() const
Returns the amount of free space in the file.
Definition: H5File.cpp:417
H5::H5File::H5File
H5File()
Default constructor: creates a stub H5File object.
Definition: H5File.cpp:52
H5::FileCreatPropList
Class FileCreatPropList inherits from PropList and provides wrappers for the HDF5 file create propert...
Definition: H5FcreatProp.h:25
H5::H5File::getCreatePlist
FileCreatPropList getCreatePlist() const
Returns a copy of the creation property list of this file.
Definition: H5File.cpp:350
H5::H5File::getFileSize
hsize_t getFileSize() const
Returns the file size of the HDF5 file.
Definition: H5File.cpp:571
H5::Exception::getDetailMsg
H5std_string getDetailMsg() const
Returns the detailed message set at the time the exception is thrown.
Definition: H5Exception.cpp:256
H5::FileCreatPropList::DEFAULT
static const FileCreatPropList & DEFAULT
Default file creation property list.
Definition: H5FcreatProp.h:28
H5::H5File::throwException
virtual void throwException(const H5std_string &func_name, const H5std_string &msg) const
Throws file exception - initially implemented for CommonFG.
Definition: H5File.cpp:711
H5::H5File
Class H5File represents an HDF5 file and inherits from class Group as file is a root group.
Definition: H5File.h:25
H5::H5File::getObjIDs
void getObjIDs(unsigned types, size_t max_objs, hid_t *oid_list) const
Retrieves a list of opened object IDs (files, datasets, groups and datatypes) in the same file.
Definition: H5File.cpp:484
H5::H5File::getFileNum
unsigned long getFileNum() const
Returns the file number of the HDF5 file.
Definition: H5File.cpp:592
H5::PropList::getId
virtual hid_t getId() const
Get the id of this property list.
Definition: H5PropList.cpp:292
H5::H5File::getLocId
virtual hid_t getLocId() const
H5::H5File::fromClass
virtual H5std_string fromClass() const
Returns this class name.
Definition: H5File.h:96
H5::H5File::~H5File
virtual ~H5File()
Properly terminates access to this file.
Definition: H5File.cpp:728
H5::H5File::getObjCount
ssize_t getObjCount(unsigned types=H5F_OBJ_ALL) const
Returns the number of opened object IDs (files, datasets, groups and datatypes) in the same file.
Definition: H5File.cpp:449
H5
Definition: H5AbstractDs.cpp:34
H5::FileAccPropList
Class FileAccPropList inherits from PropList and provides wrappers for the HDF5 file access property ...
Definition: H5FaccProp.h:25


The HDF Group Help Desk:
  Copyright by The HDF Group
and the Board of Trustees of the University of Illinois