Skip to content

Commit feb62a9

Browse files
committed
Merge commit '00249d525338235273a8ca6bfdd9c06cb200419b' into upstream
2 parents 8f833fc + 00249d5 commit feb62a9

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

commands2/src/cpp/frc2/command/CommandPtr.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ CommandPtr CommandPtr::WithName(std::string_view name) && {
226226
return std::move(wrapper).ToPtr();
227227
}
228228

229-
CommandBase* CommandPtr::get() const {
229+
CommandBase* CommandPtr::get() const& {
230230
AssertValid();
231231
return m_ptr.get();
232232
}
@@ -236,27 +236,27 @@ std::unique_ptr<CommandBase> CommandPtr::Unwrap() && {
236236
return std::move(m_ptr);
237237
}
238238

239-
void CommandPtr::Schedule() const {
239+
void CommandPtr::Schedule() const& {
240240
AssertValid();
241241
CommandScheduler::GetInstance().Schedule(*this);
242242
}
243243

244-
void CommandPtr::Cancel() const {
244+
void CommandPtr::Cancel() const& {
245245
AssertValid();
246246
CommandScheduler::GetInstance().Cancel(*this);
247247
}
248248

249-
bool CommandPtr::IsScheduled() const {
249+
bool CommandPtr::IsScheduled() const& {
250250
AssertValid();
251251
return CommandScheduler::GetInstance().IsScheduled(*this);
252252
}
253253

254-
bool CommandPtr::HasRequirement(Subsystem* requirement) const {
254+
bool CommandPtr::HasRequirement(Subsystem* requirement) const& {
255255
AssertValid();
256256
return m_ptr->HasRequirement(requirement);
257257
}
258258

259-
CommandPtr::operator bool() const {
259+
CommandPtr::operator bool() const& {
260260
return m_ptr.operator bool();
261261
}
262262

commands2/src/cpp/frc2/command/CommandScheduler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,10 @@ void CommandScheduler::OnCommandFinish(Action action) {
433433

434434
void CommandScheduler::RequireUngrouped(const Command* command) {
435435
if (command->IsComposed()) {
436-
throw FRC_MakeError(
437-
frc::err::CommandIllegalUse,
438-
"Commands cannot be added to more than one CommandGroup");
436+
throw FRC_MakeError(frc::err::CommandIllegalUse,
437+
"Commands that have been composed may not be added to "
438+
"another composition or scheduled "
439+
"individually!");
439440
}
440441
}
441442

commands2/src/include/frc2/command/CommandPtr.h

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,10 @@ class CommandPtr final {
232232
/**
233233
* Get a raw pointer to the held command.
234234
*/
235-
CommandBase* get() const;
235+
CommandBase* get() const&;
236+
237+
// Prevent calls on a temporary, as the returned pointer would be invalid
238+
CommandBase* get() && = delete;
236239

237240
/**
238241
* Convert to the underlying unique_ptr.
@@ -242,13 +245,19 @@ class CommandPtr final {
242245
/**
243246
* Schedules this command.
244247
*/
245-
void Schedule() const;
248+
void Schedule() const&;
249+
250+
// Prevent calls on a temporary, as the returned pointer would be invalid
251+
void Schedule() && = delete;
246252

247253
/**
248254
* Cancels this command. Will call End(true). Commands will be canceled
249255
* regardless of interruption behavior.
250256
*/
251-
void Cancel() const;
257+
void Cancel() const&;
258+
259+
// Prevent calls on a temporary, as the returned pointer would be invalid
260+
void Cancel() && = delete;
252261

253262
/**
254263
* Whether or not the command is currently scheduled. Note that this does not
@@ -257,7 +266,10 @@ class CommandPtr final {
257266
*
258267
* @return Whether the command is scheduled.
259268
*/
260-
bool IsScheduled() const;
269+
bool IsScheduled() const&;
270+
271+
// Prevent calls on a temporary, as the returned pointer would be invalid
272+
void IsScheduled() && = delete;
261273

262274
/**
263275
* Whether the command requires a given subsystem. Named "HasRequirement"
@@ -267,12 +279,18 @@ class CommandPtr final {
267279
* @param requirement the subsystem to inquire about
268280
* @return whether the subsystem is required
269281
*/
270-
bool HasRequirement(Subsystem* requirement) const;
282+
bool HasRequirement(Subsystem* requirement) const&;
283+
284+
// Prevent calls on a temporary, as the returned pointer would be invalid
285+
void HasRequirement(Subsystem* requirement) && = delete;
271286

272287
/**
273288
* Check if this CommandPtr object is valid and wasn't moved-from.
274289
*/
275-
explicit operator bool() const;
290+
explicit operator bool() const&;
291+
292+
// Prevent calls on a temporary, as the returned pointer would be invalid
293+
explicit operator bool() && = delete;
276294

277295
/**
278296
* Convert a vector of CommandPtr objects to their underlying unique_ptrs.

0 commit comments

Comments
 (0)