blob: 5dbee54aeea3adc8bdf8c04f9617e0b3740b0b53 [file] [log] [blame]
Brian Silvermanf7f267a2017-02-04 16:16:08 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2011-2017. 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 the root directory of */
5/* the project. */
6/*----------------------------------------------------------------------------*/
7
8#pragma once
9
10#include <memory>
11#include <string>
12
13#include "SmartDashboard/SendableChooserBase.h"
14#include "llvm/StringMap.h"
15#include "llvm/StringRef.h"
16#include "tables/ITable.h"
17
18namespace frc {
19
20/**
21 * The {@link SendableChooser} class is a useful tool for presenting a selection
22 * of options to the {@link SmartDashboard}.
23 *
24 * <p>For instance, you may wish to be able to select between multiple
25 * autonomous modes. You can do this by putting every possible {@link Command}
26 * you want to run as an autonomous into a {@link SendableChooser} and then put
27 * it into the {@link SmartDashboard} to have a list of options appear on the
28 * laptop. Once autonomous starts, simply ask the {@link SendableChooser} what
29 * the selected value is.</p>
30 *
31 * @tparam T The type of values to be stored
32 * @see SmartDashboard
33 */
34template <class T>
35class SendableChooser : public SendableChooserBase {
36 public:
37 virtual ~SendableChooser() = default;
38
39 void AddObject(llvm::StringRef name, const T& object);
40 void AddDefault(llvm::StringRef name, const T& object);
41 T GetSelected();
42
43 void InitTable(std::shared_ptr<ITable> subtable) override;
44
45 private:
46 llvm::StringMap<T> m_choices;
47};
48
49} // namespace frc
50
51#include "SendableChooser.inc"