blob: bfdf87757c4c77967061418f8d8520fdbd3f5208 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2011. All Rights Reserved.
3 */
4/* Open Source Software - may be modified and shared by FRC teams. The code */
5/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
6/*----------------------------------------------------------------------------*/
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