Skip to content

Commit

Permalink
Standardized c++ and java usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel1464 committed Nov 7, 2024
1 parent 3d276de commit b5e15d3
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,10 @@ public WrapperCommand withName(String name) {
* one or more requirements with a command
* that will be added to it.
*
* @param parallelGroup The parallel group command.
* @param toAdd The command that will be added to the parallel group.
*/
protected void ensureDisjointRequirements(Command parallelGroup, Command toAdd) {
var sharedRequirements = new HashSet<>(parallelGroup.getRequirements());
protected void ensureDisjointRequirements(Command toAdd) {
var sharedRequirements = new HashSet<>(getRequirements());
sharedRequirements.retainAll(toAdd.getRequirements());
if (!sharedRequirements.isEmpty()) {
StringBuilder sharedRequirementsStr = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public final void addCommands(Command... commands) {
CommandScheduler.getInstance().registerComposedCommands(commands);

for (Command command : commands) {
Commands.ensureDisjointRequirements(this, command);
ensureDisjointRequirements(command);
m_commands.put(command, false);
addRequirements(command.getRequirements());
m_runWhenDisabled &= command.runsWhenDisabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public final void addCommands(Command... commands) {
CommandScheduler.getInstance().registerComposedCommands(commands);

for (Command command : commands) {
Commands.ensureDisjointRequirements(this, command);
ensureDisjointRequirements(command);
m_commands.put(command, false);
addRequirements(command.getRequirements());
m_runWhenDisabled &= command.runsWhenDisabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public final void addCommands(Command... commands) {
CommandScheduler.getInstance().registerComposedCommands(commands);

for (Command command : commands) {
Commands.ensureDisjointRequirements(this, command);
ensureDisjointRequirements(command);
m_commands.add(command);
addRequirements(command.getRequirements());
m_runWhenDisabled &= command.runsWhenDisabled();
Expand Down
17 changes: 7 additions & 10 deletions wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ void Command::InitSendable(wpi::SendableBuilder& builder) {
"runsWhenDisabled", [this] { return RunsWhenDisabled(); }, nullptr);
}

namespace frc2 {

void EnsureDisjointRequirements(Command* parallelGroup, Command* toAdd) {
void EnsureDisjointRequirements(Command* toAdd) {
std::string sharedRequirementsStr = "";
bool hasSharedRequirements = false;
auto&& requirementsToAdd = toAdd->GetRequirements();
Expand All @@ -236,12 +234,11 @@ void EnsureDisjointRequirements(Command* parallelGroup, Command* toAdd) {
}
if (hasSharedRequirements) {
throw FRC_MakeError(
frc::err::CommandIllegalUse,
"Command {} could not be added to this parallel group"
" because the subsystems [{}] are already required in this command."
" Multiple commands in a parallel composition cannot require the "
"same subsystems.",
toAdd->GetName(), sharedRequirementsStr);
frc::err::CommandIllegalUse,
"Command {} could not be added to this Parallel Group"
" because the subsystems [{}] are already required in this command."
" Multiple commands in a parallel composition cannot require the "
"same subsystems.",
command->GetName(), sharedRequirementsStr);
}
}
} // namespace frc2
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void ParallelCommandGroup::AddCommands(
}

for (auto&& command : commands) {
EnsureDisjointRequirements(this, command.get());
EnsureDisjointRequirements(command.get());
command->SetComposed(true);
AddRequirements(command->GetRequirements());
m_runWhenDisabled &= command->RunsWhenDisabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void ParallelDeadlineGroup::AddCommands(
}

for (auto&& command : commands) {
EnsureDisjointRequirements(this, command.get());
EnsureDisjointRequirements(command.get());
command->SetComposed(true);
AddRequirements(command->GetRequirements());
m_runWhenDisabled &= command->RunsWhenDisabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void ParallelRaceGroup::AddCommands(
}

for (auto&& command : commands) {
EnsureDisjointRequirements(this, command.get());
EnsureDisjointRequirements(command.get());
command->SetComposed(true);
AddRequirements(command->GetRequirements());
m_runWhenDisabled &= command->RunsWhenDisabled();
Expand Down
21 changes: 10 additions & 11 deletions wpilibNewCommands/src/main/native/include/frc2/command/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,20 +485,19 @@ class Command : public wpi::Sendable, public wpi::SendableHelper<Command> {
protected:
Command();

/**
* Throws an error if a parallel group already shares
* one or more requirements with a command
* that will be added to it.
*
* @param parallelGroup The parallel group command.
* @param toAdd The command that will be added to the parallel group.
*/
void EnsureDisjointRequirements(Command* toAdd);

private:
/// Requirements set.
wpi::SmallSet<Subsystem*, 4> m_requirements;

std::optional<std::string> m_previousComposition;
};

/**
* Throws an error if a parallel group already shares
* one or more requirements with a command
* that will be added to it.
*
* @param parallelGroup The parallel group command.
* @param toAdd The command that will be added to the parallel group.
*/
void EnsureDisjointRequirements(Command* parallelGroup, Command* toAdd);
} // namespace frc2

0 comments on commit b5e15d3

Please sign in to comment.