Skip to content

Commit

Permalink
Add registerCommand overload that takes a CommandPtr (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansen4857 authored Oct 9, 2023
1 parent a9e8b76 commit 507b9b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
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

0 comments on commit 507b9b5

Please sign in to comment.