mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
[wpilibc] Use std::string_view instead of Twine (#3380)
Use fmtlib where needed for string formatting into std::string_view.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <networktables/NetworkTableEntry.h>
|
||||
@@ -14,7 +15,6 @@
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/SmallSet.h>
|
||||
#include <wpi/StringMap.h>
|
||||
#include <wpi/Twine.h>
|
||||
|
||||
#include "frc/shuffleboard/BuiltInLayouts.h"
|
||||
#include "frc/shuffleboard/LayoutType.h"
|
||||
@@ -38,7 +38,7 @@ class SimpleWidget;
|
||||
*/
|
||||
class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
public:
|
||||
explicit ShuffleboardContainer(const wpi::Twine& title);
|
||||
explicit ShuffleboardContainer(std::string_view title);
|
||||
|
||||
ShuffleboardContainer(ShuffleboardContainer&& rhs) = default;
|
||||
|
||||
@@ -58,7 +58,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @param layoutType the type of the layout, eg "List" or "Grid"
|
||||
* @return the layout
|
||||
*/
|
||||
ShuffleboardLayout& GetLayout(const wpi::Twine& title, BuiltInLayouts type);
|
||||
ShuffleboardLayout& GetLayout(std::string_view title, BuiltInLayouts type);
|
||||
|
||||
/**
|
||||
* Gets the layout with the given type and title, creating it if it does not
|
||||
@@ -68,8 +68,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @param layoutType the type of the layout, eg "List" or "Grid"
|
||||
* @return the layout
|
||||
*/
|
||||
ShuffleboardLayout& GetLayout(const wpi::Twine& title,
|
||||
const LayoutType& type);
|
||||
ShuffleboardLayout& GetLayout(std::string_view title, const LayoutType& type);
|
||||
|
||||
/**
|
||||
* Gets the layout with the given type and title, creating it if it does not
|
||||
@@ -84,8 +83,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @return the layout
|
||||
* @see #GetLayout(String, LayoutType)
|
||||
*/
|
||||
ShuffleboardLayout& GetLayout(const wpi::Twine& title,
|
||||
const wpi::Twine& type);
|
||||
ShuffleboardLayout& GetLayout(std::string_view title, std::string_view type);
|
||||
|
||||
/**
|
||||
* Gets the already-defined layout in this container with the given title.
|
||||
@@ -102,7 +100,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @return the layout with the given title
|
||||
* @throws if no layout has yet been defined with the given title
|
||||
*/
|
||||
ShuffleboardLayout& GetLayout(const wpi::Twine& title);
|
||||
ShuffleboardLayout& GetLayout(std::string_view title);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display the given sendable.
|
||||
@@ -113,7 +111,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @throws IllegalArgumentException if a widget already exists in this
|
||||
* container with the given title
|
||||
*/
|
||||
ComplexWidget& Add(const wpi::Twine& title, Sendable& sendable);
|
||||
ComplexWidget& Add(std::string_view title, Sendable& sendable);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display the given video stream.
|
||||
@@ -124,7 +122,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @throws IllegalArgumentException if a widget already exists in this
|
||||
* container with the given title
|
||||
*/
|
||||
ComplexWidget& Add(const wpi::Twine& title, const cs::VideoSource& video);
|
||||
ComplexWidget& Add(std::string_view title, const cs::VideoSource& video);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display the given sendable.
|
||||
@@ -157,7 +155,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* container with the given title
|
||||
* @see #addPersistent(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& Add(const wpi::Twine& title,
|
||||
SimpleWidget& Add(std::string_view title,
|
||||
std::shared_ptr<nt::Value> defaultValue);
|
||||
|
||||
/**
|
||||
@@ -170,7 +168,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* container with the given title
|
||||
* @see #addPersistent(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& Add(const wpi::Twine& title, bool defaultValue);
|
||||
SimpleWidget& Add(std::string_view title, bool defaultValue);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display the given data.
|
||||
@@ -182,7 +180,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* container with the given title
|
||||
* @see #addPersistent(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& Add(const wpi::Twine& title, double defaultValue);
|
||||
SimpleWidget& Add(std::string_view title, double defaultValue);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display the given data.
|
||||
@@ -194,7 +192,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* container with the given title
|
||||
* @see #addPersistent(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& Add(const wpi::Twine& title, int defaultValue);
|
||||
SimpleWidget& Add(std::string_view title, int defaultValue);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display the given data.
|
||||
@@ -206,7 +204,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* container with the given title
|
||||
* @see #addPersistent(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& Add(const wpi::Twine& title, const wpi::Twine& defaultValue);
|
||||
SimpleWidget& Add(std::string_view title, std::string_view defaultValue);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display the given data.
|
||||
@@ -218,7 +216,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* container with the given title
|
||||
* @see #addPersistent(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& Add(const wpi::Twine& title, const char* defaultValue);
|
||||
SimpleWidget& Add(std::string_view title, const char* defaultValue);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display the given data.
|
||||
@@ -230,7 +228,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* container with the given title
|
||||
* @see #addPersistent(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& Add(const wpi::Twine& title, wpi::ArrayRef<bool> defaultValue);
|
||||
SimpleWidget& Add(std::string_view title, wpi::ArrayRef<bool> defaultValue);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display the given data.
|
||||
@@ -242,8 +240,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* container with the given title
|
||||
* @see #addPersistent(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& Add(const wpi::Twine& title,
|
||||
wpi::ArrayRef<double> defaultValue);
|
||||
SimpleWidget& Add(std::string_view title, wpi::ArrayRef<double> defaultValue);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display the given data.
|
||||
@@ -255,7 +252,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* container with the given title
|
||||
* @see #addPersistent(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& Add(const wpi::Twine& title,
|
||||
SimpleWidget& Add(std::string_view title,
|
||||
wpi::ArrayRef<std::string> defaultValue);
|
||||
|
||||
/**
|
||||
@@ -269,7 +266,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @return a widget to display data
|
||||
*/
|
||||
SuppliedValueWidget<std::string>& AddString(
|
||||
const wpi::Twine& title, std::function<std::string()> supplier);
|
||||
std::string_view title, std::function<std::string()> supplier);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container. The widget will display the data provided
|
||||
@@ -281,7 +278,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @param valueSupplier the supplier for values
|
||||
* @return a widget to display data
|
||||
*/
|
||||
SuppliedValueWidget<double>& AddNumber(const wpi::Twine& title,
|
||||
SuppliedValueWidget<double>& AddNumber(std::string_view title,
|
||||
std::function<double()> supplier);
|
||||
|
||||
/**
|
||||
@@ -294,7 +291,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @param valueSupplier the supplier for values
|
||||
* @return a widget to display data
|
||||
*/
|
||||
SuppliedValueWidget<bool>& AddBoolean(const wpi::Twine& title,
|
||||
SuppliedValueWidget<bool>& AddBoolean(std::string_view title,
|
||||
std::function<bool()> supplier);
|
||||
|
||||
/**
|
||||
@@ -308,7 +305,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @return a widget to display data
|
||||
*/
|
||||
SuppliedValueWidget<std::vector<std::string>>& AddStringArray(
|
||||
const wpi::Twine& title,
|
||||
std::string_view title,
|
||||
std::function<std::vector<std::string>()> supplier);
|
||||
|
||||
/**
|
||||
@@ -322,7 +319,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @return a widget to display data
|
||||
*/
|
||||
SuppliedValueWidget<std::vector<double>>& AddNumberArray(
|
||||
const wpi::Twine& title, std::function<std::vector<double>()> supplier);
|
||||
std::string_view title, std::function<std::vector<double>()> supplier);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container. The widget will display the data provided
|
||||
@@ -335,7 +332,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @return a widget to display data
|
||||
*/
|
||||
SuppliedValueWidget<std::vector<int>>& AddBooleanArray(
|
||||
const wpi::Twine& title, std::function<std::vector<int>()> supplier);
|
||||
std::string_view title, std::function<std::vector<int>()> supplier);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container. The widget will display the data provided
|
||||
@@ -347,8 +344,8 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @param valueSupplier the supplier for values
|
||||
* @return a widget to display data
|
||||
*/
|
||||
SuppliedValueWidget<wpi::StringRef>& AddRaw(
|
||||
const wpi::Twine& title, std::function<wpi::StringRef()> supplier);
|
||||
SuppliedValueWidget<std::string_view>& AddRaw(
|
||||
std::string_view title, std::function<std::string_view()> supplier);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display a simple piece of data.
|
||||
@@ -362,7 +359,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @return a widget to display the sendable data
|
||||
* @see #add(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& AddPersistent(const wpi::Twine& title,
|
||||
SimpleWidget& AddPersistent(std::string_view title,
|
||||
std::shared_ptr<nt::Value> defaultValue);
|
||||
|
||||
/**
|
||||
@@ -377,7 +374,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @return a widget to display the sendable data
|
||||
* @see #add(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& AddPersistent(const wpi::Twine& title, bool defaultValue);
|
||||
SimpleWidget& AddPersistent(std::string_view title, bool defaultValue);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display a simple piece of data.
|
||||
@@ -391,7 +388,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @return a widget to display the sendable data
|
||||
* @see #add(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& AddPersistent(const wpi::Twine& title, double defaultValue);
|
||||
SimpleWidget& AddPersistent(std::string_view title, double defaultValue);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display a simple piece of data.
|
||||
@@ -405,7 +402,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @return a widget to display the sendable data
|
||||
* @see #add(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& AddPersistent(const wpi::Twine& title, int defaultValue);
|
||||
SimpleWidget& AddPersistent(std::string_view title, int defaultValue);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display a simple piece of data.
|
||||
@@ -419,8 +416,8 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @return a widget to display the sendable data
|
||||
* @see #add(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& AddPersistent(const wpi::Twine& title,
|
||||
const wpi::Twine& defaultValue);
|
||||
SimpleWidget& AddPersistent(std::string_view title,
|
||||
std::string_view defaultValue);
|
||||
|
||||
/**
|
||||
* Adds a widget to this container to display a simple piece of data.
|
||||
@@ -434,7 +431,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @return a widget to display the sendable data
|
||||
* @see #add(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& AddPersistent(const wpi::Twine& title,
|
||||
SimpleWidget& AddPersistent(std::string_view title,
|
||||
wpi::ArrayRef<bool> defaultValue);
|
||||
|
||||
/**
|
||||
@@ -449,7 +446,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @return a widget to display the sendable data
|
||||
* @see #add(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& AddPersistent(const wpi::Twine& title,
|
||||
SimpleWidget& AddPersistent(std::string_view title,
|
||||
wpi::ArrayRef<double> defaultValue);
|
||||
|
||||
/**
|
||||
@@ -464,7 +461,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
* @return a widget to display the sendable data
|
||||
* @see #add(String, Object) add(String title, Object defaultValue)
|
||||
*/
|
||||
SimpleWidget& AddPersistent(const wpi::Twine& title,
|
||||
SimpleWidget& AddPersistent(std::string_view title,
|
||||
wpi::ArrayRef<std::string> defaultValue);
|
||||
|
||||
void EnableIfActuator() override;
|
||||
@@ -484,7 +481,7 @@ class ShuffleboardContainer : public virtual ShuffleboardValue {
|
||||
*
|
||||
* @return True if title isn't in use; false otherwise.
|
||||
*/
|
||||
void CheckTitle(const wpi::Twine& title);
|
||||
void CheckTitle(std::string_view title);
|
||||
|
||||
friend class SimpleWidget;
|
||||
};
|
||||
@@ -505,7 +502,7 @@ inline frc::ComplexWidget& frc::ShuffleboardContainer::Add(
|
||||
}
|
||||
|
||||
inline frc::ComplexWidget& frc::ShuffleboardContainer::Add(
|
||||
const wpi::Twine& title, const cs::VideoSource& video) {
|
||||
std::string_view title, const cs::VideoSource& video) {
|
||||
return Add(title, frc::SendableCameraWrapper::Wrap(video));
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user