WPILibC++  unspecified
SendableChooser.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2011-2018 FIRST. 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 
12 #include <llvm/StringMap.h>
13 #include <llvm/StringRef.h>
14 
15 #include "SmartDashboard/SendableChooserBase.h"
16 
17 namespace frc {
18 
32 template <class T>
34  llvm::StringMap<T> m_choices;
35 
36  template <class U>
37  static U _unwrap_smart_ptr(const U& value);
38 
39  template <class U>
40  static U* _unwrap_smart_ptr(const std::unique_ptr<U>& value);
41 
42  template <class U>
43  static std::weak_ptr<U> _unwrap_smart_ptr(const std::shared_ptr<U>& value);
44 
45  public:
46  ~SendableChooser() override = default;
47 
48  void AddObject(llvm::StringRef name, T object);
49  void AddDefault(llvm::StringRef name, T object);
50 
51  auto GetSelected() -> decltype(_unwrap_smart_ptr(m_choices[""]));
52 
53  void InitSendable(SendableBuilder& builder) override;
54 };
55 
56 } // namespace frc
57 
58 #include "SendableChooser.inc"
Definition: RobotController.cpp:14
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:32
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:63
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:46
The SendableChooser class is a useful tool for presenting a selection of options to the SmartDashboar...
Definition: SendableChooser.h:33
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
Definition: SendableChooser.inc:77
Definition: SendableBuilder.h:23
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42