WPILibC++ 2023.4.3-108-ge5452e3
CommandHelper.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <concepts>
8#include <memory>
9#include <utility>
10
13
14namespace frc2 {
15
16/**
17 * CRTP implementation to allow polymorphic decorator functions in Command.
18 *
19 * <p>Note: ALWAYS create a subclass by extending CommandHelper<Base, Subclass>,
20 * or decorators will not function!
21 *
22 * This class is provided by the NewCommands VendorDep
23 */
24template <std::derived_from<Command> Base, typename CRTP>
25class CommandHelper : public Base {
26 using Base::Base;
27
28 public:
29 CommandHelper() = default;
30
31 CommandPtr ToPtr() && override {
32 return CommandPtr(
33 std::make_unique<CRTP>(std::move(*static_cast<CRTP*>(this))));
34 }
35
36 protected:
37 std::unique_ptr<Command> TransferOwnership() && override {
38 return std::make_unique<CRTP>(std::move(*static_cast<CRTP*>(this)));
39 }
40};
41} // namespace frc2
CRTP implementation to allow polymorphic decorator functions in Command.
Definition: CommandHelper.h:25
std::unique_ptr< Command > TransferOwnership() &&override
Definition: CommandHelper.h:37
CommandHelper()=default
CommandPtr ToPtr() &&override
Definition: CommandHelper.h:31
A wrapper around std::unique_ptr<Command> so commands have move-only semantics.
Definition: CommandPtr.h:29
Definition: ProfiledPIDCommand.h:18