Skip to content

Use inheritance to remove This data member#347

Merged
ChrisThrasher merged 1 commit intomasterfrom
remove_This
Sep 24, 2024
Merged

Use inheritance to remove This data member#347
ChrisThrasher merged 1 commit intomasterfrom
remove_This

Conversation

@ChrisThrasher
Copy link
Copy Markdown
Member

@ChrisThrasher ChrisThrasher commented Sep 20, 2024

Closes #222

It's reasonable to say that, for example, sfImage is an sf::Image. This "is-a" relationship is what inheritance does a very good job modeling. By using inheritance to implement CSFML types in terms of their SFML counterpart, we get code that is simpler and easier to read.

@ChrisThrasher ChrisThrasher added this to the 3.0 milestone Sep 20, 2024
@ChrisThrasher ChrisThrasher marked this pull request as ready for review September 21, 2024 18:37
Copy link
Copy Markdown
Contributor

@ZXShady ZXShady left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unnecessary ternary and static cast

@ChrisThrasher ChrisThrasher force-pushed the remove_This branch 2 times, most recently from 9f12818 to 960142f Compare September 22, 2024 01:18
Copy link
Copy Markdown
Contributor

@ZXShady ZXShady left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readd assert and remove unnecessary static_cast and ternary

@ChrisThrasher ChrisThrasher force-pushed the remove_This branch 2 times, most recently from 0a60a3d to 600f98d Compare September 23, 2024 05:01
@eXpl0it3r
Copy link
Copy Markdown
Member

Could this cause issues from pure C side or a binding using CSFML? We're only returning pointers and have typedefs, but now the fundamental type is no longer just a simple struct 🤔

@ZXShady
Copy link
Copy Markdown
Contributor

ZXShady commented Sep 23, 2024

the type was never a simple struct to begin with the sf Classes had non standard layout types inside it. and the typedef is to make the pointer opaque.

the user has no knowledge of what the pointer is

@ChrisThrasher
Copy link
Copy Markdown
Member Author

Could this cause issues from pure C side or a binding using CSFML? We're only returning pointers and have typedefs, but now the fundamental type is no longer just a simple struct 🤔

Notice how this PR only touches the src/ directory. Users have no way to observe structs that are defined in src/. They can only see the definition of structs defined in include/. This is the reason we use opaque pointers in the interface. It gives us full freedom to implement these structs however we like.

@ChrisThrasher ChrisThrasher force-pushed the remove_This branch 2 times, most recently from 6f4649d to 9b8a498 Compare September 23, 2024 20:32
@eXpl0it3r
Copy link
Copy Markdown
Member

I get that, I was just wondering if there's any limit to that. We now had opaque pointers to structs, but now it's a derived type. Can this have any side effect from a C/binding point of view?

@ChrisThrasher
Copy link
Copy Markdown
Member Author

No, there’s no way for users to notice anything has changed.

It's reasonable to say that, for example, sfImage _is_ an sf::Image.
This "is-a" relationship is what inheritance does a very good job
modeling. By using inheritance to implement CSFML types in terms of
their SFML counterpart, we get code that is simpler and easier to
read. We also avoid some of the extra "dancing" required to construct
a CSFML type from an SFML type. This improves the encapsulation of
our CSFML implementation.
@ChrisThrasher ChrisThrasher merged commit 7b583b1 into master Sep 24, 2024
@ChrisThrasher ChrisThrasher deleted the remove_This branch September 24, 2024 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use inheritance to implement wrapper struct types

3 participants