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

Added support of (smart) pointers as members and added support for "T& getter()" getters #166

Merged
merged 7 commits into from
Jan 19, 2021

Conversation

Omegapol
Copy link
Contributor

Added support of (smart) pointers as members and added "T& getter()" getters.

Newly supported member types:

  • T*
  • SharedPtr

Getters supported (not limited to, might be more I didn't think of/test):

  • T& getter();
  • T* getter();
  • const T* getter();
  • T* getter() const;
  • const T* getter() const;
  • SharedPtr getter();
  • getter() const;

@mikke89
Copy link
Owner

mikke89 commented Jan 14, 2021

First of all, thanks a lot for the PR, it's very much appreciated. I love the fact that we can retrieve generic types from getters, and also follow (smart) pointers. I'm certain it will be very helpful for many users.

There also seems to be some limitations here if I understand it properly. Currently, pointers do not automatically work within Arrays and Scalars. To make them work we would have to add special support for each of them. We should also add support for unique_ptr. I'm also thinking about custom pointer-like types that users may want to use. While most of these limitations can be worked out, I'm a bit worried that the code complexity will rise to levels I'm not comfortable with.

What I'm thinking about now is that we add some mapping/pointer wrapper which can be registered, whose sole purpose is to dereference whatever gets passed to it. Internally, we should provide support for raw pointers, shared pointers, and unique pointers. If that works out as intended, then they will automatically be available for Scalars, Arrays and Structs without any special support. Hopefully.

I have previously been playing around with implementing getter and setter functions for types instead of variables, which would fit nicely into this. With these changes, we should be able to remove the RegisterMemberFunc and BindFunc functions.

Anyway, what you have here is a great start. I think I want to play with it on a separate branch for now, and see if I can work out something I like. Or it might not work out, and we'll instead continue along this approach and extend it to other cases and clean up the interface a bit.

@mikke89 mikke89 added enhancement New feature or request data binding labels Jan 14, 2021
@mikke89 mikke89 changed the base branch from master to databinding_pointers January 14, 2021 23:38
@Omegapol
Copy link
Contributor Author

Omegapol commented Jan 15, 2021

Currently, pointers do not automatically work within Arrays and Scalars.

I get the Arrays part, but what do you mean by mentioning Scalars? You can have pointers to scalars and they will work automatically with my changes :)

@mikke89
Copy link
Owner

mikke89 commented Jan 15, 2021

Not right now, but that's how I'd like it to work yes :)

@Omegapol
Copy link
Contributor Author

Hey Mike,
I've been thinking about what you said, about having those pointers wrapped in something.
I did few additional changes and also added support for arrays of pointers and registration of pointers/smart_ptr/unique_ptr/(or anything that implements get() and returns a raw pointer)
https://github.com/Omegapol/RmlUi/commits/wrapped_pointers
I added those changes on seperate branch because this is a little bit different approach than originally, I'll move it here if you think that I should.

@mikke89
Copy link
Owner

mikke89 commented Jan 16, 2021

Very cool! That is very close to what I was thinking about. It would be nice if you could merge it in here.

I haven't had time to work on this myself yet, but I'm happy to have this to start with, thanks a lot!

@mikke89 mikke89 merged commit f14a5a9 into mikke89:databinding_pointers Jan 19, 2021
@mikke89
Copy link
Owner

mikke89 commented Jan 19, 2021

Thank you!

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

Successfully merging this pull request may close these issues.

2 participants