Move CameraServer and WPILib headers into their own folder

The old headers were moved into folders because doing so avoids polluting
the system include directories.

Folder names were also normalized to lowercase.
This commit is contained in:
Tyler Veness
2018-07-20 00:03:45 -07:00
committed by Peter Johnson
parent 31ced30c1e
commit d89b7dd412
728 changed files with 1876 additions and 1851 deletions

View File

@@ -0,0 +1,32 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2012-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <string>
#include <wpi/deprecated.h>
#include "frc/smartdashboard/Sendable.h"
namespace frc {
/**
* The interface for sendable objects that gives the sendable a default name in
* the Smart Dashboard.
* @deprecated Use Sendable directly instead
*/
class WPI_DEPRECATED("use Sendable directly instead") NamedSendable
: public Sendable {
public:
void SetName(const wpi::Twine& name) override;
std::string GetSubsystem() const override;
void SetSubsystem(const wpi::Twine& subsystem) override;
void InitSendable(SendableBuilder& builder) override;
};
} // namespace frc

View File

@@ -0,0 +1,69 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2011-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <string>
#include <wpi/Twine.h>
namespace frc {
class SendableBuilder;
class Sendable {
public:
virtual ~Sendable() = default;
/**
* Gets the name of this Sendable object.
*
* @return Name
*/
virtual std::string GetName() const = 0;
/**
* Sets the name of this Sendable object.
*
* @param name name
*/
virtual void SetName(const wpi::Twine& name) = 0;
/**
* Sets both the subsystem name and device name of this Sendable object.
*
* @param subsystem subsystem name
* @param name device name
*/
void SetName(const wpi::Twine& subsystem, const wpi::Twine& name) {
SetSubsystem(subsystem);
SetName(name);
}
/**
* Gets the subsystem name of this Sendable object.
*
* @return Subsystem name
*/
virtual std::string GetSubsystem() const = 0;
/**
* Sets the subsystem name of this Sendable object.
*
* @param subsystem subsystem name
*/
virtual void SetSubsystem(const wpi::Twine& subsystem) = 0;
/**
* Initializes this Sendable object.
*
* @param builder sendable builder
*/
virtual void InitSendable(SendableBuilder& builder) = 0;
};
} // namespace frc

View File

@@ -0,0 +1,78 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <memory>
#include <string>
#include <wpi/mutex.h>
#include "frc/smartdashboard/Sendable.h"
namespace frc {
class SendableBase : public Sendable {
public:
/**
* Creates an instance of the sensor base.
*
* @param addLiveWindow if true, add this Sendable to LiveWindow
*/
explicit SendableBase(bool addLiveWindow = true);
~SendableBase() override;
using Sendable::SetName;
std::string GetName() const final;
void SetName(const wpi::Twine& name) final;
std::string GetSubsystem() const final;
void SetSubsystem(const wpi::Twine& subsystem) final;
protected:
/**
* Add a child component.
*
* @param child child component
*/
void AddChild(std::shared_ptr<Sendable> child);
/**
* Add a child component.
*
* @param child child component
*/
void AddChild(void* child);
/**
* Sets the name of the sensor with a channel number.
*
* @param moduleType A string that defines the module name in the label for
* the value
* @param channel The channel number the device is plugged into
*/
void SetName(const wpi::Twine& moduleType, int channel);
/**
* Sets the name of the sensor with a module and channel number.
*
* @param moduleType A string that defines the module name in the label for
* the value
* @param moduleNumber The number of the particular module type
* @param channel The channel number the device is plugged into (usually
* PWM)
*/
void SetName(const wpi::Twine& moduleType, int moduleNumber, int channel);
private:
mutable wpi::mutex m_mutex;
std::string m_name;
std::string m_subsystem = "Ungrouped";
};
} // namespace frc

View File

