mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[commands] Change C++ CommandPtr to use CommandBase (#4677)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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))));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user