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

Add registerCommand overload that takes a CommandPtr #390

Merged
Show file tree
Hide file tree
Changes from all 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 @@ -5,15 +5,6 @@ using namespace pathplanner;

std::unordered_map<std::string, std::shared_ptr<frc2::Command>> NamedCommands::namedCommands;

void NamedCommands::registerCommand(std::string name,
std::shared_ptr<frc2::Command> command) {
NamedCommands::namedCommands.emplace(name, command);
}

bool NamedCommands::hasCommand(std::string name) {
return NamedCommands::namedCommands.contains(name);
}

frc2::CommandPtr NamedCommands::getCommand(std::string name) {
if (NamedCommands::hasCommand(name)) {
return CommandUtil::wrappedEventCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,27 @@ class NamedCommands {
* @param name the name of the command
* @param command shared pointer to the command to register
*/
static void registerCommand(std::string name,
std::shared_ptr<frc2::Command> command);
static inline void registerCommand(std::string name,
std::shared_ptr<frc2::Command> command) {
NamedCommands::namedCommands.emplace(name, command);
}

static inline void registerCommand(std::string name,
frc2::CommandPtr &&command) {
registerCommand(name,
std::shared_ptr < frc2::Command
> (std::move(command).Unwrap()));
}

/**
* Returns whether a command with the given name has been registered.
*
* @param name the name of the command to check
* @return true if a command with the given name has been registered, false otherwise
*/
static bool hasCommand(std::string name);
static inline bool hasCommand(std::string name) {
return NamedCommands::namedCommands.contains(name);
}

/**
* Returns the command with the given name.
Expand Down