H5File.h

00001 // C++ informative line for the emacs editor: -*- C++ -*-
00002 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00003  * Copyright by The HDF Group.                                               *
00004  * Copyright by the Board of Trustees of the University of Illinois.         *
00005  * All rights reserved.                                                      *
00006  *                                                                           *
00007  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
00008  * terms governing use, modification, and redistribution, is contained in    *
00009  * the files COPYING and Copyright.html.  COPYING can be found at the root   *
00010  * of the source code distribution tree; Copyright.html can be found at the  *
00011  * root level of an installed copy of the electronic HDF5 document set and   *
00012  * is linked from the top-level documents page.  It can also be found at     *
00013  * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
00014  * access to either file, you may request a copy from help@hdfgroup.org.     *
00015  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00016 
00017 #ifndef _H5File_H
00018 #define _H5File_H
00019 
00020 #ifndef H5_NO_NAMESPACE
00021 namespace H5 {
00022 #endif
00023 
00024 class H5_DLLCPP H5File : public IdComponent, public CommonFG {
00025    public:
00026         // Creates or opens an HDF5 file.
00027         H5File( const char* name, unsigned int flags,
00028            const FileCreatPropList& create_plist = FileCreatPropList::DEFAULT,
00029            const FileAccPropList& access_plist = FileAccPropList::DEFAULT );
00030         H5File( const H5std_string& name, unsigned int flags,
00031            const FileCreatPropList& create_plist = FileCreatPropList::DEFAULT,
00032            const FileAccPropList& access_plist = FileAccPropList::DEFAULT );
00033 
00034         // Open the file
00035         void openFile(const H5std_string& name, unsigned int flags,
00036             const FileAccPropList& access_plist = FileAccPropList::DEFAULT);
00037         void openFile(const char* name, unsigned int flags,
00038             const FileAccPropList& access_plist = FileAccPropList::DEFAULT);
00039 
00040         // Close this file.
00041         virtual void close();
00042 
00043         // Flushes all buffers associated with this file to disk
00044         void flush(H5F_scope_t scope) const;
00045 
00046         // Gets the access property list of this file.
00047         FileAccPropList getAccessPlist() const;
00048 
00049         // Gets the creation property list of this file.
00050         FileCreatPropList getCreatePlist() const;
00051 
00052         // Gets the name of this file.
00053         H5std_string getFileName() const;
00054 
00055         // Retrieves the file size of an opened file.
00056         hsize_t getFileSize() const;
00057 
00058         // Returns the amount of free space in the file.
00059         hssize_t getFreeSpace() const;
00060 
00061         // Returns the number of opened object IDs (files, datasets, groups
00062         // and datatypes) in the same file.
00063         ssize_t getObjCount(unsigned types) const;
00064         ssize_t getObjCount() const;
00065 
00066         // Retrieves a list of opened object IDs (files, datasets, groups
00067         // and datatypes) in the same file.
00068         void getObjIDs(unsigned types, size_t max_objs, hid_t *oid_list) const;
00069 
00070 #ifndef H5_NO_DEPRECATED_SYMBOLS
00071         // Retrieves the type of object that an object reference points to.
00072         H5G_obj_t getObjType(void *ref, H5R_type_t ref_type = H5R_OBJECT) const;
00073 #endif /* H5_NO_DEPRECATED_SYMBOLS */
00074 
00075         // Retrieves a dataspace with the region pointed to selected.
00076         DataSpace getRegion(void *ref, H5R_type_t ref_type = H5R_DATASET_REGION) const;
00077 
00078         // Returns the pointer to the file handle of the low-level file driver.
00079         void getVFDHandle(FileAccPropList& fapl, void **file_handle) const;
00080         void getVFDHandle(void **file_handle) const;
00081 
00082         // Determines if a file, specified by its name, is in HDF5 format
00083         static bool isHdf5(const char* name );
00084         static bool isHdf5(const H5std_string& name );
00085 
00086         // Reopens this file.
00087         void reOpen();  // added for better name
00088         void reopen();
00089 
00090         // Creates a reference to a named HDF5 object or to a dataset region
00091         // in this object.
00092         void reference(void* ref, const char* name, const DataSpace& dataspace,
00093                         H5R_type_t ref_type = H5R_DATASET_REGION) const;
00094         void reference(void* ref, const char* name) const;
00095         void reference(void* ref, const H5std_string& name) const;
00096 
00098         virtual H5std_string fromClass () const { return("H5File"); }
00099 
00100         // Throw file exception.
00101         virtual void throwException(const H5std_string& func_name, const H5std_string& msg) const;
00102 
00103         // Gets the file id
00104         virtual hid_t getLocId() const;
00105 
00106         // Default constructor
00107         H5File();
00108 
00109         // Copy constructor: makes a copy of the original H5File object.
00110         H5File(const H5File& original);
00111 
00112         // Gets the HDF5 file id.
00113         virtual hid_t getId() const;
00114 
00115         // H5File destructor.
00116         virtual ~H5File();
00117 
00118    private:
00119         hid_t id;       // HDF5 file id
00120 
00121 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00122 
00123         // This function is private and contains common code between the
00124         // constructors taking a string or a char*
00125         void p_get_file( const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist );
00126 
00127         // Creates a reference to an HDF5 object or a dataset region.
00128         void p_reference(void* ref, const char* name, hid_t space_id, H5R_type_t ref_type) const;
00129 
00130 #ifndef H5_NO_DEPRECATED_SYMBOLS
00131         // Retrieves the type of object that an object reference points to.
00132         H5G_obj_t p_get_obj_type(void *ref, H5R_type_t ref_type) const;
00133 #endif /* H5_NO_DEPRECATED_SYMBOLS */
00134 
00135         // Retrieves a dataspace with the region pointed to selected.
00136         hid_t p_get_region(void *ref, H5R_type_t ref_type) const;
00137 
00138    protected:
00139         // Sets the HDF5 file id.
00140         virtual void p_setId(const hid_t new_id);
00141 
00142 #endif // DOXYGEN_SHOULD_SKIP_THIS
00143 
00144 };
00145 #ifndef H5_NO_NAMESPACE
00146 }
00147 #endif
00148 #endif