From edbd6816829f50da6ebd3f5835725de4f1a98a7d Mon Sep 17 00:00:00 2001 From: Starlight220 <53231611+Starlight220@users.noreply.github.com> Date: Tue, 10 Jan 2023 12:34:26 +0200 Subject: [PATCH 1/4] reword --- .../src/main/native/cpp/frc2/command/CommandScheduler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp index 5a4782f594f..678b2b1ec88 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp @@ -435,7 +435,8 @@ void CommandScheduler::RequireUngrouped(const Command* command) { if (command->IsComposed()) { throw FRC_MakeError( frc::err::CommandIllegalUse, - "Commands cannot be added to more than one CommandGroup"); + "Commands that have been composed may not be added to another composition or scheduled" + "individually!"); } } From 48cff964dece0ca7976ecbb9994965e886e244c6 Mon Sep 17 00:00:00 2001 From: Starlight220 <53231611+Starlight220@users.noreply.github.com> Date: Tue, 10 Jan 2023 15:12:06 +0200 Subject: [PATCH 2/4] delete rvalue methods --- .../native/cpp/frc2/command/CommandPtr.cpp | 12 ++++---- .../native/include/frc2/command/CommandPtr.h | 30 +++++++++++++++---- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index 44150a297cb..c6531c4fad7 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -226,7 +226,7 @@ CommandPtr CommandPtr::WithName(std::string_view name) && { return std::move(wrapper).ToPtr(); } -CommandBase* CommandPtr::get() const { +CommandBase* CommandPtr::get() const & { AssertValid(); return m_ptr.get(); } @@ -236,27 +236,27 @@ std::unique_ptr CommandPtr::Unwrap() && { return std::move(m_ptr); } -void CommandPtr::Schedule() const { +void CommandPtr::Schedule() const & { AssertValid(); CommandScheduler::GetInstance().Schedule(*this); } -void CommandPtr::Cancel() const { +void CommandPtr::Cancel() const & { AssertValid(); CommandScheduler::GetInstance().Cancel(*this); } -bool CommandPtr::IsScheduled() const { +bool CommandPtr::IsScheduled() const & { AssertValid(); return CommandScheduler::GetInstance().IsScheduled(*this); } -bool CommandPtr::HasRequirement(Subsystem* requirement) const { +bool CommandPtr::HasRequirement(Subsystem* requirement) const & { AssertValid(); return m_ptr->HasRequirement(requirement); } -CommandPtr::operator bool() const { +CommandPtr::operator bool() const & { return m_ptr.operator bool(); } diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h index 0ab1e97186c..fa0cee457be 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h @@ -232,7 +232,10 @@ class CommandPtr final { /** * Get a raw pointer to the held command. */ - CommandBase* get() const; + CommandBase* get() const &; + + // Prevent calls on a temporary, as the returned pointer would be invalid + CommandBase* get() && = delete; /** * Convert to the underlying unique_ptr. @@ -242,13 +245,19 @@ class CommandPtr final { /** * Schedules this command. */ - void Schedule() const; + void Schedule() const &; + + // Prevent calls on a temporary, as the returned pointer would be invalid + void Schedule() && = delete; /** * Cancels this command. Will call End(true). Commands will be canceled * regardless of interruption behavior. */ - void Cancel() const; + void Cancel() const &; + + // Prevent calls on a temporary, as the returned pointer would be invalid + void Cancel() && = delete; /** * Whether or not the command is currently scheduled. Note that this does not @@ -257,7 +266,10 @@ class CommandPtr final { * * @return Whether the command is scheduled. */ - bool IsScheduled() const; + bool IsScheduled() const &; + + // Prevent calls on a temporary, as the returned pointer would be invalid + void IsScheduled() && = delete; /** * Whether the command requires a given subsystem. Named "HasRequirement" @@ -267,12 +279,18 @@ class CommandPtr final { * @param requirement the subsystem to inquire about * @return whether the subsystem is required */ - bool HasRequirement(Subsystem* requirement) const; + bool HasRequirement(Subsystem* requirement) const &; + + // Prevent calls on a temporary, as the returned pointer would be invalid + void HasRequirement(Subsystem* requirement) && = delete; /** * Check if this CommandPtr object is valid and wasn't moved-from. */ - explicit operator bool() const; + explicit operator bool() const &; + + // Prevent calls on a temporary, as the returned pointer would be invalid + explicit operator bool() && = delete; /** * Convert a vector of CommandPtr objects to their underlying unique_ptrs. From a04670944411bc598a41fa2a80c719dbfff453dd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 10 Jan 2023 14:30:30 +0000 Subject: [PATCH 3/4] Formatting fixes --- .../src/main/native/cpp/frc2/command/CommandPtr.cpp | 12 ++++++------ .../native/cpp/frc2/command/CommandScheduler.cpp | 8 ++++---- .../main/native/include/frc2/command/CommandPtr.h | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index c6531c4fad7..1bb8bf0815f 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -226,7 +226,7 @@ CommandPtr CommandPtr::WithName(std::string_view name) && { return std::move(wrapper).ToPtr(); } -CommandBase* CommandPtr::get() const & { +CommandBase* CommandPtr::get() const& { AssertValid(); return m_ptr.get(); } @@ -236,27 +236,27 @@ std::unique_ptr CommandPtr::Unwrap() && { return std::move(m_ptr); } -void CommandPtr::Schedule() const & { +void CommandPtr::Schedule() const& { AssertValid(); CommandScheduler::GetInstance().Schedule(*this); } -void CommandPtr::Cancel() const & { +void CommandPtr::Cancel() const& { AssertValid(); CommandScheduler::GetInstance().Cancel(*this); } -bool CommandPtr::IsScheduled() const & { +bool CommandPtr::IsScheduled() const& { AssertValid(); return CommandScheduler::GetInstance().IsScheduled(*this); } -bool CommandPtr::HasRequirement(Subsystem* requirement) const & { +bool CommandPtr::HasRequirement(Subsystem* requirement) const& { AssertValid(); return m_ptr->HasRequirement(requirement); } -CommandPtr::operator bool() const & { +CommandPtr::operator bool() const& { return m_ptr.operator bool(); } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp index 678b2b1ec88..b5b616443ca 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp @@ -433,10 +433,10 @@ void CommandScheduler::OnCommandFinish(Action action) { void CommandScheduler::RequireUngrouped(const Command* command) { if (command->IsComposed()) { - throw FRC_MakeError( - frc::err::CommandIllegalUse, - "Commands that have been composed may not be added to another composition or scheduled" - "individually!"); + throw FRC_MakeError(frc::err::CommandIllegalUse, + "Commands that have been composed may not be added to " + "another composition or scheduled" + "individually!"); } } diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h index fa0cee457be..cc61106b780 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h @@ -232,7 +232,7 @@ class CommandPtr final { /** * Get a raw pointer to the held command. */ - CommandBase* get() const &; + CommandBase* get() const&; // Prevent calls on a temporary, as the returned pointer would be invalid CommandBase* get() && = delete; @@ -245,7 +245,7 @@ class CommandPtr final { /** * Schedules this command. */ - void Schedule() const &; + void Schedule() const&; // Prevent calls on a temporary, as the returned pointer would be invalid void Schedule() && = delete; @@ -254,7 +254,7 @@ class CommandPtr final { * Cancels this command. Will call End(true). Commands will be canceled * regardless of interruption behavior. */ - void Cancel() const &; + void Cancel() const&; // Prevent calls on a temporary, as the returned pointer would be invalid void Cancel() && = delete; @@ -266,7 +266,7 @@ class CommandPtr final { * * @return Whether the command is scheduled. */ - bool IsScheduled() const &; + bool IsScheduled() const&; // Prevent calls on a temporary, as the returned pointer would be invalid void IsScheduled() && = delete; @@ -279,7 +279,7 @@ class CommandPtr final { * @param requirement the subsystem to inquire about * @return whether the subsystem is required */ - bool HasRequirement(Subsystem* requirement) const &; + bool HasRequirement(Subsystem* requirement) const&; // Prevent calls on a temporary, as the returned pointer would be invalid void HasRequirement(Subsystem* requirement) && = delete; @@ -287,7 +287,7 @@ class CommandPtr final { /** * Check if this CommandPtr object is valid and wasn't moved-from. */ - explicit operator bool() const &; + explicit operator bool() const&; // Prevent calls on a temporary, as the returned pointer would be invalid explicit operator bool() && = delete; From c10b6de391663fd83ddc2c8dce7eab4efa94e2d2 Mon Sep 17 00:00:00 2001 From: Starlight220 <53231611+Starlight220@users.noreply.github.com> Date: Tue, 10 Jan 2023 23:32:42 +0200 Subject: [PATCH 4/4] Update wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp Co-authored-by: Ryan Blue --- .../src/main/native/cpp/frc2/command/CommandScheduler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp index b5b616443ca..70443f497d0 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp @@ -435,7 +435,7 @@ void CommandScheduler::RequireUngrouped(const Command* command) { if (command->IsComposed()) { throw FRC_MakeError(frc::err::CommandIllegalUse, "Commands that have been composed may not be added to " - "another composition or scheduled" + "another composition or scheduled " "individually!"); } }