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

Reviewing Getter and Setter #303

Open
furudbat opened this issue Mar 3, 2024 · 1 comment
Open

Reviewing Getter and Setter #303

furudbat opened this issue Mar 3, 2024 · 1 comment

Comments

@furudbat
Copy link
Contributor

furudbat commented Mar 3, 2024

While rewriting the code for my own proposes, I encounter that everything can be get and set, at first this not bad, but doesn't make always sense, for example: all the owning pointers or resources with depending member like width and height in Image.
Maybe we can prevent the user from setting depended members or changing pointer to leak memory/ownership.
What happens when someone tempers with SetMaterialCount in Model but didn't update Materials.

For example, Image:

    CONST_GETTER(void*, Data, data)
    GETTER(int, Width, width)
    GETTER(int, Height, height)
    GETTER(int, Mipmaps, mipmaps)
    GETTER(int, Format, format)

So the Image can only been loaded or manipulated with operations like Format.

Not sure about something like Texture, is resetting the id ok (?) Only set the id via Load or from ::Texture (?)

There is also the possibility for using something like std::span for arrays.

    /// Model
    GETTERSETTER(int, MeshCount, meshCount)
    GETTERSETTER(int, MaterialCount, materialCount)
    SPAN_GETTER(::Mesh, Meshes, meshes, meshCount)
    SPAN_GETTER(::Material, Materials, materials, materialCount)   ///< std::span{materials, materialCount}

    /// AutomationEventList
    GETTERSETTER(unsigned int, Capacity, capacity)
    GETTERSETTER(unsigned int, Count, count)
    SPAN_GETTER(AutomationEvent, Events, events, capacity)

While the classes still can been converted to (C) raylib structs and "loaded" from raylibs structs, the wrapper interface itself can been a little bit more robust, and if someone really want to tamper with the data, it still can been done via (explicit) casting. or using the public members. (I personally thinking about, using composition for the classes and explicit casting, so the data is no more public)

@furudbat furudbat changed the title Reviewing Getter ernd Setter Reviewing Getter and Setter Mar 3, 2024
@RobLoach
Copy link
Owner

RobLoach commented Mar 3, 2024

Good ideas. I agree some things should not be actually set

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