[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:
Peter Johnson
2021-05-26 17:44:18 -07:00
committed by GitHub
parent 50915cb7ed
commit 4e2c3051be
76 changed files with 387 additions and 419 deletions

View File

@@ -7,6 +7,7 @@
#include <functional>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
#include <networktables/NetworkTable.h>
@@ -14,7 +15,6 @@
#include <networktables/NetworkTableValue.h>
#include <wpi/ArrayRef.h>
#include <wpi/SmallVector.h>
#include <wpi/Twine.h>
namespace frc {
@@ -28,7 +28,7 @@ class SendableBuilder {
*
* @param type data type
*/
virtual void SetSmartDashboardType(const wpi::Twine& type) = 0;
virtual void SetSmartDashboardType(std::string_view type) = 0;
/**
* Set a flag indicating if this sendable should be treated as an actuator.
@@ -63,7 +63,7 @@ class SendableBuilder {
* @param key property name
* @return Network table entry
*/
virtual nt::NetworkTableEntry GetEntry(const wpi::Twine& key) = 0;
virtual nt::NetworkTableEntry GetEntry(std::string_view key) = 0;
/**
* Add a boolean property.
@@ -72,7 +72,7 @@ class SendableBuilder {
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
virtual void AddBooleanProperty(const wpi::Twine& key,
virtual void AddBooleanProperty(std::string_view key,
std::function<bool()> getter,
std::function<void(bool)> setter) = 0;
@@ -83,7 +83,7 @@ class SendableBuilder {
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
virtual void AddDoubleProperty(const wpi::Twine& key,
virtual void AddDoubleProperty(std::string_view key,
std::function<double()> getter,
std::function<void(double)> setter) = 0;
@@ -95,7 +95,7 @@ class SendableBuilder {
* @param setter setter function (sets new value)
*/
virtual void AddStringProperty(
const wpi::Twine& key, std::function<std::string()> getter,
std::string_view key, std::function<std::string()> getter,
std::function<void(wpi::StringRef)> setter) = 0;
/**
@@ -106,7 +106,7 @@ class SendableBuilder {
* @param setter setter function (sets new value)
*/
virtual void AddBooleanArrayProperty(
const wpi::Twine& key, std::function<std::vector<int>()> getter,
std::string_view key, std::function<std::vector<int>()> getter,
std::function<void(wpi::ArrayRef<int>)> setter) = 0;
/**
@@ -117,7 +117,7 @@ class SendableBuilder {
* @param setter setter function (sets new value)
*/
virtual void AddDoubleArrayProperty(
const wpi::Twine& key, std::function<std::vector<double>()> getter,
std::string_view key, std::function<std::vector<double>()> getter,
std::function<void(wpi::ArrayRef<double>)> setter) = 0;
/**
@@ -128,7 +128,7 @@ class SendableBuilder {
* @param setter setter function (sets new value)
*/
virtual void AddStringArrayProperty(
const wpi::Twine& key, std::function<std::vector<std::string>()> getter,
std::string_view key, std::function<std::vector<std::string>()> getter,
std::function<void(wpi::ArrayRef<std::string>)> setter) = 0;
/**
@@ -138,7 +138,7 @@ class SendableBuilder {
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
virtual void AddRawProperty(const wpi::Twine& key,
virtual void AddRawProperty(std::string_view key,
std::function<std::string()> getter,
std::function<void(wpi::StringRef)> setter) = 0;
@@ -150,7 +150,7 @@ class SendableBuilder {
* @param setter setter function (sets new value)
*/
virtual void AddValueProperty(
const wpi::Twine& key, std::function<std::shared_ptr<nt::Value>()> getter,
std::string_view key, std::function<std::shared_ptr<nt::Value>()> getter,
std::function<void(std::shared_ptr<nt::Value>)> setter) = 0;
/**
@@ -161,7 +161,7 @@ class SendableBuilder {
* @param setter setter function (sets new value)
*/
virtual void AddSmallStringProperty(
const wpi::Twine& key,
std::string_view key,
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
std::function<void(wpi::StringRef)> setter) = 0;
@@ -173,7 +173,7 @@ class SendableBuilder {
* @param setter setter function (sets new value)
*/
virtual void AddSmallBooleanArrayProperty(
const wpi::Twine& key,
std::string_view key,
std::function<wpi::ArrayRef<int>(wpi::SmallVectorImpl<int>& buf)> getter,
std::function<void(wpi::ArrayRef<int>)> setter) = 0;
@@ -185,7 +185,7 @@ class SendableBuilder {
* @param setter setter function (sets new value)
*/
virtual void AddSmallDoubleArrayProperty(
const wpi::Twine& key,
std::string_view key,
std::function<wpi::ArrayRef<double>(wpi::SmallVectorImpl<double>& buf)>
getter,
std::function<void(wpi::ArrayRef<double>)> setter) = 0;
@@ -198,7 +198,7 @@ class SendableBuilder {
* @param setter setter function (sets new value)
*/
virtual void AddSmallStringArrayProperty(
const wpi::Twine& key,
std::string_view key,
std::function<
wpi::ArrayRef<std::string>(wpi::SmallVectorImpl<std::string>& buf)>
getter,
@@ -212,7 +212,7 @@ class SendableBuilder {
* @param setter setter function (sets new value)
*/
virtual void AddSmallRawProperty(
const wpi::Twine& key,
std::string_view key,
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
std::function<void(wpi::StringRef)> setter) = 0;