1818using namespace frc2 ;
1919
2020Command::~Command () {
21- CommandScheduler::GetInstance ().Cancel (this );
21+ // CommandScheduler::GetInstance().Cancel(shared_from_this() );
2222}
2323
24- Command::Command (const Command& rhs) : ErrorBase(rhs) {}
24+ // Command::Command(const Command& rhs) : ErrorBase(rhs) {}
2525
26- Command& Command::operator =(const Command& rhs) {
27- ErrorBase::operator =(rhs);
28- m_isGrouped = false ;
29- return *this ;
30- }
26+ // Command& Command::operator=(const Command& rhs) {
27+ // ErrorBase::operator=(rhs);
28+ // m_isGrouped = false;
29+ // return *this;
30+ // }
3131
3232void Command::Initialize () {}
3333void Command::Execute () {}
3434void Command::End (bool interrupted) {}
3535
36- ParallelRaceGroup Command::WithTimeout (units::second_t duration) && {
37- std::vector<std::unique_ptr <Command>> temp;
38- temp.emplace_back (std::make_unique <WaitCommand>(duration));
39- temp.emplace_back (std::move (* this ). TransferOwnership ());
40- return ParallelRaceGroup (std::move (temp));
36+ std::shared_ptr< ParallelRaceGroup> Command::WithTimeout (units::second_t duration) {
37+ std::vector<std::shared_ptr <Command>> temp;
38+ temp.emplace_back (std::make_shared <WaitCommand>(duration));
39+ temp.emplace_back (shared_from_this ());
40+ return std::make_shared< ParallelRaceGroup> (std::move (temp));
4141}
4242
43- ParallelRaceGroup Command::WithInterrupt (std::function<bool ()> condition) && {
44- std::vector<std::unique_ptr <Command>> temp;
45- temp.emplace_back (std::make_unique <WaitUntilCommand>(std::move (condition)));
46- temp.emplace_back (std::move (* this ). TransferOwnership ());
47- return ParallelRaceGroup (std::move (temp));
43+ std::shared_ptr< ParallelRaceGroup> Command::WithInterrupt (std::function<bool ()> condition) {
44+ std::vector<std::shared_ptr <Command>> temp;
45+ temp.emplace_back (std::make_shared <WaitUntilCommand>(std::move (condition)));
46+ temp.emplace_back (shared_from_this ());
47+ return std::make_shared< ParallelRaceGroup> (std::move (temp));
4848}
4949
50- SequentialCommandGroup Command::BeforeStarting (
50+ std::shared_ptr< SequentialCommandGroup> Command::BeforeStarting (
5151 std::function<void ()> toRun,
52- std::initializer_list<Subsystem*> requirements) && {
53- return std::move (* this ). BeforeStarting (
52+ std::initializer_list<std::shared_ptr< Subsystem>> requirements) {
53+ return BeforeStarting (
5454 std::move (toRun),
5555 wpi::makeArrayRef (requirements.begin (), requirements.end ()));
5656}
5757
58- SequentialCommandGroup Command::BeforeStarting (
59- std::function<void ()> toRun, wpi::ArrayRef<Subsystem*> requirements) && {
60- std::vector<std::unique_ptr <Command>> temp;
58+ std::shared_ptr< SequentialCommandGroup> Command::BeforeStarting (
59+ std::function<void ()> toRun, wpi::ArrayRef<std::shared_ptr< Subsystem>> requirements) {
60+ std::vector<std::shared_ptr <Command>> temp;
6161 temp.emplace_back (
62- std::make_unique <InstantCommand>(std::move (toRun), requirements));
63- temp.emplace_back (std::move (* this ). TransferOwnership ());
64- return SequentialCommandGroup (std::move (temp));
62+ std::make_shared <InstantCommand>(std::move (toRun), requirements));
63+ temp.emplace_back (shared_from_this ());
64+ return std::make_shared< SequentialCommandGroup> (std::move (temp));
6565}
6666
67- SequentialCommandGroup Command::AndThen (
67+ std::shared_ptr< SequentialCommandGroup> Command::AndThen (
6868 std::function<void ()> toRun,
69- std::initializer_list<Subsystem*> requirements) && {
70- return std::move (* this ). AndThen (
69+ std::initializer_list<std::shared_ptr< Subsystem>> requirements) {
70+ return AndThen (
7171 std::move (toRun),
7272 wpi::makeArrayRef (requirements.begin (), requirements.end ()));
7373}
7474
75- SequentialCommandGroup Command::AndThen (
76- std::function<void ()> toRun, wpi::ArrayRef<Subsystem*> requirements) && {
77- std::vector<std::unique_ptr <Command>> temp;
78- temp.emplace_back (std::move (* this ). TransferOwnership ());
75+ std::shared_ptr< SequentialCommandGroup> Command::AndThen (
76+ std::function<void ()> toRun, wpi::ArrayRef<std::shared_ptr< Subsystem>> requirements) {
77+ std::vector<std::shared_ptr <Command>> temp;
78+ temp.emplace_back (shared_from_this ());
7979 temp.emplace_back (
80- std::make_unique <InstantCommand>(std::move (toRun), requirements));
81- return SequentialCommandGroup (std::move (temp));
80+ std::make_shared <InstantCommand>(std::move (toRun), requirements));
81+ return std::make_shared< SequentialCommandGroup> (std::move (temp));
8282}
8383
84- PerpetualCommand Command::Perpetually () && {
85- return PerpetualCommand ( std::move (* this ). TransferOwnership ());
84+ std::shared_ptr< PerpetualCommand> Command::Perpetually () {
85+ return std::make_shared<PerpetualCommand>( shared_from_this ());
8686}
8787
88- ProxyScheduleCommand Command::AsProxy () {
89- return ProxyScheduleCommand ( this );
88+ std::shared_ptr< ProxyScheduleCommand> Command::AsProxy () {
89+ return std::make_shared< ProxyScheduleCommand>( shared_from_this () );
9090}
9191
9292void Command::Schedule (bool interruptible) {
93- CommandScheduler::GetInstance ().Schedule (interruptible, this );
93+ CommandScheduler::GetInstance ().Schedule (interruptible, shared_from_this () );
9494}
9595
9696void Command::Cancel () {
97- CommandScheduler::GetInstance ().Cancel (this );
97+ CommandScheduler::GetInstance ().Cancel (shared_from_this () );
9898}
9999
100- bool Command::IsScheduled () const {
101- return CommandScheduler::GetInstance ().IsScheduled (this );
100+ bool Command::IsScheduled () {
101+ return CommandScheduler::GetInstance ().IsScheduled (shared_from_this () );
102102}
103103
104- bool Command::HasRequirement (Subsystem* requirement) const {
104+ bool Command::HasRequirement (std::shared_ptr< Subsystem> requirement) const {
105105 bool hasRequirement = false ;
106106 for (auto && subsystem : GetRequirements ()) {
107107 hasRequirement |= requirement == subsystem;
@@ -110,7 +110,7 @@ bool Command::HasRequirement(Subsystem* requirement) const {
110110}
111111
112112std::string Command::GetName () const {
113- return GetTypeName (* this );
113+ return GetTypeName (shared_from_this () );
114114}
115115
116116bool Command::IsGrouped () const {
@@ -126,7 +126,8 @@ bool RequirementsDisjoint(Command* first, Command* second) {
126126 bool disjoint = true ;
127127 auto && requirements = second->GetRequirements ();
128128 for (auto && requirement : first->GetRequirements ()) {
129- disjoint &= requirements.find (requirement) == requirements.end ();
129+ // disjoint &= requirements.count(requirement) == requirements.end();
130+ disjoint &= requirements.count (requirement) == 0 ;
130131 }
131132 return disjoint;
132133}
0 commit comments