2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
2021-05-26 17:44:18 -07:00
|
|
|
#include <string_view>
|
2017-12-04 23:28:33 -08:00
|
|
|
#include <vector>
|
|
|
|
|
|
2021-06-13 16:38:05 -07:00
|
|
|
#include "wpi/SmallVector.h"
|
|
|
|
|
#include "wpi/span.h"
|
2017-12-04 23:28:33 -08:00
|
|
|
|
2021-06-13 16:38:05 -07:00
|
|
|
namespace wpi {
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
class SendableBuilder {
|
|
|
|
|
public:
|
2021-06-13 16:38:05 -07:00
|
|
|
/**
|
|
|
|
|
* The backend kinds used for the sendable builder.
|
|
|
|
|
*/
|
|
|
|
|
enum BackendKind { kUnknown, kNetworkTables };
|
|
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
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
|
|
|
|
|
*/
|
2021-05-26 17:44:18 -07:00
|
|
|
virtual void SetSmartDashboardType(std::string_view type) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
2018-07-28 14:04:46 -07:00
|
|
|
/**
|
|
|
|
|
* Set a flag indicating if this sendable should be treated as an actuator.
|
|
|
|
|
* By default this flag is false.
|
|
|
|
|
*
|
|
|
|
|
* @param value true if actuator, false if not
|
|
|
|
|
*/
|
|
|
|
|
virtual void SetActuator(bool value) = 0;
|
|
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a boolean property.
|
|
|
|
|
*
|
|
|
|
|
* @param key property name
|
|
|
|
|
* @param getter getter function (returns current value)
|
|
|
|
|
* @param setter setter function (sets new value)
|
|
|
|
|
*/
|
2021-05-26 17:44:18 -07:00
|
|
|
virtual void AddBooleanProperty(std::string_view key,
|
2017-12-04 23:28:33 -08:00
|
|
|
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)
|
|
|
|
|
*/
|
2021-05-26 17:44:18 -07:00
|
|
|
virtual void AddDoubleProperty(std::string_view key,
|
2017-12-04 23:28:33 -08:00
|
|
|
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(
|
2021-05-26 17:44:18 -07:00
|
|
|
std::string_view key, std::function<std::string()> getter,
|
2021-06-06 16:13:58 -07:00
|
|
|
std::function<void(std::string_view)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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(
|
2021-05-26 17:44:18 -07:00
|
|
|
std::string_view key, std::function<std::vector<int>()> getter,
|
2021-06-06 19:51:14 -07:00
|
|
|
std::function<void(wpi::span<const int>)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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(
|
2021-05-26 17:44:18 -07:00
|
|
|
std::string_view key, std::function<std::vector<double>()> getter,
|
2021-06-06 19:51:14 -07:00
|
|
|
std::function<void(wpi::span<const double>)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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(
|
2021-05-26 17:44:18 -07:00
|
|
|
std::string_view key, std::function<std::vector<std::string>()> getter,
|
2021-06-06 19:51:14 -07:00
|
|
|
std::function<void(wpi::span<const std::string>)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a raw property.
|
|
|
|
|
*
|
|
|
|
|
* @param key property name
|
|
|
|
|
* @param getter getter function (returns current value)
|
|
|
|
|
* @param setter setter function (sets new value)
|
|
|
|
|
*/
|
2021-05-26 17:44:18 -07:00
|
|
|
virtual void AddRawProperty(std::string_view key,
|
2017-12-04 23:28:33 -08:00
|
|
|
std::function<std::string()> getter,
|
2021-06-06 16:13:58 -07:00
|
|
|
std::function<void(std::string_view)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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(
|
2021-05-26 17:44:18 -07:00
|
|
|
std::string_view key,
|
2021-06-06 16:13:58 -07:00
|
|
|
std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
|
|
|
|
|
std::function<void(std::string_view)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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(
|
2021-05-26 17:44:18 -07:00
|
|
|
std::string_view key,
|
2021-06-06 19:51:14 -07:00
|
|
|
std::function<wpi::span<const int>(wpi::SmallVectorImpl<int>& buf)>
|
|
|
|
|
getter,
|
|
|
|
|
std::function<void(wpi::span<const int>)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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(
|
2021-05-26 17:44:18 -07:00
|
|
|
std::string_view key,
|
2021-06-06 19:51:14 -07:00
|
|
|
std::function<wpi::span<const double>(wpi::SmallVectorImpl<double>& buf)>
|
2017-12-04 23:28:33 -08:00
|
|
|
getter,
|
2021-06-06 19:51:14 -07:00
|
|
|
std::function<void(wpi::span<const double>)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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(
|
2021-05-26 17:44:18 -07:00
|
|
|
std::string_view key,
|
2017-12-04 23:28:33 -08:00
|
|
|
std::function<
|
2021-06-06 19:51:14 -07:00
|
|
|
wpi::span<const std::string>(wpi::SmallVectorImpl<std::string>& buf)>
|
2017-12-04 23:28:33 -08:00
|
|
|
getter,
|
2021-06-06 19:51:14 -07:00
|
|
|
std::function<void(wpi::span<const std::string>)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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(
|
2021-05-26 17:44:18 -07:00
|
|
|
std::string_view key,
|
2021-06-06 16:13:58 -07:00
|
|
|
std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
|
|
|
|
|
std::function<void(std::string_view)> setter) = 0;
|
2020-12-05 23:19:15 -08:00
|
|
|
|
|
|
|
|
/**
|
2021-06-13 16:38:05 -07:00
|
|
|
* Gets the kind of backend being used.
|
|
|
|
|
*
|
|
|
|
|
* @return Backend kind
|
|
|
|
|
*/
|
|
|
|
|
virtual BackendKind GetBackendKind() const = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return whether this sendable has been published.
|
|
|
|
|
*
|
|
|
|
|
* @return True if it has been published, false if not.
|
|
|
|
|
*/
|
|
|
|
|
virtual bool IsPublished() const = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the published values by calling the getters for all properties.
|
|
|
|
|
*/
|
|
|
|
|
virtual void Update() = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clear properties.
|
2020-12-05 23:19:15 -08:00
|
|
|
*/
|
2021-06-13 16:38:05 -07:00
|
|
|
virtual void ClearProperties() = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
};
|
|
|
|
|
|
2021-06-13 16:38:05 -07:00
|
|
|
} // namespace wpi
|