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

[cpp cmd] Fix leakage and multiple composition bug in SelectCommand #5571

Merged
merged 4 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class SelectCommand extends Command {
private boolean m_runsWhenDisabled = true;
private InterruptionBehavior m_interruptBehavior = InterruptionBehavior.kCancelIncoming;

private final Command m_defaultCommand =
new PrintCommand("SelectCommand selector value does not correspond to any command!");

/**
* Creates a new SelectCommand.
*
Expand All @@ -52,8 +55,7 @@ public SelectCommand(Map<Object, Command> commands, Supplier<Object> selector) {
@Override
public void initialize() {
if (!m_commands.containsKey(m_selector.get())) {
m_selectedCommand =
new PrintCommand("SelectCommand selector value does not correspond to any command!");
m_selectedCommand = m_defaultCommand;
} else {
m_selectedCommand = m_commands.get(m_selector.get());
rzblue marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,16 @@ class SelectCommand : public CommandHelper<Command, SelectCommand<Key>> {
bool m_runsWhenDisabled = true;
Command::InterruptionBehavior m_interruptBehavior{
Command::InterruptionBehavior::kCancelIncoming};

PrintCommand m_defaultCommand{
"SelectCommand selector value does not correspond to any command!"};
};

template <typename T>
void SelectCommand<T>::Initialize() {
auto find = m_commands.find(m_selector());
if (find == m_commands.end()) {
m_selectedCommand = new PrintCommand(
"SelectCommand selector value does not correspond to any command!");
m_selectedCommand = &m_defaultCommand;
} else {
m_selectedCommand = find->second.get();
}
Expand Down