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

Template return-type functions for reading data? #216

Open
martukas opened this issue Jan 27, 2018 · 8 comments
Open

Template return-type functions for reading data? #216

martukas opened this issue Jan 27, 2018 · 8 comments
Assignees
Milestone

Comments

@martukas
Copy link
Collaborator

Could we have instead of:

uint32_t v = 0;
attr.read(v);

this:

auto v = attr.read<uint32_t>();

Just an idea

@martukas martukas added this to the Version 0.0.5 milestone Jan 27, 2018
@martukas
Copy link
Collaborator Author

Here is another example of boilerplate that could potentially be a one-liner

      auto ds_event_time_zero
          = hdf5::node::get_dataset(root_group, group_path + "/event_time_zero");
      vector<uint64_t> event_time_zero(ds_event_time_zero.dataspace().size());
      ds_event_time_zero.read(event_time_zero);

Yes, it's not as efficient as allocating everything at the beginning of the universe, but reality dictates many such situations as, for example, the above being from some unit tests that validate small datasets.

@eugenwintersberger
Copy link
Collaborator

eugenwintersberger commented Jan 29, 2018

We definitely should have something like this and it is already planned. What we have to do for that purpose is to refacture the type trait framework we currently use for IO. What we would need in particular is a type trait that tells the library how to create an instance of a particular type.
Something like this

template<typename T> class FactoryTrait
{
  public:
    static T create(const hdf5::dataspace::Dataspace &space,
                            const hdf5::datatype::Datatype &type); 
}

With this in our arsenal it would be rather straight forward to do things like the above.

I have a very rough design in mind which would do the job. But it still requires some rethinking. I hope I can put a draft online for discussion this week.

@martukas
Copy link
Collaborator Author

martukas commented May 7, 2018

I have attempted to do something like

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

but this only works for scalar values, not vectors, as it needs to resize them before writing. Any idea how to do this so it would work for both? Would this FactoryTrait really help?

@martukas martukas modified the milestones: Version 0.0.7, Version 0.0.8 May 9, 2018
@martukas martukas modified the milestones: Version 0.0.8, Version 0.1.0 Jun 27, 2018
@eugenwintersberger eugenwintersberger self-assigned this Jul 28, 2018
@martukas martukas modified the milestones: Version 0.1.0, Version 0.2.0 Oct 15, 2018
@eugenwintersberger
Copy link
Collaborator

As for the discusion with Jan on #379 the first step to make this happen is to add the following static member to the dataspace trait

namespace hdf5 {
namespace dataspace {
template<typename T> class TypeTrait<T>

  public:
    // create a new instance of T according to dataspace
    static T allocate(const Dataspace &dataspace) 
    {

    }
};
}
}

@martukas martukas modified the milestones: Version 0.2.0, Version 0.3.0 Mar 23, 2019
@jkotan jkotan modified the milestones: Version 0.3.0, Vesion 0.4.0 Dec 10, 2019
@jkotan jkotan modified the milestones: Vesion 0.4.0, Version 0.5.0 Dec 21, 2020
@zjttoefs
Copy link
Contributor

zjttoefs commented Jun 2, 2021

There is a fairly stale branch for this issue: https://github.com/ess-dmsc/h5cpp/tree/issue_280
Is this worth preserving?

@eugenwintersberger
Copy link
Collaborator

I do not see this branch and the link is dead. Is this something you still have around on your machine?

@zjttoefs
Copy link
Contributor

zjttoefs commented Jun 3, 2021

Sorry, I must have pasted the wrong link. I deleted the branch for the closed ticket #280 that had nothing that isn't in master. Nothing to do with this one.

The branch for this ticket is https://github.com/ess-dmsc/h5cpp/tree/issue_216
Just adds this: https://github.com/ess-dmsc/h5cpp/compare/issue_216

@eugenwintersberger
Copy link
Collaborator

This branch can be definitely removed. No objections on that. But we should leave this ticket open.

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

No branches or pull requests

4 participants