Учитывая вектор строк, как лучше всего записать их в набор данных HDF5? На данный момент делаю примерно следующее:
const unsigned int MaxStrLength = 512;
struct TempContainer {
char string[MaxStrLength];
};
void writeVector (hid_t group, std::vector<std::string> const & v)
{
//
// Firstly copy the contents of the vector into a temporary container
std::vector<TempContainer> tc;
for (std::vector<std::string>::const_iterator i = v.begin ()
, end = v.end ()
; i != end
; ++i)
{
TempContainer t;
strncpy (t.string, i->c_str (), MaxStrLength);
tc.push_back (t);
}
//
// Write the temporary container to a dataset
hsize_t dims[] = { tc.size () } ;
hid_t dataspace = H5Screate_simple(sizeof(dims)/sizeof(*dims)
, dims
, NULL);
hid_t strtype = H5Tcopy (H5T_C_S1);
H5Tset_size (strtype, MaxStrLength);
hid_t datatype = H5Tcreate (H5T_COMPOUND, sizeof (TempConainer));
H5Tinsert (datatype
, "string"
, HOFFSET(TempContainer, string)
, strtype);
hid_t dataset = H5Dcreate1 (group
, "files"
, datatype
, dataspace
, H5P_DEFAULT);
H5Dwrite (dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, &tc[0] );
H5Dclose (dataset);
H5Sclose (dataspace);
H5Tclose (strtype);
H5Tclose (datatype);
}
Как минимум, мне бы очень хотелось изменить вышесказанное так, чтобы:
- Он использует строки переменной длины
- Мне не нужен временный контейнер
У меня нет ограничений на то, как я храню данные, поэтому, например, это не обязательно должен быть тип данных COMPOUND, если есть лучший способ сделать это.
РЕДАКТИРОВАТЬ: Чтобы сузить проблему, я относительно знаком с игрой с данными на стороне C ++, именно на стороне HDF5 мне больше всего нужна помощь.
Спасибо за вашу помощь.