QMCPACK
h5data_proxy< std::string > Struct Template Reference

Specialization for std::string. More...

+ Collaboration diagram for h5data_proxy< std::string >:

Public Types

using data_type = std::string
 

Public Member Functions

 h5data_proxy (const data_type &a)
 
bool read (data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT)
 
bool write (const data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT) const
 

Detailed Description

template<>
struct qmcplusplus::h5data_proxy< std::string >

Specialization for std::string.

Definition at line 136 of file hdf_stl.h.

Member Typedef Documentation

◆ data_type

using data_type = std::string

Definition at line 138 of file hdf_stl.h.

Constructor & Destructor Documentation

◆ h5data_proxy()

h5data_proxy ( const data_type a)
inline

Definition at line 140 of file hdf_stl.h.

140 {}

Member Function Documentation

◆ read()

bool read ( data_type ref,
hid_t  grp,
const std::string &  aname,
hid_t  xfer_plist = H5P_DEFAULT 
)
inline

Definition at line 142 of file hdf_stl.h.

143  {
144  hid_t dataset = H5Dopen(grp, aname.c_str(), H5P_DEFAULT);
145  if (dataset > -1)
146  {
147  hid_t datatype = H5Dget_type(dataset);
148  hsize_t dim_out;
149  if (datatype == H5T_NATIVE_CHAR)
150  {
151  hid_t dataspace = H5Dget_space(dataset);
152  hid_t status = H5Sget_simple_extent_dims(dataspace, &dim_out, NULL);
153  H5Sclose(dataspace);
154  }
155  else
156  {
157  dim_out = H5Tget_size(datatype);
158  }
159  ref.resize(dim_out);
160  herr_t ret = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, xfer_plist, &(ref[0]));
161  H5Tclose(datatype);
162  H5Dclose(dataset);
163  return ret != -1;
164  }
165  return false;
166  }

◆ write()

bool write ( const data_type ref,
hid_t  grp,
const std::string &  aname,
hid_t  xfer_plist = H5P_DEFAULT 
) const
inline

Definition at line 168 of file hdf_stl.h.

169  {
170  hid_t str80 = H5Tcopy(H5T_C_S1);
171  H5Tset_size(str80, ref.size());
172  hsize_t dim = 1;
173 
174  herr_t ret = -1;
175  hid_t h1 = H5Dopen(grp, aname.c_str(), H5P_DEFAULT);
176  if (h1 < 0) // missing create one
177  {
178  hid_t dataspace = H5Screate_simple(1, &dim, NULL);
179  hid_t dataset = H5Dcreate(grp, aname.c_str(), str80, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
180  ret = H5Dwrite(dataset, str80, H5S_ALL, H5S_ALL, xfer_plist, ref.data());
181  H5Sclose(dataspace);
182  H5Dclose(dataset);
183  }
184  else
185  {
186  ret = H5Dwrite(h1, str80, H5S_ALL, H5S_ALL, xfer_plist, ref.data());
187  }
188  H5Dclose(h1);
189  return ret != -1;
190  }

The documentation for this struct was generated from the following file: