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>
|
|
|
|
|
|
2019-11-05 20:52:49 -08:00
|
|
|
#include <wpi/ArrayRef.h>
|
|
|
|
|
|
|
|
|
|
#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.
|
|
|
|
|
*/
|
|
|
|
|
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.
|
|
|
|
|
*
|
|
|
|
|
* @param commands The command to check
|
|
|
|
|
* @return True if all the command is ungrouped.
|
|
|
|
|
*/
|
|
|
|
|
static bool RequireUngrouped(Command& command);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
static bool RequireUngrouped(wpi::ArrayRef<std::unique_ptr<Command>>);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
static bool RequireUngrouped(std::initializer_list<Command*>);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|