18
18
using namespace frc2 ;
19
19
20
20
Command::~Command () {
21
- CommandScheduler::GetInstance ().Cancel (this );
21
+ // CommandScheduler::GetInstance().Cancel(shared_from_this() );
22
22
}
23
23
24
- Command::Command (const Command& rhs) : ErrorBase(rhs) {}
24
+ // Command::Command(const Command& rhs) : ErrorBase(rhs) {}
25
25
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
+ // }
31
31
32
32
void Command::Initialize () {}
33
33
void Command::Execute () {}
34
34
void Command::End (bool interrupted) {}
35
35
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));
41
41
}
42
42
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));
48
48
}
49
49
50
- SequentialCommandGroup Command::BeforeStarting (
50
+ std::shared_ptr< SequentialCommandGroup> Command::BeforeStarting (
51
51
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 (
54
54
std::move (toRun),
55
55
wpi::makeArrayRef (requirements.begin (), requirements.end ()));
56
56
}
57
57
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;
61
61
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));
65
65
}
66
66
67
- SequentialCommandGroup Command::AndThen (
67
+ std::shared_ptr< SequentialCommandGroup> Command::AndThen (
68
68
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 (
71
71
std::move (toRun),
72
72
wpi::makeArrayRef (requirements.begin (), requirements.end ()));
73
73
}
74
74
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 ());
79
79
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));
82
82
}
83
83
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 ());
86
86
}
87
87
88
- ProxyScheduleCommand Command::AsProxy () {
89
- return ProxyScheduleCommand ( this );
88
+ std::shared_ptr< ProxyScheduleCommand> Command::AsProxy () {
89
+ return std::make_shared< ProxyScheduleCommand>( shared_from_this () );
90
90
}
91
91
92
92
void Command::Schedule (bool interruptible) {
93
- CommandScheduler::GetInstance ().Schedule (interruptible, this );
93
+ CommandScheduler::GetInstance ().Schedule (interruptible, shared_from_this () );
94
94
}
95
95
96
96
void Command::Cancel () {
97
- CommandScheduler::GetInstance ().Cancel (this );
97
+ CommandScheduler::GetInstance ().Cancel (shared_from_this () );
98
98
}
99
99
100
- bool Command::IsScheduled () const {
101
- return CommandScheduler::GetInstance ().IsScheduled (this );
100
+ bool Command::IsScheduled () {
101
+ return CommandScheduler::GetInstance ().IsScheduled (shared_from_this () );
102
102
}
103
103
104
- bool Command::HasRequirement (Subsystem* requirement) const {
104
+ bool Command::HasRequirement (std::shared_ptr< Subsystem> requirement) const {
105
105
bool hasRequirement = false ;
106
106
for (auto && subsystem : GetRequirements ()) {
107
107
hasRequirement |= requirement == subsystem;
@@ -110,7 +110,7 @@ bool Command::HasRequirement(Subsystem* requirement) const {
110
110
}
111
111
112
112
std::string Command::GetName () const {
113
- return GetTypeName (* this );
113
+ return GetTypeName (shared_from_this () );
114
114
}
115
115
116
116
bool Command::IsGrouped () const {
@@ -126,7 +126,8 @@ bool RequirementsDisjoint(Command* first, Command* second) {
126
126
bool disjoint = true ;
127
127
auto && requirements = second->GetRequirements ();
128
128
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 ;
130
131
}
131
132
return disjoint;
132
133
}
0 commit comments