WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
SendableChooser.h
1 /*----------------------------------------------------------------------------*/
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 
18 namespace frc {
19 
34 template <class T>
36  llvm::StringMap<T> m_choices;
37 
38  template <class U>
39  static U _unwrap_smart_ptr(const U& value);
40 
41  template <class U>
42  static U* _unwrap_smart_ptr(const std::unique_ptr<U>& value);
43 
44  template <class U>
45  static std::weak_ptr<U> _unwrap_smart_ptr(const std::shared_ptr<U>& value);
46 
47  public:
48  virtual ~SendableChooser() = default;
49 
50  void AddObject(llvm::StringRef name, T object);
51  void AddDefault(llvm::StringRef name, T object);
52 
53  auto GetSelected() -> decltype(_unwrap_smart_ptr(m_choices[""]));
54 
55  void InitTable(std::shared_ptr<ITable> subtable) override;
56 };
57 
58 } // namespace frc
59 
60 #include "SendableChooser.inc"
This class is a non-template base class for SendableChooser.
Definition: SendableChooserBase.h:24
void AddObject(llvm::StringRef name, T object)
Adds the given object to the list of options.
Definition: SendableChooser.inc:28
auto GetSelected() -> decltype(_unwrap_smart_ptr(m_choices[""]))
Returns a copy of the selected option (a raw pointer U* if T = std::unique_ptr<U> or a std::weak_ptr<...
Definition: SendableChooser.inc:60
void AddDefault(llvm::StringRef name, T object)
Add the given object to the list of options and marks it as the default.
Definition: SendableChooser.inc:43
The SendableChooser class is a useful tool for presenting a selection of options to the SmartDashboar...
Definition: SendableChooser.h:35
void InitTable(std::shared_ptr< ITable > subtable) override
Initializes a table for this sendable object.
Definition: SendableChooser.inc:71