Page MenuHomec4science

specmicp_hdf5.hpp
No OneTemporary

File Metadata

Created
Thu, May 16, 23:47

specmicp_hdf5.hpp

/* =============================================================================
Copyright (c) 2014 - 2016
F. Georget <fabieng@princeton.edu> Princeton University
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
============================================================================= */
#ifndef SPECMICP_UTIL_SPECMICPHDF5_HPP
#define SPECMICP_UTIL_SPECMICPHDF5_HPP
#include "../../macros.hpp"
#include <memory>
// forward declaration
namespace H5 {
class H5File;
class DataSet;
class DataSpace;
class PredType;
class DataType;
class DSetCreatPropList;
class Group;
} //end namespace H5
namespace specmicp {
namespace io {
//! \brief Mode to open/create a file
enum class HDF5_OpenMode
{
CreateTruncate, //!< Create a file, truncate if it exists
CreateFailIfExist, //!< Create a file, fail if it exists
OpenReadOnly, //!< Open a file, read only mode
OpenReadWrite //!< Open a file, read write mode
};
//! \brief A HDF5 file
//!
//! To be subclassed
class SPECMICP_DLL_PUBLIC HDF5File
{
public:
HDF5File();
HDF5File(const std::string& filename, HDF5_OpenMode mode);
~HDF5File();
//! \brief Open a file
//!
//! \param filename Name of the file to open
//! \param mode Opening mode
//! \return True if the file was successfully open
//!
bool open(const std::string& filename, HDF5_OpenMode mode);
//! \brief Close the file
void close();
//! \brief Return true if the file handle is open
bool is_open();
//! \brief Create a dataset in the root ("/")
std::unique_ptr<H5::DataSet> create_dataset(
const std::string& name,
const H5::DataType& type,
const H5::DataSpace& data_space,
const H5::DSetCreatPropList& list
);
//! \brief Create a dataset in 'section'
std::unique_ptr<H5::DataSet> create_dataset(
const std::string& name,
const std::string& section,
const H5::DataType& type,
const H5::DataSpace& data_space,
const H5::DSetCreatPropList& list
);
//! \brief Create a new group
std::unique_ptr<H5::Group> create_group(
const std::string& name
);
//! \brief Give the complete the name of a dataset
std::string complete_name(
const std::string& name,
const std::string& section
);
protected:
std::unique_ptr<H5::H5File> m_file {nullptr};
private:
HDF5File(const HDF5File& other) = delete;
HDF5File& operator= (const HDF5File& other) = delete;
};
} //end namespace io
} //end namespace specmicp
#endif // SPECMICP_UTIL_SPECMICPHDF5_HPP

Event Timeline