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

Redesign SDLEnums to not be objects #20

Closed
joeljfischer opened this issue Oct 29, 2014 · 5 comments
Closed

Redesign SDLEnums to not be objects #20

joeljfischer opened this issue Oct 29, 2014 · 5 comments
Labels
proposal Accepted SDL Evolution Proposal
Milestone

Comments

@joeljfischer
Copy link
Contributor

joeljfischer commented Oct 29, 2014

Lots of enum objects permanently in memory now, could do conversion between String Enum <–> Integer Enum instead. Less memory overhead, probably more CPU overhead, likely negligible. Removes an enormous amount of code.

Right now, Enums are designed as objects. From what I understand, there are a few reasons for this:

  1. Namespacing. You can type SDLAmbientLightStatus and get a list of the component enums.
  2. Typechecking. You can call the [valueOf:] method on an enum and get the object, or nil if it is not a component object.

See the comment below for more details.

Also, see #425, perhaps just typedef EnumName NSString and stringly typed constants?

@joeljfischer joeljfischer added proposal Accepted SDL Evolution Proposal epic labels Oct 29, 2014
@joeljfischer
Copy link
Contributor Author

I have come up with a (completely untested) possible method of doing this. See the following gist for an example.

https://gist.github.com/joeljfischer/67bd1d4da444e948cb5d

There are still objects here, each SDLEnum object holds a single (enforced by a singleton pattern) dictionary held in it's overridden +[map] method. This maps a enum value to a string. The superclass SDLEnum contains class methods that are capable of converting between the two. Enum -> String is a simple dictionary lookup in 0(1) time. String -> Enum is 0(n) time worst case. These two cases could be reversed if desired with no impact to developer facing API.

To the developer, all they ever need to deal with are the public enum values. This will help with enforcing correct values and will be very fast, since they're just integers. At runtime, when we need to, we'll convert back and forth for the protocol.

@GENIVI
Copy link

GENIVI commented Feb 2, 2015

hi, Joel

Thanks for your gist. I'll hold on them and try it tomorrow and keep you
updated.

Thanks
Yingang

@joeljfischer
Copy link
Contributor Author

Hey Yingang, I would not recommend trying to implement the ideas presented in the gist into the library at this point. To actually do so would require a lot of work and changes to many places in the library. Many/all enums would need to be altered to work in the manner described, and lower level changes to message creation and parsing would need to be implemented. The gist was intended strictly as a presentation of ideas for discussion for now.

@joeljfischer
Copy link
Contributor Author

Note that all NS_ENUMs could be moved to a separate public enum file, all +[map] methods could be moved into SDLEnum base class as separate methods, such as +[appHMITypeMap]. This would eliminate a crazy amount of classes, and allow the SDLEnum class to be private to the library, reducing public class exposure.

@joeljfischer joeljfischer added this to the 5.0.0 milestone Feb 19, 2015
@joeljfischer
Copy link
Contributor Author

Closed in favor of #425

davidswi pushed a commit to davidswi/sdl_ios that referenced this issue May 18, 2017
…L-872 to master

* commit '7dab7f4d8d51142e5705adf894e62965780142a0':
  Control session has to be stopped on main thread, not receive queue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Accepted SDL Evolution Proposal
Projects
None yet
Development

No branches or pull requests

1 participant