2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2019-11-05 20:52:49 -08:00
|
|
|
#include <initializer_list>
|
2019-08-25 23:55:59 -04:00
|
|
|
#include <memory>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2021-06-06 19:51:14 -07:00
|
|
|
#include <wpi/span.h>
|
2019-11-05 20:52:49 -08:00
|
|
|
|
|
|
|
|
#include "frc2/command/CommandBase.h"
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
namespace frc2 {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A base for CommandGroups. Statically tracks commands that have been
|
|
|
|
|
* allocated to groups to ensure those commands are not also used independently,
|
|
|
|
|
* which can result in inconsistent command state and unpredictable execution.
|
2022-01-08 11:11:34 -08:00
|
|
|
*
|
|
|
|
|
* This class is provided by the NewCommands VendorDep
|
2019-08-25 23:55:59 -04:00
|
|
|
*/
|
|
|
|
|
class CommandGroupBase : public CommandBase {
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Requires that the specified command not have been already allocated to a
|
|
|
|
|
* CommandGroup. Reports an error if the command is already grouped.
|
|
|
|
|
*
|
2021-06-06 19:51:14 -07:00
|
|
|
* @param command The command to check
|
2019-08-25 23:55:59 -04:00
|
|
|
* @return True if all the command is ungrouped.
|
|
|
|
|
*/
|
2021-06-06 19:51:14 -07:00
|
|
|
static bool RequireUngrouped(const Command& command);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Requires that the specified command not have been already allocated to a
|
|
|
|
|
* CommandGroup. Reports an error if the command is already grouped.
|
|
|
|
|
*
|
|
|
|
|
* @param command The command to check
|
|
|
|
|
* @return True if all the command is ungrouped.
|
|
|
|
|
*/
|
|
|
|
|
static bool RequireUngrouped(const Command* command);
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Requires that the specified commands not have been already allocated to a
|
|
|
|
|
* CommandGroup. Reports an error if any of the commands are already grouped.
|
|
|
|
|
*
|
|
|
|
|
* @param commands The commands to check
|
|
|
|
|
* @return True if all the commands are ungrouped.
|
|
|
|
|
*/
|
2021-10-14 18:09:38 -07:00
|
|
|
static bool RequireUngrouped(
|
|
|
|
|
wpi::span<const std::unique_ptr<Command>> commands);
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Requires that the specified commands not have been already allocated to a
|
|
|
|
|
* CommandGroup. Reports an error if any of the commands are already grouped.
|
|
|
|
|
*
|
|
|
|
|
* @param commands The commands to check
|
|
|
|
|
* @return True if all the commands are ungrouped.
|
|
|
|
|
*/
|
2021-10-14 18:09:38 -07:00
|
|
|
static bool RequireUngrouped(std::initializer_list<const Command*> commands);
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds the given commands to the command group.
|
|
|
|
|
*
|
|
|
|
|
* @param commands The commands to add.
|
|
|
|
|
*/
|
|
|
|
|
virtual void AddCommands(
|
|
|
|
|
std::vector<std::unique_ptr<Command>>&& commands) = 0;
|
|
|
|
|
};
|
|
|
|
|
} // namespace frc2
|