blob: a0813817c9713e083b92a6432acb4d707d2c1254 [file] [log] [blame]
jerrymf1579332013-02-07 01:56:28 +00001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2011. All Rights Reserved. */
3/* Open Source Software - may be modified and shared by FRC teams. The code */
4/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
5/*----------------------------------------------------------------------------*/
6
7#ifndef __COMMAND_GROUP_H__
8#define __COMMAND_GROUP_H__
9
10#include "Commands/Command.h"
11#include "Commands/CommandGroupEntry.h"
12#include <list>
13#include <vector>
14
15/**
16 * A {@link CommandGroup} is a list of commands which are executed in sequence.
17 *
18 * <p>Commands in a {@link CommandGroup} are added using the {@link CommandGroup#AddSequential(Command) AddSequential(...)} method
19 * and are called sequentially.
20 * {@link CommandGroup CommandGroups} are themselves {@link Command Commands}
21 * and can be given to other {@link CommandGroup CommandGroups}.</p>
22 *
23 * <p>{@link CommandGroup CommandGroups} will carry all of the requirements of their {@link Command subcommands}. Additional
24 * requirements can be specified by calling {@link CommandGroup#Requires(Subsystem) Requires(...)}
25 * normally in the constructor.</P>
26 *
27 * <p>CommandGroups can also execute commands in parallel, simply by adding them
28 * using {@link CommandGroup#AddParallel(Command) AddParallel(...)}.</p>
29 *
30 * @see Command
31 * @see Subsystem
32 */
33class CommandGroup : public Command
34{
35public:
36 CommandGroup();
37 CommandGroup(const char *name);
38 virtual ~CommandGroup();
39
40 void AddSequential(Command *command);
41 void AddSequential(Command *command, double timeout);
42 void AddParallel(Command *command);
43 void AddParallel(Command *command, double timeout);
44 bool IsInterruptible();
45 int GetSize();
46
47protected:
48 virtual void Initialize();
49 virtual void Execute();
50 virtual bool IsFinished();
51 virtual void End();
52 virtual void Interrupted();
53 virtual void _Initialize();
54 virtual void _Interrupted();
55 virtual void _Execute();
56 virtual void _End();
57
58private:
59 void CancelConflicts(Command *command);
60
61 typedef std::vector<CommandGroupEntry> CommandVector;
62 /** The commands in this group (stored in entries) */
63 CommandVector m_commands;
64 typedef std::list<CommandGroupEntry> CommandList;
65 /** The active children in this group (stored in entries) */
66 CommandList m_children;
67 /** The current command, -1 signifies that none have been run */
68 int m_currentCommandIndex;
69};
70
71#endif