@@ -0,0 +1,214 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <functional>
#include <memory>
#include <string>
#include <vector>
#include <networktables/NetworkTableEntry.h>
#include <networktables/NetworkTableValue.h>
#include <wpi/ArrayRef.h>
#include <wpi/SmallVector.h>
#include <wpi/Twine.h>
namespace frc {
class SendableBuilder {
public:
virtual ~SendableBuilder() = default;
/**
* Set the string representation of the named data type that will be used
* by the smart dashboard for this sendable.
*
* @param type data type
*/
virtual void SetSmartDashboardType(const wpi::Twine& type) = 0;
/**
* Set the function that should be called to set the Sendable into a safe
* state. This is called when entering and exiting Live Window mode.
*
* @param func function
*/
virtual void SetSafeState(std::function<void()> func) = 0;
/**
* Set the function that should be called to update the network table
* for things other than properties. Note this function is not passed
* the network table object; instead it should use the entry handles
* returned by GetEntry().
*
* @param func function
*/
virtual void SetUpdateTable(std::function<void()> func) = 0;
/**
* Add a property without getters or setters. This can be used to get
* entry handles for the function called by SetUpdateTable().
*
* @param key property name
* @return Network table entry
*/
virtual nt::NetworkTableEntry GetEntry(const wpi::Twine& key) = 0;
/**
* Add a boolean property.
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
virtual void AddBooleanProperty(const wpi::Twine& key,
std::function<bool()> getter,
std::function<void(bool)> setter) = 0;
/**
* Add a double property.
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
virtual void AddDoubleProperty(const wpi::Twine& key,
std::function<double()> getter,
std::function<void(double)> setter) = 0;
/**
* Add a string property.
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
virtual void AddStringProperty(
const wpi::Twine& key, std::function<std::string()> getter,
std::function<void(wpi::StringRef)> setter) = 0;
/**
* Add a boolean array property.
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
virtual void AddBooleanArrayProperty(
const wpi::Twine& key, std::function<std::vector<int>()> getter,
std::function<void(wpi::ArrayRef<int>)> setter) = 0;
/**
* Add a double array property.
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
virtual void AddDoubleArrayProperty(
const wpi::Twine& key, std::function<std::vector<double>()> getter,
std::function<void(wpi::ArrayRef<double>)> setter) = 0;
/**
* Add a string array property.
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
virtual void AddStringArrayProperty(
const wpi::Twine& key, std::function<std::vector<std::string>()> getter,
std::function<void(wpi::ArrayRef<std::string>)> setter) = 0;
/**
* Add a raw property.
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
virtual void AddRawProperty(const wpi::Twine& key,
std::function<std::string()> getter,
std::function<void(wpi::StringRef)> setter) = 0;
/**
* Add a NetworkTableValue property.
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
virtual void AddValueProperty(
const wpi::Twine& key, std::function<std::shared_ptr<nt::Value>()> getter,
std::function<void(std::shared_ptr<nt::Value>)> setter) = 0;
/**
* Add a string property (SmallString form).
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
virtual void AddSmallStringProperty(
const wpi::Twine& key,
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
std::function<void(wpi::StringRef)> setter) = 0;
/**
* Add a boolean array property (SmallVector form).
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
virtual void AddSmallBooleanArrayProperty(
const wpi::Twine& key,
std::function<wpi::ArrayRef<int>(wpi::SmallVectorImpl<int>& buf)> getter,
std::function<void(wpi::ArrayRef<int>)> setter) = 0;
/**
* Add a double array property (SmallVector form).
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
virtual void AddSmallDoubleArrayProperty(
const wpi::Twine& key,
std::function<wpi::ArrayRef<double>(wpi::SmallVectorImpl<double>& buf)>
getter,
std::function<void(wpi::ArrayRef<double>)> setter) = 0;
/**
* Add a string array property (SmallVector form).
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
virtual void AddSmallStringArrayProperty(
const wpi::Twine& key,
std::function<
wpi::ArrayRef<std::string>(wpi::SmallVectorImpl<std::string>& buf)>
getter,
std::function<void(wpi::ArrayRef<std::string>)> setter) = 0;
/**
* Add a raw property (SmallVector form).
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
virtual void AddSmallRawProperty(
const wpi::Twine& key,
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
std::function<void(wpi::StringRef)> setter) = 0;
};
} // namespace frc

View File

@@ -0,0 +1,192 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <functional>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <networktables/NetworkTable.h>
#include <networktables/NetworkTableEntry.h>
#include <networktables/NetworkTableValue.h>
#include <wpi/ArrayRef.h>
#include <wpi/SmallVector.h>
#include <wpi/Twine.h>
#include "frc/smartdashboard/SendableBuilder.h"
namespace frc {
class SendableBuilderImpl : public SendableBuilder {
public:
SendableBuilderImpl() = default;
SendableBuilderImpl(const SendableBuilderImpl&) = delete;
SendableBuilderImpl(SendableBuilderImpl&& other) = default;
SendableBuilderImpl& operator=(const SendableBuilderImpl&) = delete;
SendableBuilderImpl& operator=(SendableBuilderImpl&& other) = default;
~SendableBuilderImpl() override = default;
/**
* Set the network table. Must be called prior to any Add* functions being
* called.
* @param table Network table
*/
void SetTable(std::shared_ptr<nt::NetworkTable> table);
/**
* Get the network table.
* @return The network table
*/
std::shared_ptr<nt::NetworkTable> GetTable();
/**
* Update the network table values by calling the getters for all properties.
*/
void UpdateTable();
/**
* Hook setters for all properties.
*/
void StartListeners();
/**
* Unhook setters for all properties.
*/
void StopListeners();
/**
* Start LiveWindow mode by hooking the setters for all properties. Also
* calls the SafeState function if one was provided.
*/
void StartLiveWindowMode();
/**
* Stop LiveWindow mode by unhooking the setters for all properties. Also
* calls the SafeState function if one was provided.
*/
void StopLiveWindowMode();
void SetSmartDashboardType(const wpi::Twine& type) override;
void SetSafeState(std::function<void()> func) override;
void SetUpdateTable(std::function<void()> func) override;
nt::NetworkTableEntry GetEntry(const wpi::Twine& key) override;
void AddBooleanProperty(const wpi::Twine& key, std::function<bool()> getter,
std::function<void(bool)> setter) override;
void AddDoubleProperty(const wpi::Twine& key, std::function<double()> getter,
std::function<void(double)> setter) override;
void AddStringProperty(const wpi::Twine& key,
std::function<std::string()> getter,
std::function<void(wpi::StringRef)> setter) override;
void AddBooleanArrayProperty(
const wpi::Twine& key, std::function<std::vector<int>()> getter,
std::function<void(wpi::ArrayRef<int>)> setter) override;
void AddDoubleArrayProperty(
const wpi::Twine& key, std::function<std::vector<double>()> getter,
std::function<void(wpi::ArrayRef<double>)> setter) override;
void AddStringArrayProperty(
const wpi::Twine& key, std::function<std::vector<std::string>()> getter,
std::function<void(wpi::ArrayRef<std::string>)> setter) override;
void AddRawProperty(const wpi::Twine& key,
std::function<std::string()> getter,
std::function<void(wpi::StringRef)> setter) override;
void AddValueProperty(
const wpi::Twine& key, std::function<std::shared_ptr<nt::Value>()> getter,
std::function<void(std::shared_ptr<nt::Value>)> setter) override;
void AddSmallStringProperty(
const wpi::Twine& key,
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
std::function<void(wpi::StringRef)> setter) override;
void AddSmallBooleanArrayProperty(
const wpi::Twine& key,
std::function<wpi::ArrayRef<int>(wpi::SmallVectorImpl<int>& buf)> getter,
std::function<void(wpi::ArrayRef<int>)> setter) override;
void AddSmallDoubleArrayProperty(
const wpi::Twine& key,
std::function<wpi::ArrayRef<double>(wpi::SmallVectorImpl<double>& buf)>
getter,
std::function<void(wpi::ArrayRef<double>)> setter) override;
void AddSmallStringArrayProperty(
const wpi::Twine& key,
std::function<
wpi::ArrayRef<std::string>(wpi::SmallVectorImpl<std::string>& buf)>
getter,
std::function<void(wpi::ArrayRef<std::string>)> setter) override;
void AddSmallRawProperty(
const wpi::Twine& key,
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
std::function<void(wpi::StringRef)> setter) override;
private:
struct Property {
Property(nt::NetworkTable& table, const wpi::Twine& key)
: entry(table.GetEntry(key)) {}
Property(const Property&) = delete;
Property& operator=(const Property&) = delete;
Property(Property&& other) noexcept
: entry(other.entry),
listener(other.listener),
update(std::move(other.update)),
createListener(std::move(other.createListener)) {
other.entry = nt::NetworkTableEntry();
other.listener = 0;
}
Property& operator=(Property&& other) noexcept {
entry = other.entry;
listener = other.listener;
other.entry = nt::NetworkTableEntry();
other.listener = 0;
update = std::move(other.update);
createListener = std::move(other.createListener);
return *this;
}
~Property() { StopListener(); }
void StartListener() {
if (entry && listener == 0 && createListener)
listener = createListener(entry);
}
void StopListener() {
if (entry && listener != 0) {
entry.RemoveListener(listener);
listener = 0;
}
}
nt::NetworkTableEntry entry;
NT_EntryListener listener = 0;
std::function<void(nt::NetworkTableEntry entry, uint64_t time)> update;
std::function<NT_EntryListener(nt::NetworkTableEntry entry)> createListener;
};
std::vector<Property> m_properties;
std::function<void()> m_safeState;
std::function<void()> m_updateTable;
std::shared_ptr<nt::NetworkTable> m_table;
};
} // namespace frc

