[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 <utility>
#include <vector>
@@ -15,7 +16,6 @@
#include <networktables/NetworkTableValue.h>
#include <wpi/ArrayRef.h>
#include <wpi/SmallVector.h>
#include <wpi/Twine.h>
#include "frc/smartdashboard/SendableBuilder.h"
@@ -86,73 +86,72 @@ class SendableBuilderImpl : public SendableBuilder {
*/
void ClearProperties();
void SetSmartDashboardType(const wpi::Twine& type) override;
void SetSmartDashboardType(std::string_view type) override;
void SetActuator(bool value) override;
void SetSafeState(std::function<void()> func) override;
void SetUpdateTable(std::function<void()> func) override;
nt::NetworkTableEntry GetEntry(const wpi::Twine& key) override;
nt::NetworkTableEntry GetEntry(std::string_view key) override;
void AddBooleanProperty(const wpi::Twine& key, std::function<bool()> getter,
void AddBooleanProperty(std::string_view key, std::function<bool()> getter,
std::function<void(bool)> setter) override;
void AddDoubleProperty(const wpi::Twine& key, std::function<double()> getter,
void AddDoubleProperty(std::string_view key, std::function<double()> getter,
std::function<void(double)> setter) override;
void AddStringProperty(const wpi::Twine& key,
void AddStringProperty(std::string_view 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::string_view 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::string_view 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::string_view 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,
void AddRawProperty(std::string_view 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::string_view 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::string_view key,
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
std::function<void(wpi::StringRef)> setter) override;
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) override;
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) override;
void AddSmallStringArrayProperty(
const wpi::Twine& key,
std::string_view 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::string_view 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)
Property(nt::NetworkTable& table, std::string_view key)
: entry(table.GetEntry(key)) {}
Property(const Property&) = delete;