Skip to content

Commit

Permalink
auto read for scalar types; updates #216'
Browse files Browse the repository at this point in the history
  • Loading branch information
martukas committed May 7, 2018
1 parent 4f37dbf commit c8117c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/h5cpp/attribute/attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ class DLL_EXPORT Attribute
void write(const T& data,const datatype::Datatype &mem_type) const;
void write(const char *data,const datatype::Datatype &mem_type) const;

template<typename T>
T read() const
{
T ret;
read(ret);
return ret;
}

template<typename T>
void read(T &data) const;

Expand Down
12 changes: 12 additions & 0 deletions test/attribute/attribute_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ TEST_F(Attribute,test_create_from_vector)
EXPECT_EQ(buffer,data);
}

TEST_F(Attribute, read_auto)
{
auto a = root_.attributes.create_from("test",float(23.4));
auto ret = a.read<float>();
EXPECT_EQ(ret, 23.4f);

// using AttributeData = std::vector<double>;
// AttributeData data{1,2,3,4,5};
// auto b = root_.attributes.create_from("test2",data);
// auto ret_b = b.read<AttributeData>();
// EXPECT_EQ(ret_b, data);
}



0 comments on commit c8117c6

Please sign in to comment.