View File

@@ -0,0 +1,59 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2011-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <memory>
#include <wpi/StringMap.h>
#include <wpi/StringRef.h>
#include "frc/smartdashboard/SendableBuilder.h"
#include "frc/smartdashboard/SendableChooserBase.h"
namespace frc {
/**
* The SendableChooser class is a useful tool for presenting a selection of
* options to the SmartDashboard.
*
* For instance, you may wish to be able to select between multiple autonomous
* modes. You can do this by putting every possible Command you want to run as
* an autonomous into a SendableChooser and then put it into the SmartDashboard
* to have a list of options appear on the laptop. Once autonomous starts,
* simply ask the SendableChooser what the selected value is.
*
* @tparam T The type of values to be stored
* @see SmartDashboard
*/
template <class T>
class SendableChooser : public SendableChooserBase {
wpi::StringMap<T> m_choices;
template <class U>
static U _unwrap_smart_ptr(const U& value);
template <class U>
static U* _unwrap_smart_ptr(const std::unique_ptr<U>& value);
template <class U>
static std::weak_ptr<U> _unwrap_smart_ptr(const std::shared_ptr<U>& value);
public:
~SendableChooser() override = default;
void AddObject(wpi::StringRef name, T object);
void AddDefault(wpi::StringRef name, T object);
auto GetSelected() -> decltype(_unwrap_smart_ptr(m_choices[""]));
void InitSendable(SendableBuilder& builder) override;
};
} // namespace frc
#include "frc/smartdashboard/SendableChooser.inc"

