Hdf5File.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2007 Ball Aerospace & Technologies Corporation
00004  * and is subject to the terms and conditions of the
00005  * GNU Lesser General Public License Version 2.1
00006  * The license text is available from   
00007  * http://www.gnu.org/licenses/lgpl.html
00008  */
00009 
00010 #ifndef HDF5FILE_H
00011 #define HDF5FILE_H
00012 
00013 #include <hdf5.h>
00014 #include <string>
00015 #include <vector>
00016 
00017 #include "Hdf5Node.h"
00018 
00019 class Hdf5Group;
00020 
00021 /**
00022  * The HDF File is provided as an abstraction of the structure of the HDF File
00023  * on disk without requiring the HDF libraries installed.
00024  */
00025 class Hdf5File : public Hdf5Node
00026 {
00027 public:
00028    /**
00029     * Creates an Hdf5File with a given filename.
00030     *
00031     * @param  filename
00032     *         The name of the HDF file on disk.
00033     *
00034     * @param  fileHandle
00035     *         Handle to a previously open file, or -1 if the file is currently unavailable.
00036     *         This object does NOT assume ownership of fileHandle.
00037     */
00038    explicit Hdf5File(const std::string& filename, hid_t fileHandle = -1);
00039    
00040    /**
00041     * Destroys the Hdf5File object.
00042     */
00043    ~Hdf5File();
00044 
00045    /**
00046     * Returns a pointer to the file's 'root group' object. The root group will be empty until readFileData() is called.
00047     *
00048     * @return A pointer to the %Hdf5File's root group object. Cannot be NULL.
00049     *
00050     * @see readFileData()
00051     */
00052    virtual Hdf5Group* getRootGroup() const;
00053 
00054    /**
00055     * Returns the name of the file.
00056     *
00057     * @return The filename provided to the constructor.
00058     */
00059    virtual std::string getFilename() const;
00060 
00061    /**
00062     * Returns the file handle.
00063     *
00064     * @return The fileHandle provided to the constructor.
00065     */
00066    virtual hid_t getFileHandle() const;
00067 
00068    /**
00069     * Reads the HDF file at the specified path, opening and closing it if necessary.
00070     *
00071     * This method reads the data from the file. If the fileHandle passed to the constructor was valid,
00072     * then that handle will be used to access the file. If the fileHandle passed to the constructor was not valid,
00073     * then the file will be opened, read, and closed before returning from this method.
00074     *
00075     * @param  groupPath
00076     *         The desired HDF group to read. This group will be iterated over via H5Giterate.
00077     *         The results are stored in the 'root group' object with paths relative to the root of the HDF file.
00078     *
00079     * @return True on success, false otherwise.
00080     *
00081     * @see getRootGroup(), getFileHandle(), getFilename()
00082     */
00083    bool readFileData(const std::string& groupPath = "/");
00084 
00085    // Override of Hdf5Node function
00086    virtual Hdf5File* getFile() const;
00087 
00088 private:
00089    hid_t mFileHandle;
00090    std::string mFilename;
00091    Hdf5Group* mpRootGroup;
00092 };
00093 
00094 #endif

Software Development Kit - Opticks 4.9.0 Build 16218