blob: 9560746e03400ddaaa7722b2c1461fb15bdd3ce7 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05002/* Copyright (c) FIRST 2011-2016. All Rights Reserved. */
Brian Silverman26e4e522015-12-17 01:56:40 -05003/* Open Source Software - may be modified and shared by FRC teams. The code */
Brian Silverman1a675112016-02-20 20:42:49 -05004/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
Brian Silverman26e4e522015-12-17 01:56:40 -05006/*----------------------------------------------------------------------------*/
7
8#ifndef __SENDABLE_CHOOSER_H__
9#define __SENDABLE_CHOOSER_H__
10
11#include "SmartDashboard/Sendable.h"
12#include "tables/ITable.h"
13#include <map>
14#include <memory>
15#include <string>
16
17/**
18 * The {@link SendableChooser} class is a useful tool for presenting a selection
19 * of options
20 * to the {@link SmartDashboard}.
21 *
22 * <p>For instance, you may wish to be able to select between multiple
23 * autonomous modes.
24 * You can do this by putting every possible {@link Command} you want to run as
25 * an autonomous into
26 * a {@link SendableChooser} and then put it into the {@link SmartDashboard} to
27 * have a list of options
28 * appear on the laptop. Once autonomous starts, simply ask the {@link
29 * SendableChooser} what the selected
30 * value is.</p>
31 *
32 * @see SmartDashboard
33 */
34class SendableChooser : public Sendable {
35 public:
36 virtual ~SendableChooser() = default;
37
38 void AddObject(const std::string &name, void *object);
39 void AddDefault(const std::string &name, void *object);
40 void *GetSelected();
41
42 virtual void InitTable(std::shared_ptr<ITable> subtable);
43 virtual std::shared_ptr<ITable> GetTable() const;
44 virtual std::string GetSmartDashboardType() const;
45
46 private:
47 std::string m_defaultChoice;
48 std::map<std::string, void *> m_choices;
49 std::shared_ptr<ITable> m_table;
50};
51
52#endif