[commands] Change C++ CommandPtr to use CommandBase (#4677)

This commit is contained in:
Starlight220
2022-11-21 19:45:50 +02:00
committed by GitHub
parent 98e922313b
commit 0bee875aff
5 changed files with 27 additions and 29 deletions

View File

@@ -345,6 +345,12 @@ safe) semantics.
virtual std::string GetName() const;
/**
* Transfers ownership of this command to a unique pointer. Used for
* decorator methods.
*/
virtual CommandPtr ToPtr() && = 0;
protected:
/**
* Transfers ownership of this command to a unique pointer. Used for

View File

@@ -29,7 +29,7 @@ class CommandHelper : public Base {
public:
CommandHelper() = default;
CommandPtr ToPtr() && {
CommandPtr ToPtr() && override {
return CommandPtr(
std::make_unique<CRTP>(std::move(*static_cast<CRTP*>(this))));
}

View File

@@ -11,7 +11,7 @@
#include <utility>
#include <vector>
#include "frc2/command/Command.h"
#include "frc2/command/CommandBase.h"
namespace frc2 {
/**
@@ -26,7 +26,7 @@ namespace frc2 {
*/
class CommandPtr final {
public:
explicit CommandPtr(std::unique_ptr<Command>&& command)
explicit CommandPtr(std::unique_ptr<CommandBase>&& command)
: m_ptr(std::move(command)) {}
template <class T, typename = std::enable_if_t<std::is_base_of_v<
@@ -222,12 +222,12 @@ class CommandPtr final {
/**
* Get a raw pointer to the held command.
*/
Command* get() const;
CommandBase* get() const;
/**
* Convert to the underlying unique_ptr.
*/
std::unique_ptr<Command> Unwrap() &&;
std::unique_ptr<CommandBase> Unwrap() &&;
/**
* Schedules this command.
@@ -271,7 +271,7 @@ class CommandPtr final {
std::vector<CommandPtr>&& vec);
private:
std::unique_ptr<Command> m_ptr;
std::unique_ptr<CommandBase> m_ptr;
void AssertValid() const;
};