Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91568889
specmicp_hdf5.hpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Nov 12, 07:14
Size
5 KB
Mime Type
text/x-c++
Expires
Thu, Nov 14, 07:14 (2 d)
Engine
blob
Format
Raw Data
Handle
22284463
Attached To
rSPECMICP SpecMiCP / ReactMiCP
specmicp_hdf5.hpp
View Options
/* =============================================================================
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 "specmicp_common/macros.hpp"
#include <memory>
#include <functional>
#include "H5public.h"
// herr_t
#include "H5Ipublic.h"
// hid_t
// forward declaration
namespace
H5
{
class
H5File
;
class
Attribute
;
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
};
using
iterate_function_t
=
herr_t
(
*
)(
hid_t
,
const
char
*
,
void
*
);
//! \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 Open a dataset
std
::
unique_ptr
<
H5
::
DataSet
>
open_dataset
(
const
std
::
string
&
name
)
const
;
//! \brief Open a dataset in 'section'
std
::
unique_ptr
<
H5
::
DataSet
>
open_dataset
(
const
std
::
string
&
name
,
const
std
::
string
&
section
)
const
;
//! \brief Create a new group
std
::
unique_ptr
<
H5
::
Group
>
create_group
(
const
std
::
string
&
name
);
//! \brief Open an existing group
std
::
unique_ptr
<
H5
::
Group
>
open_group
(
const
std
::
string
&
name
)
const
;
//! \brief Give the complete the name of a dataset
static
std
::
string
complete_name
(
const
std
::
string
&
name
,
const
std
::
string
&
section
);
//! \brief Create an attribute
std
::
unique_ptr
<
H5
::
Attribute
>
create_attribute
(
const
std
::
string
&
name
,
const
H5
::
DataType
&
type
,
const
H5
::
DataSpace
&
data_space
);
//! \brief Open an attribute
std
::
unique_ptr
<
H5
::
Attribute
>
open_attribute
(
const
std
::
string
&
name
)
const
;
//! \brief Return the number of objects in the file
std
::
size_t
get_number_objects
();
//! \brief Return the number of objects in the group 'section'
std
::
size_t
get_number_objects
(
const
std
::
string
&
section
);
//! \brief Iterate other the elements
int
iterate_over_elements
(
iterate_function_t
func
);
int
iterate_over_elements
(
iterate_function_t
func
,
void
*
extra_data
);
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
Log In to Comment