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

Investigate about the possibility to make the BufferMananger manage different data types #76

Open
Nicogene opened this issue Feb 15, 2021 · 10 comments
Labels
enhancement New feature or request

Comments

@Nicogene
Copy link
Member

At this moment the BufferManager is a template class, then it can handle only one type of data.
It would be nice if we can implement only template functions(maybe moving them outside the class) in order to make it possible to handle different data types with just one BufferManager(maybe it would become a singleton?)

@Nicogene Nicogene added the enhancement New feature or request label Feb 15, 2021
@Nicogene
Copy link
Member Author

This goes in #34 direction

@S-Dafarra
Copy link
Collaborator

During a meeting we had with @traversaro @GiulioRomualdi @AlexAntn and @Nicogene, we thought that it might be indeed interesting to have this fixed. The main reasons are:

  • the possibility to store and synchronize different types of data:
    • double
    • int
    • strings
  • remove the template from the BufferManager class.

One possibility would be to use https://en.cppreference.com/w/cpp/utility/any or https://en.cppreference.com/w/cpp/utility/variant

@S-Dafarra
Copy link
Collaborator

S-Dafarra commented Jan 10, 2022

I just figured that rather than using variant/any up to Record we can edit this line
https://github.com/robotology/yarp-telemetry/blob/0646ef0d6c099b5a3c6291a0f7d535c46a7462e8/src/libYARP_telemetry/src/yarp/telemetry/experimental/BufferManager.h#L594
into

std::shared_ptr<TreeNode<std::any>> m_tree;

if possible. Then, std::any could be BufferInfo<double>, BufferInfo<int>, BufferInfo<sd::string>, ...

In this way, the modifications remain limited to the BufferManager class only.

@Nicogene
Copy link
Member Author

I would prefer using variant instead of any, this post resume why it is better and safer https://stackoverflow.com/questions/56303939/c-stdvariant-vs-stdany

@S-Dafarra
Copy link
Collaborator

The types supported by matioCpp are those listed in https://github.com/ami-iit/matio-cpp/blob/d8a450ea7c3289ca78ea5111aea0f451a8b19b74/include/matioCpp/ConversionUtilities.h#L50-L62. To this list, we can add std::string that is automatically turned into a vector of chars (see https://github.com/ami-iit/matio-cpp/blob/d8a450ea7c3289ca78ea5111aea0f451a8b19b74/include/matioCpp/ForwardDeclarations.h#L192)

@S-Dafarra
Copy link
Collaborator

In the direction of being compatible with different data types, a possibility could be also to store videos. I suppose the type of the channel, in this case, could be some sort of image (or even a char array). Related issue #155

@S-Dafarra
Copy link
Collaborator

I am currently working on this in https://github.com/S-Dafarra/yarp-telemetry/tree/multiple_types

In the end, I opted for std::any. The main reason is that with ami-iit/matio-cpp#55 we can convert generic structs to matioCpp::Structs. Hence, I cannot know a prior all the types that we could store.

@S-Dafarra
Copy link
Collaborator

Corresponding PR: #168

@traversaro
Copy link
Member

Not sure if it can be relevant (and even if it is, we can totally go for std::any for now): https://github.com/stephane-caron/palimpsest . See also section https://github.com/stephane-caron/palimpsest#alternatives .

@S-Dafarra
Copy link
Collaborator

Not sure if it can be relevant (and even if it is, we can totally go for std::any for now): https://github.com/stephane-caron/palimpsest . See also section https://github.com/stephane-caron/palimpsest#alternatives .

Interesting! If I understood correctly, it is more like a container that can hold different types. In some sense, it is more comparable to matioCpp::Struct than std::any. It could have been useful to store Buffers templated with different types, while in #168 I worked it around by removing the use of templates from Buffer.

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

No branches or pull requests

3 participants