-
Notifications
You must be signed in to change notification settings - Fork 633
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
[wpilibNewCommands] Add get subsystem list function from CommandScheduler #7835
base: main
Are you sure you want to change the base?
Conversation
This PR modifies commands. Please open a corresponding PR in Python Commands and include a link to this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the intent to do a copy or return an object that is a readonly view? (Does the below work?)
Set<Subsystem> subsystems = CommandScheduler.getInstance().getAllRegisteredSubsystems();
Subsystem mySubsystem = new Subsystem() {};
CommandScheduler.getInstance.registerSubsystem(mySubsystem);
assertTrue(subsystems.contains(mySubsystem));
As it is right now, Java is a readonly view (the code snippet above will pass) while C++ is a copy (the C++ version of the above will not pass).
See #6475 for discussion of this feature and #6526 for the troubles encountered a year ago in getting the readonly view to work in C++.
robotpycommands2 pr: robotpy/robotpy-commands-v2#86 |
Ideally it will be a readonly view in c++, as that makes the most sense but might have to make both copies if it turns out that we can't get the readonly view to compile in cpp |
sorry for inactivity, have some time now, just letting you know so this doesn't get closed |
Is UnmodifiableSet ordered like .keySet? The return value should be ordered |
Unfortunately it's looking like std::ranges::keys_view is incompatible with DenseMap, so there's either the option of writing some sort of backend to support it(which will likely be pretty inefficient), or returning a copy and changing java to do the same. I'm getting this output trying to build: https://gist.github.com/OhmV-IR/42e21bf0b6de95cc59cbcaabb4ff4e93 |
I changed java to also return a copy instead of a read-only view |
In java, the subsystems are returned as an immutable set and in c++ they are returned as a const vector. No tests for these as there isn't testing framework to create mock subsystems in wpilibNewCommands tests, at least not that I'm aware of.