Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dose create_compound support string or vector? #601

Closed
xuedj opened this issue Aug 6, 2022 · 2 comments
Closed

Dose create_compound support string or vector? #601

xuedj opened this issue Aug 6, 2022 · 2 comments

Comments

@xuedj
Copy link

xuedj commented Aug 6, 2022

#include <highfive/H5DataType.hpp>
#include <highfive/H5File.hpp>
#include <string>
#include <vector>
using namespace std;
using namespace HighFive;

struct Test {
  int i;
  string str;
  vector<int> vec;
};

CompoundType create_compound_Test() {
  return CompoundType{{"i", create_datatype<int>()},
                      {"str", create_datatype<string>()},
                      {"vec", create_datatype<vector<int>>()}};
}
HIGHFIVE_REGISTER_TYPE(Test, create_compound_Test)

int main() {
  const std::string FILE_NAME("test_compounds.h5");
  const std::string DATASET_NAME("Test");

  HighFive::File file(FILE_NAME, HighFive::File::Truncate);

  auto t1 = create_compound_Test();
  t1.commit(file, "Test");

  std::vector<Test> dims{{1, "3", vector<int>{0, 1}},
                         {2, "4", vector<int>{2, 3}}};
  auto dataset = file.createDataSet(DATASET_NAME, dims);

  auto g1 = file.createGroup("group1");
  g1.createAttribute(DATASET_NAME, dims);
}

//==============================================================================

In file included from /usr/local/HighFive/include/highfive/H5DataType.hpp:395:0,
                 from /mnt/hdd1T/program/HighFive-2.4.1/src/examples/test/test_compound.cpp:13:
/usr/local/HighFive/include/highfive/bits/H5DataType_misc.hpp: In instantiation of ‘HighFive::AtomicType<T>::AtomicType() [with T = std::vector<int>]’:
/usr/local/HighFive/include/highfive/bits/H5DataType_misc.hpp:425:12:   required from ‘HighFive::DataType HighFive::create_datatype() [with T = std::vector<int>]’
/mnt/hdd1T/program/HighFive-2.4.1/src/examples/test/test_compound.cpp:29:60:   required from here
/usr/local/HighFive/include/highfive/bits/H5DataType_misc.hpp:187:5: error: static assertion failed: Atomic types cant be arrays, except for char[] (fixed-length strings)
     static_assert(details::inspector<T>::recursive_ndim == 0,
     ^~~~~~~~~~~~~
In file included from /usr/local/HighFive/include/highfive/bits/H5Attribute_misc.hpp:25:0,
                 from /usr/local/HighFive/include/highfive/bits/H5Annotate_traits_misc.hpp:18,
                 from /usr/local/HighFive/include/highfive/H5File.hpp:94,
                 from /mnt/hdd1T/program/HighFive-2.4.1/src/examples/test/test_compound.cpp:14:
/usr/local/HighFive/include/highfive/bits/H5Converter_misc.hpp: In instantiation of ‘HighFive::details::data_converter<T, Enable>::data_converter(const HighFive::DataSpace&) [with Scalar = std::vector<Test>; Enable = void]’:
/usr/local/HighFive/include/highfive/bits/H5Slice_traits_misc.hpp:226:32:   required from ‘void HighFive::SliceTraits<Derivate>::write(const T&) [with T = std::vector<Test>; Derivate = HighFive::DataSet]’
/usr/local/HighFive/include/highfive/bits/H5Node_traits_misc.hpp:82:5:   required from ‘HighFive::DataSet HighFive::NodeTraits<Derivate>::createDataSet(const string&, const T&, const DataSetCreateProps&, const DataSetAccessProps&, bool) [with T = std::vector<Test>; Derivate = HighFive::File; std::__cxx11::string = std::__cxx11::basic_string<char>; HighFive::DataSetCreateProps = HighFive::PropertyList<(HighFive::PropertyType)3>; HighFive::DataSetAccessProps = HighFive::PropertyList<(HighFive::PropertyType)4>]’
/mnt/hdd1T/program/HighFive-2.4.1/src/examples/test/test_compound.cpp:44:55:   required from here
/usr/local/HighFive/include/highfive/bits/H5Converter_misc.hpp:120:9: error: static assertion failed: supported datatype should be an arithmetic value, a std::string or a container/array
         static_assert((std::is_arithmetic<Scalar>::value || std::is_enum<Scalar>::value ||
         ^~~~~~~~~~~~~

The second error confuses me, How can I achieve my purpose? thanks

@xuedj xuedj changed the title Dose HighFive support struct? Dose create_compound support string or vector? Aug 6, 2022
@xuedj xuedj closed this as completed Aug 11, 2022
@xuedj
Copy link
Author

xuedj commented Aug 11, 2022

already solved

@TITAINc
Copy link

TITAINc commented Oct 13, 2022

Hi@xuedj , I have encountered the same problem as you. How did you solve it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants