WPILibC++  2020.3.2
SuppliedValueWidget.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2019 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 <functional>
11 #include <memory>
12 
13 #include <networktables/NetworkTable.h>
14 #include <networktables/NetworkTableEntry.h>
15 #include <wpi/Twine.h>
16 
17 #include "frc/shuffleboard/ShuffleboardComponent.h"
18 #include "frc/shuffleboard/ShuffleboardComponent.inc"
19 #include "frc/shuffleboard/ShuffleboardComponentBase.h"
20 #include "frc/shuffleboard/ShuffleboardContainer.h"
21 #include "frc/shuffleboard/ShuffleboardWidget.h"
22 
23 namespace frc {
24 template <typename T>
25 class SuppliedValueWidget : public ShuffleboardWidget<SuppliedValueWidget<T> > {
26  public:
28  std::function<T()> supplier,
29  std::function<void(nt::NetworkTableEntry, T)> setter)
30  : ShuffleboardValue(title),
32  m_supplier(supplier),
33  m_setter(setter) {}
34 
35  void BuildInto(std::shared_ptr<nt::NetworkTable> parentTable,
36  std::shared_ptr<nt::NetworkTable> metaTable) override {
37  this->BuildMetadata(metaTable);
38  metaTable->GetEntry("Controllable").SetBoolean(false);
39 
40  auto entry = parentTable->GetEntry(this->GetTitle());
41  m_setter(entry, m_supplier());
42  }
43 
44  private:
45  std::function<T()> m_supplier;
46  std::function<void(nt::NetworkTableEntry, T)> m_setter;
47 };
48 } // namespace frc
frc::SuppliedValueWidget
Definition: SuppliedValueWidget.h:25
frc::ShuffleboardValue
Definition: ShuffleboardValue.h:19
nt::NetworkTableEntry
NetworkTables Entry.
Definition: NetworkTableEntry.h:39
frc::ShuffleboardContainer
Common interface for objects that can contain shuffleboard components.
Definition: ShuffleboardContainer.h:44
frc
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16
frc::SuppliedValueWidget::BuildInto
void BuildInto(std::shared_ptr< nt::NetworkTable > parentTable, std::shared_ptr< nt::NetworkTable > metaTable) override
Builds the entries for this value.
Definition: SuppliedValueWidget.h:35
frc::ShuffleboardWidget
Abstract superclass for widgets.
Definition: ShuffleboardWidget.h:32
wpi::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:85
frc::ShuffleboardValue::GetTitle
wpi::StringRef GetTitle() const
Gets the title of this Shuffleboard value.
Definition: ShuffleboardValue.h:31