4 #ifndef tools_hdf5_pages
5 #define tools_hdf5_pages
31 hid_t a_group,
const std::string& a_name,
const std::string& a_form,
32 bool a_write,
unsigned int a_compress)
33 :m_out(a_out),m_name(a_name),m_form(a_form)
35 ,m_group(-1),m_dataset(-1),m_write(a_write),m_compress(a_compress),m_entries(0),m_pos(0){
37 tools::mem::increment(s_class().c_str());
42 m_out <<
"pages::pages : can't create group for column " << m_name <<
"." << std::endl;
46 if(!
write_atb(m_group,
"class",s_class())) {
47 m_out <<
"pages::pages : write_atb(class) failed." << std::endl;
53 if (!write_scalar_atb<int>(m_group,
"version",v)) {
54 m_out <<
"pages::pages : write_scalar_atb(version) failed." << std::endl;
62 m_out <<
"pages::pages : can't open group for column " << m_name <<
"." << std::endl;
66 if(!read_scalar<tools::uint64>(m_group,s_entries(),m_entries)) {
67 m_out <<
"pages::pages : read_scalar(entries) failed." << std::endl;
76 if(!write_scalar<tools::uint64>(m_group,s_entries(),m_entries)) {
77 m_out <<
"pages::~pages : write_scalar(entries) failed." << std::endl;
79 if(m_dataset>=0) ::H5Dclose(m_dataset);
83 tools::mem::decrement(s_class().c_str());
89 tools::mem::increment(s_class().c_str());
94 bool is_valid()
const {
return m_group<0?
false:
true;}
96 const std::string&
name()
const {
return m_name;}
97 const std::string&
form()
const {
return m_form;}
104 template <
class TYPE>
107 if(!write_array<TYPE>(m_group,s_pages(),a_size,a_array,a_size?a_size:32,m_compress)) {
108 m_out <<
"pages::write_page : write_array<TYPE>() failed. Pos " << m_pos << std::endl;
113 m_out <<
"pages::write_page : H5Dopen failed. Pos " << m_pos << std::endl;
117 if(!write_append_array_dataset<TYPE>(m_dataset,a_size,a_array)) {
118 m_out <<
"pages::write_page : write_append_array_dataset<TYPE>() failed. Pos " << m_pos << std::endl;
127 template <
class TYPE>
130 unsigned int _size = a_size;
133 if(!read_sub_array<TYPE>(m_group,s_pages(),(
unsigned int)m_pos,(
unsigned int)_size,n,
array)) {
134 m_out <<
"pages::read_page : read_sub_array<TYPE>() failed." << std::endl;
138 m_out <<
"pages::read_page : size mismatch. Requested " << _size <<
", got "<< n <<
"." << std::endl;
143 {TYPE* rpos = (TYPE*)
array;
144 TYPE* wpos = (TYPE*)a_array;
145 for(
size_t i=0;i<n;i++,rpos++,wpos++) *wpos = *rpos;
146 for(
size_t i=n;i<_size;i++,rpos++,wpos++) *wpos = TYPE();}
154 template <
class TYPE>
157 if(!hdf5::write_vlen<TYPE>(m_group,s_pages(),a_size,a_array,a_size?a_size:32,m_compress)) {
158 m_out <<
"pages::write_vlen : write_vlen<TYPE>() failed. Pos " << m_pos << std::endl;
163 m_out <<
"pages::write_vlen : H5Dopen failed. Pos " << m_pos << std::endl;
167 if(!write_append_vlen_dataset<TYPE>(m_dataset,a_size,a_array)) {
168 m_out <<
"pages::write_vlen : write_append_vlen_dataset<TYPE>() failed. Pos " << m_pos << std::endl;
177 template <
class TYPE>
181 if(!read_sub_vlen<TYPE>(m_group,s_pages(),(
unsigned int)m_pos,sz,a_array)) {
182 m_out <<
"pages::read_vlen : read_sub_vlen<TYPE>() failed." << std::endl;
196 m_out <<
"pages::write_string : hdf5::write_string() failed. Pos " << m_pos << std::endl;
201 m_out <<
"pages::write_string : H5Dopen failed. Pos " << m_pos << std::endl;
206 m_out <<
"pages::write_string : write_append_string_dataset() failed. Pos " << m_pos << std::endl;
217 m_out <<
"pages::read_string : read_sub_string() failed." << std::endl;