View File

@@ -0,0 +1,119 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2011-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <wpi/StringRef.h>
namespace frc {
/**
* Adds the given object to the list of options.
*
* On the SmartDashboard on the desktop, the object will appear as the given
* name.
*
* @param name the name of the option
* @param object the option
*/
template <class T>
void SendableChooser<T>::AddObject(wpi::StringRef name, T object) {
m_choices[name] = std::move(object);
}
/**
* Add the given object to the list of options and marks it as the default.
*
* Functionally, this is very close to AddObject() except that it will use this
* as the default option if none other is explicitly selected.
*
* @param name the name of the option
* @param object the option
*/
template <class T>
void SendableChooser<T>::AddDefault(wpi::StringRef name, T object) {
m_defaultChoice = name;
AddObject(name, std::move(object));
}
/**
* Returns a copy of the selected option (a raw pointer U* if T =
* std::unique_ptr<U> or a std::weak_ptr<U> if T = std::shared_ptr<U>).
*
* If there is none selected, it will return the default. If there is none
* selected and no default, then it will return a value-initialized instance.
* For integer types, this is 0. For container types like std::string, this is
* an empty string.
*
* @return The option selected
*/
template <class T>
auto SendableChooser<T>::GetSelected()
-> decltype(_unwrap_smart_ptr(m_choices[""])) {
std::string selected = m_defaultChoice;
if (m_selectedEntry) {
selected = m_selectedEntry.GetString(m_defaultChoice);
}
if (selected.empty()) {
return decltype(_unwrap_smart_ptr(m_choices[""])){};
} else {
return _unwrap_smart_ptr(m_choices[selected]);
}
}
template <class T>
void SendableChooser<T>::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("String Chooser");
builder.AddStringArrayProperty(kOptions,
[=]() {
std::vector<std::string> keys;
for (const auto& choice : m_choices) {
keys.push_back(choice.first());
}
// Unlike std::map, wpi::StringMap elements
// are not sorted
std::sort(keys.begin(), keys.end());
return keys;
},
nullptr);
builder.AddSmallStringProperty(
kDefault,
[=](const wpi::SmallVectorImpl<char>&) -> wpi::StringRef {
return m_defaultChoice;
},
nullptr);
m_selectedEntry = builder.GetEntry(kSelected);
}
template <class T>
template <class U>
U SendableChooser<T>::_unwrap_smart_ptr(const U& value) {
return value;
}
template <class T>
template <class U>
U* SendableChooser<T>::_unwrap_smart_ptr(const std::unique_ptr<U>& value) {
return value.get();
}
template <class T>
template <class U>
std::weak_ptr<U> SendableChooser<T>::_unwrap_smart_ptr(
const std::shared_ptr<U>& value) {
return value;
}
} // namespace frc

