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

Feature request: implementation of the Scalar value for attribute #517

Open
menoret-allan opened this issue Jan 30, 2025 · 1 comment
Open

Comments

@menoret-allan
Copy link

Hello,

We have a feature request :)

We would like to have the possibility to choose between Array and Scalar value while adding an attribute.
I added a screenshot bellow to see the difference in the HDF viewer.

Image

I already have an semi-implementation which allows this behavior.
I had troubles with 4 types: bool, char, decimal and string:

  • bool, char, decimal are not supported or does not work when setting the right H5T parameter , we decided to throw an exception that those types are not supported.
  • string: it is working with ASCII but I did not manage to get it to work with UTF8

We made breaking changes on the API inside the PR:
Before:
WriteAttribute: it would take one argument and then set it into an array
ReadAttribute: it would read an array and return the first element
In the PR:
WriteAttribute: it would take one argument set the value as a Scalar value inside the HDF5 file
ReadAttribute: it would read a Scalar value inside the HDF5 and return this value.

We also created 2 overload in this PR one generic and one for string but we will change it to have just one method which accept generic without constraint then.

Since these changes are quite big breaking changes on the API level, we could also create new methods for example:

  • (int success, long createdId) WriteScalarAttribute<T>(long groupId, string name, T value)
  • T ReadScalarAttribute<T>(long groupId, string name) or (bool success, T value) ReadScalarAttribute<T>(long groupId, string name)

I created a draft PR just that you can check the changes and what we have done. The goal is not to merge this PR since there is quite some re-work to do there (tests, code duplication, comments...).
It also contains the translation from the tree structure that we get the right attribute, array or scalar.
Here's is the link to the PR:
#516

If you have any questions, concerned you can ping me or comment the PR ;)

Cheers !

@LiorBanai
Copy link
Owner

Thanks a lot. I'll take a look hopefully next week 👍

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