WPILibC++  unspecified
SendableChooser.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2011-2017 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 #include <string>
12 
13 #include <llvm/StringMap.h>
14 #include <llvm/StringRef.h>
15 
16 #include "SmartDashboard/SendableChooserBase.h"
17 #include "networktables/NetworkTable.h"
18 #include "networktables/NetworkTableEntry.h"
19 
20 namespace frc {
21 
36 template <class T>
38  llvm::StringMap<T> m_choices;
39  nt::NetworkTableEntry m_selectedEntry;
40 
41  template <class U>
42  static U _unwrap_smart_ptr(const U& value);
43 
44  template <class U>
45  static U* _unwrap_smart_ptr(const std::unique_ptr<U>& value);
46 
47  template <class U>
48  static std::weak_ptr<U> _unwrap_smart_ptr(const std::shared_ptr<U>& value);
49 
50  public:
51  virtual ~SendableChooser() = default;
52 
53  void AddObject(llvm::StringRef name, T object);
54  void AddDefault(llvm::StringRef name, T object);
55 
56  auto GetSelected() -> decltype(_unwrap_smart_ptr(m_choices[""]));
57 
58  void InitTable(std::shared_ptr<nt::NetworkTable> subtable) override;
59 };
60 
61 } // namespace frc
62 
63 #include "SendableChooser.inc"
Definition: Timer.cpp:18
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:37
NetworkTables Entry.
Definition: NetworkTableEntry.h:30
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42
void InitTable(std::shared_ptr< nt::NetworkTable > subtable) override
Initializes a table for this sendable object.
Definition: SendableChooser.inc:71