View File

@@ -0,0 +1,38 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <string>
#include <networktables/NetworkTableEntry.h>
#include "frc/smartdashboard/SendableBase.h"
namespace frc {
/**
* This class is a non-template base class for SendableChooser.
*
* It contains static, non-templated variables to avoid their duplication in the
* template class.
*/
class SendableChooserBase : public SendableBase {
public:
SendableChooserBase();
~SendableChooserBase() override = default;
protected:
static constexpr const char* kDefault = "default";
static constexpr const char* kOptions = "options";
static constexpr const char* kSelected = "selected";
std::string m_defaultChoice;
nt::NetworkTableEntry m_selectedEntry;
};
} // namespace frc

View File

@@ -0,0 +1,413 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2011-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <memory>
#include <string>
#include <vector>
#include <networktables/NetworkTableValue.h>
#include "frc/ErrorBase.h"
#include "frc/smartdashboard/SendableBase.h"
namespace frc {
class Sendable;
class SmartDashboard : public ErrorBase, public SendableBase {
public:
static void init();
/**
* Determines whether the given key is in this table.
*
* @param key the key to search for
* @return true if the table as a value assigned to the given key
*/
static bool ContainsKey(wpi::StringRef key);
/**
* @param types bitmask of types; 0 is treated as a "don't care".
* @return keys currently in the table
*/
static std::vector<std::string> GetKeys(int types = 0);
/**
* Makes a key's value persistent through program restarts.
*
* @param key the key to make persistent
*/
static void SetPersistent(wpi::StringRef key);
/**
* Stop making a key's value persistent through program restarts.
* The key cannot be null.
*
* @param key the key name
*/
static void ClearPersistent(wpi::StringRef key);
/**
* Returns whether the value is persistent through program restarts.
* The key cannot be null.
*
* @param key the key name
*/
static bool IsPersistent(wpi::StringRef key);
/**
* Sets flags on the specified key in this table. The key can
* not be null.
*
* @param key the key name
* @param flags the flags to set (bitmask)
*/
static void SetFlags(wpi::StringRef key, unsigned int flags);
/**
* Clears flags on the specified key in this table. The key can
* not be null.
*
* @param key the key name
* @param flags the flags to clear (bitmask)
*/
static void ClearFlags(wpi::StringRef key, unsigned int flags);
/**
* Returns the flags for the specified key.
*
* @param key the key name
* @return the flags, or 0 if the key is not defined
*/
static unsigned int GetFlags(wpi::StringRef key);
/**
* Deletes the specified key in this table.
*
* @param key the key name
*/
static void Delete(wpi::StringRef key);
/**
* Maps the specified key to the specified value in this table.
*
* The value can be retrieved by calling the get method with a key that is
* equal to the original key.
*
* @param keyName the key
* @param value the value
*/
static void PutData(wpi::StringRef key, Sendable* data);
/**
* Maps the specified key (where the key is the name of the Sendable)
* to the specified value in this table.
*
* The value can be retrieved by calling the get method with a key that is
* equal to the original key.
*
* @param value the value
*/
static void PutData(Sendable* value);
/**
* Returns the value at the specified key.
*
* @param keyName the key
* @return the value
*/
static Sendable* GetData(wpi::StringRef keyName);
/**
* Maps the specified key to the specified value in this table.
*
* The value can be retrieved by calling the get method with a key that is
* equal to the original key.
*
* @param keyName the key
* @param value the value
* @return False if the table key already exists with a different type
*/
static bool PutBoolean(wpi::StringRef keyName, bool value);
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
static bool SetDefaultBoolean(wpi::StringRef key, bool defaultValue);
/**
* Returns the value at the specified key.
*
* If the key is not found, returns the default value.
*
* @param keyName the key
* @return the value
*/
static bool GetBoolean(wpi::StringRef keyName, bool defaultValue);
/**
* Maps the specified key to the specified value in this table.
*
* The value can be retrieved by calling the get method with a key that is
* equal to the original key.
*
* @param keyName the key
* @param value the value
* @return False if the table key already exists with a different type
*/
static bool PutNumber(wpi::StringRef keyName, double value);
/**
* Gets the current value in the table, setting it if it does not exist.
*
* @param key The key.
* @param defaultValue The default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
static bool SetDefaultNumber(wpi::StringRef key, double defaultValue);
/**
* Returns the value at the specified key.
*
* If the key is not found, returns the default value.
*
* @param keyName the key
* @return the value
*/
static double GetNumber(wpi::StringRef keyName, double defaultValue);
/**
* Maps the specified key to the specified value in this table.
*
* The value can be retrieved by calling the get method with a key that is
* equal to the original key.
*
* @param keyName the key
* @param value the value
* @return False if the table key already exists with a different type
*/
static bool PutString(wpi::StringRef keyName, wpi::StringRef value);
/**
* Gets the current value in the table, setting it if it does not exist.
*
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
static bool SetDefaultString(wpi::StringRef key, wpi::StringRef defaultValue);
/**
* Returns the value at the specified key.
*
* If the key is not found, returns the default value.
*
* @param keyName the key
* @return the value
*/
static std::string GetString(wpi::StringRef keyName,
wpi::StringRef defaultValue);
/**
* Put a boolean array in the table.
*
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*
* @note The array must be of int's rather than of bool's because
* std::vector<bool> is special-cased in C++. 0 is false, any
* non-zero value is true.
*/
static bool PutBooleanArray(wpi::StringRef key, wpi::ArrayRef<int> value);
/**
* Gets the current value in the table, setting it if it does not exist.
*
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
static bool SetDefaultBooleanArray(wpi::StringRef key,
wpi::ArrayRef<int> defaultValue);
/**
* Returns the boolean array the key maps to.
*
* If the key does not exist or is of different type, it will return the
* default value.
*
* @param key The key to look up.
* @param defaultValue The value to be returned if no value is found.
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
*
* @note This makes a copy of the array. If the overhead of this is a concern,
* use GetValue() instead.
*
* @note The returned array is std::vector<int> instead of std::vector<bool>
* because std::vector<bool> is special-cased in C++. 0 is false, any
* non-zero value is true.
*/
static std::vector<int> GetBooleanArray(wpi::StringRef key,
wpi::ArrayRef<int> defaultValue);
/**
* Put a number array in the table.
*
* @param key The key to be assigned to.
* @param value The value that will be assigned.
* @return False if the table key already exists with a different type
*/
static bool PutNumberArray(wpi::StringRef key, wpi::ArrayRef<double> value);
/**
* Gets the current value in the table, setting it if it does not exist.
*
* @param key The key.
* @param defaultValue The default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
static bool SetDefaultNumberArray(wpi::StringRef key,
wpi::ArrayRef<double> defaultValue);
/**
* Returns the number array the key maps to.
*
* If the key does not exist or is of different type, it will return the
* default value.
*
* @param key The key to look up.
* @param defaultValue The value to be returned if no value is found.
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
*
* @note This makes a copy of the array. If the overhead of this is a concern,
* use GetValue() instead.
*/
static std::vector<double> GetNumberArray(wpi::StringRef key,
wpi::ArrayRef<double> defaultValue);
/**
* Put a string array in the table.
*
* @param key The key to be assigned to.
* @param value The value that will be assigned.
* @return False if the table key already exists with a different type
*/
static bool PutStringArray(wpi::StringRef key,
wpi::ArrayRef<std::string> value);
/**
* Gets the current value in the table, setting it if it does not exist.
*
* @param key The key.
* @param defaultValue The default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
static bool SetDefaultStringArray(wpi::StringRef key,
wpi::ArrayRef<std::string> defaultValue);
/**
* Returns the string array the key maps to.
*
* If the key does not exist or is of different type, it will return the
* default value.
*
* @param key The key to look up.
* @param defaultValue The value to be returned if no value is found.
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
*
* @note This makes a copy of the array. If the overhead of this is a concern,
* use GetValue() instead.
*/
static std::vector<std::string> GetStringArray(
wpi::StringRef key, wpi::ArrayRef<std::string> defaultValue);
/**
* Put a raw value (byte array) in the table.
*
* @param key The key to be assigned to.
* @param value The value that will be assigned.
* @return False if the table key already exists with a different type
*/
static bool PutRaw(wpi::StringRef key, wpi::StringRef value);
/**
* Gets the current value in the table, setting it if it does not exist.
*
* @param key The key.
* @param defaultValue The default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
static bool SetDefaultRaw(wpi::StringRef key, wpi::StringRef defaultValue);
/**
* Returns the raw value (byte array) the key maps to.
*
* If the key does not exist or is of different type, it will return the
* default value.
*
* @param key The key to look up.
* @param defaultValue The value to be returned if no value is found.
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
*
* @note This makes a copy of the raw contents. If the overhead of this is a
* concern, use GetValue() instead.
*/
static std::string GetRaw(wpi::StringRef key, wpi::StringRef defaultValue);
/**
* Maps the specified key to the specified complex value (such as an array) in
* this table.
*
* The value can be retrieved by calling the RetrieveValue method with a key
* that is equal to the original key.
*
* @param keyName the key
* @param value the value
* @return False if the table key already exists with a different type
*/
static bool PutValue(wpi::StringRef keyName,
std::shared_ptr<nt::Value> value);
/**
* Gets the current value in the table, setting it if it does not exist.
*
* @param key the key
* @param defaultValue The default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
static bool SetDefaultValue(wpi::StringRef key,
std::shared_ptr<nt::Value> defaultValue);
/**
* Retrieves the complex value (such as an array) in this table into the
* complex data object.
*
* @param keyName the key
* @param value the object to retrieve the value into
*/
static std::shared_ptr<nt::Value> GetValue(wpi::StringRef keyName);
/**
* Puts all sendable data to the dashboard.
*/
static void UpdateValues();
private:
virtual ~SmartDashboard() = default;
};
} // namespace frc