Use std::string_view and fmtlib across all libraries (#3402)

- Twine, StringRef, Format, and NativeFormatting have been removed
- Logging now uses fmtlib style formatting
- Nearly all uses of wpi::outs/errs have been replaced with fmt::print() or
std::puts()/std::fputs() (for unformatted strings).
- A wpi/fmt/raw_ostream.h header has been added to enable
fmt::print() with wpi::raw_ostream
This commit is contained in:
Peter Johnson
2021-06-06 16:13:58 -07:00
committed by GitHub
parent 4f1cecb8e7
commit b2c3b2dd8e
441 changed files with 5061 additions and 9749 deletions

View File

@@ -8,6 +8,7 @@
#include <memory>
#include <string>
#include <string_view>
#include <vector>
#include <networktables/NetworkTable.h>
@@ -53,7 +54,8 @@ class Preferences {
* @param defaultValue the value to return if none exists in the table
* @return either the value in the table, or the defaultValue
*/
std::string GetString(wpi::StringRef key, wpi::StringRef defaultValue = "");
std::string GetString(std::string_view key,
std::string_view defaultValue = "");
/**
* Returns the int at the given key. If this table does not have a value for
@@ -63,7 +65,7 @@ class Preferences {
* @param defaultValue the value to return if none exists in the table
* @return either the value in the table, or the defaultValue
*/
int GetInt(wpi::StringRef key, int defaultValue = 0);
int GetInt(std::string_view key, int defaultValue = 0);
/**
* Returns the double at the given key. If this table does not have a value
@@ -73,7 +75,7 @@ class Preferences {
* @param defaultValue the value to return if none exists in the table
* @return either the value in the table, or the defaultValue
*/
double GetDouble(wpi::StringRef key, double defaultValue = 0.0);
double GetDouble(std::string_view key, double defaultValue = 0.0);
/**
* Returns the float at the given key. If this table does not have a value
@@ -83,7 +85,7 @@ class Preferences {
* @param defaultValue the value to return if none exists in the table
* @return either the value in the table, or the defaultValue
*/
float GetFloat(wpi::StringRef key, float defaultValue = 0.0);
float GetFloat(std::string_view key, float defaultValue = 0.0);
/**
* Returns the boolean at the given key. If this table does not have a value
@@ -93,7 +95,7 @@ class Preferences {
* @param defaultValue the value to return if none exists in the table
* @return either the value in the table, or the defaultValue
*/
bool GetBoolean(wpi::StringRef key, bool defaultValue = false);
bool GetBoolean(std::string_view key, bool defaultValue = false);
/**
* Returns the long (int64_t) at the given key. If this table does not have a
@@ -104,7 +106,7 @@ class Preferences {
* @param defaultValue the value to return if none exists in the table
* @return either the value in the table, or the defaultValue
*/
int64_t GetLong(wpi::StringRef key, int64_t defaultValue = 0);
int64_t GetLong(std::string_view key, int64_t defaultValue = 0);
/**
* Puts the given string into the preferences table.
@@ -115,7 +117,7 @@ class Preferences {
* @param key the key
* @param value the value
*/
void SetString(wpi::StringRef key, wpi::StringRef value);
void SetString(std::string_view key, std::string_view value);
/**
* Puts the given string into the preferences table.
@@ -127,13 +129,13 @@ class Preferences {
* @param value the value
*/
WPI_DEPRECATED("Use SetString instead.")
void PutString(wpi::StringRef key, wpi::StringRef value);
void PutString(std::string_view key, std::string_view value);
/**
* Puts the given string into the preferences table if it doesn't
* already exist.
*/
void InitString(wpi::StringRef key, wpi::StringRef value);
void InitString(std::string_view key, std::string_view value);
/**
* Puts the given int into the preferences table.
@@ -143,7 +145,7 @@ class Preferences {
* @param key the key
* @param value the value
*/
void SetInt(wpi::StringRef key, int value);
void SetInt(std::string_view key, int value);
/**
* Puts the given int into the preferences table.
@@ -154,13 +156,13 @@ class Preferences {
* @param value the value
*/
WPI_DEPRECATED("Use SetInt instead.")
void PutInt(wpi::StringRef key, int value);
void PutInt(std::string_view key, int value);
/**
* Puts the given int into the preferences table if it doesn't
* already exist.
*/
void InitInt(wpi::StringRef key, int value);
void InitInt(std::string_view key, int value);
/**
* Puts the given double into the preferences table.
@@ -170,7 +172,7 @@ class Preferences {
* @param key the key
* @param value the value
*/
void SetDouble(wpi::StringRef key, double value);
void SetDouble(std::string_view key, double value);
/**
* Puts the given double into the preferences table.
@@ -181,13 +183,13 @@ class Preferences {
* @param value the value
*/
WPI_DEPRECATED("Use SetDouble instead.")
void PutDouble(wpi::StringRef key, double value);
void PutDouble(std::string_view key, double value);
/**
* Puts the given double into the preferences table if it doesn't
* already exist.
*/
void InitDouble(wpi::StringRef key, double value);
void InitDouble(std::string_view key, double value);
/**
* Puts the given float into the preferences table.
@@ -197,7 +199,7 @@ class Preferences {
* @param key the key
* @param value the value
*/
void SetFloat(wpi::StringRef key, float value);
void SetFloat(std::string_view key, float value);
/**
* Puts the given float into the preferences table.
@@ -208,13 +210,13 @@ class Preferences {
* @param value the value
*/
WPI_DEPRECATED("Use SetFloat instead.")
void PutFloat(wpi::StringRef key, float value);
void PutFloat(std::string_view key, float value);
/**
* Puts the given float into the preferences table if it doesn't
* already exist.
*/
void InitFloat(wpi::StringRef key, float value);
void InitFloat(std::string_view key, float value);
/**
* Puts the given boolean into the preferences table.
@@ -224,7 +226,7 @@ class Preferences {
* @param key the key
* @param value the value
*/
void SetBoolean(wpi::StringRef key, bool value);
void SetBoolean(std::string_view key, bool value);
/**
* Puts the given boolean into the preferences table.
@@ -235,13 +237,13 @@ class Preferences {
* @param value the value
*/
WPI_DEPRECATED("Use SetBoolean instead.")
void PutBoolean(wpi::StringRef key, bool value);
void PutBoolean(std::string_view key, bool value);
/**
* Puts the given boolean into the preferences table if it doesn't
* already exist.
*/
void InitBoolean(wpi::StringRef key, bool value);
void InitBoolean(std::string_view key, bool value);
/**
* Puts the given long (int64_t) into the preferences table.
@@ -251,7 +253,7 @@ class Preferences {
* @param key the key
* @param value the value
*/
void SetLong(wpi::StringRef key, int64_t value);
void SetLong(std::string_view key, int64_t value);
/**
* Puts the given long (int64_t) into the preferences table.
@@ -262,13 +264,13 @@ class Preferences {
* @param value the value
*/
WPI_DEPRECATED("Use SetLong instead.")
void PutLong(wpi::StringRef key, int64_t value);
void PutLong(std::string_view key, int64_t value);
/**
* Puts the given long into the preferences table if it doesn't
* already exist.
*/
void InitLong(wpi::StringRef key, int64_t value);
void InitLong(std::string_view key, int64_t value);
/**
* Returns whether or not there is a key with the given name.
@@ -276,14 +278,14 @@ class Preferences {
* @param key the key
* @return if there is a value at the given key
*/
bool ContainsKey(wpi::StringRef key);
bool ContainsKey(std::string_view key);
/**
* Remove a preference.
*
* @param key the key
*/
void Remove(wpi::StringRef key);
void Remove(std::string_view key);
/**
* Remove all preferences.

View File

@@ -11,7 +11,6 @@
#include <hal/Main.h>
#include <wpi/condition_variable.h>
#include <wpi/mutex.h>
#include <wpi/raw_ostream.h>
#include "frc/Errors.h"

View File

@@ -144,7 +144,7 @@ class SerialPort {
* Use Write({data, len}) to get a buffer that is shorter than the length of
* the string.
*
* @param buffer StringRef to the buffer to read the bytes from.
* @param buffer the buffer to read the bytes from.
* @return The number of bytes actually written into the port.
*/
int Write(std::string_view buffer);

View File

@@ -5,10 +5,10 @@
#pragma once
#include <chrono>
#include <string_view>
#include <hal/cpp/fpga_clock.h>
#include <wpi/StringMap.h>
#include <wpi/StringRef.h>
namespace wpi {
class raw_ostream;
@@ -48,7 +48,7 @@ class Tracer {
*
* @param epochName The name to associate with the epoch.
*/
void AddEpoch(wpi::StringRef epochName);
void AddEpoch(std::string_view epochName);
/**
* Prints list of epochs added so far and their times to the DriverStation.

View File

@@ -5,10 +5,10 @@
#pragma once
#include <functional>
#include <string_view>
#include <utility>
#include <units/time.h>
#include <wpi/StringRef.h>
#include "frc/Tracer.h"
@@ -76,7 +76,7 @@ class Watchdog {
*
* @param epochName The name to associate with the epoch.
*/
void AddEpoch(wpi::StringRef epochName);
void AddEpoch(std::string_view epochName);
/**
* Prints list of epochs added so far and their times.

View File

@@ -4,7 +4,7 @@
#pragma once
#include <wpi/StringRef.h>
#include <string_view>
namespace frc {
@@ -25,7 +25,7 @@ class LayoutType {
* Gets the string type of the layout as defined by that layout in
* Shuffleboard.
*/
wpi::StringRef GetLayoutName() const;
std::string_view GetLayoutName() const;
private:
const char* m_layoutName;

View File

@@ -6,11 +6,11 @@
#include <memory>
#include <string>
#include <string_view>
#include <networktables/NetworkTable.h>
#include <networktables/NetworkTableInstance.h>
#include <wpi/SmallVector.h>
#include <wpi/StringRef.h>
#include "frc/shuffleboard/ShuffleboardEventImportance.h"
@@ -23,10 +23,10 @@ class RecordingController final {
void StartRecording();
void StopRecording();
void SetRecordingFileNameFormat(wpi::StringRef format);
void SetRecordingFileNameFormat(std::string_view format);
void ClearRecordingFileNameFormat();
void AddEventMarker(wpi::StringRef name, wpi::StringRef description,
void AddEventMarker(std::string_view name, std::string_view description,
ShuffleboardEventImportance importance);
private:

View File

@@ -4,7 +4,7 @@
#pragma once
#include <wpi/StringRef.h>
#include <string_view>
#include "frc/shuffleboard/RecordingController.h"
#include "frc/shuffleboard/ShuffleboardEventImportance.h"
@@ -77,7 +77,7 @@ class Shuffleboard final {
* @param title the title of the tab
* @return the tab with the given title
*/
static ShuffleboardTab& GetTab(wpi::StringRef title);
static ShuffleboardTab& GetTab(std::string_view title);
/**
* Selects the tab in the dashboard with the given index in the range
@@ -93,7 +93,7 @@ class Shuffleboard final {
*
* @param title the title of the tab to select
*/
static void SelectTab(wpi::StringRef title);
static void SelectTab(std::string_view title);
/**
* Enables user control of widgets containing actuators: speed controllers,
@@ -141,7 +141,7 @@ class Shuffleboard final {
*
* @param format the format for the
*/
static void SetRecordingFileNameFormat(wpi::StringRef format);
static void SetRecordingFileNameFormat(std::string_view format);
/**
* Clears the custom name format for recording files. New recordings will use
@@ -163,7 +163,8 @@ class Shuffleboard final {
* @param description a description of the event
* @param importance the importance of the event
*/
static void AddEventMarker(wpi::StringRef name, wpi::StringRef description,
static void AddEventMarker(std::string_view name,
std::string_view description,
ShuffleboardEventImportance importance);
/**
@@ -177,7 +178,7 @@ class Shuffleboard final {
* @param name the name of the event
* @param importance the importance of the event
*/
static void AddEventMarker(wpi::StringRef name,
static void AddEventMarker(std::string_view name,
ShuffleboardEventImportance importance);
private:

View File

@@ -4,7 +4,7 @@
#pragma once
#include <wpi/StringRef.h>
#include <string_view>
namespace frc {
@@ -14,7 +14,7 @@ namespace frc {
enum ShuffleboardEventImportance { kTrivial, kLow, kNormal, kHigh, kCritical };
inline wpi::StringRef ShuffleboardEventImportanceName(
inline std::string_view ShuffleboardEventImportanceName(
ShuffleboardEventImportance importance) {
switch (importance) {
case kTrivial:

View File

@@ -5,6 +5,7 @@
#pragma once
#include <memory>
#include <string_view>
#include "frc/shuffleboard/ShuffleboardRoot.h"
#include "frc/shuffleboard/ShuffleboardTab.h"
@@ -19,7 +20,7 @@ class ShuffleboardInstance final : public ShuffleboardRoot {
ShuffleboardInstance(ShuffleboardInstance&&) = default;
ShuffleboardInstance& operator=(ShuffleboardInstance&&) = default;
frc::ShuffleboardTab& GetTab(wpi::StringRef title) override;
frc::ShuffleboardTab& GetTab(std::string_view title) override;
void Update() override;
@@ -29,7 +30,7 @@ class ShuffleboardInstance final : public ShuffleboardRoot {
void SelectTab(int index) override;
void SelectTab(wpi::StringRef) override;
void SelectTab(std::string_view) override;
private:
struct Impl;

View File

@@ -4,7 +4,7 @@
#pragma once
#include <wpi/StringRef.h>
#include <string_view>
namespace frc {
@@ -25,7 +25,7 @@ class ShuffleboardRoot {
* @param title the title of the tab
* @return the tab with the given title
*/
virtual ShuffleboardTab& GetTab(wpi::StringRef title) = 0;
virtual ShuffleboardTab& GetTab(std::string_view title) = 0;
/**
* Updates all tabs.
@@ -57,7 +57,7 @@ class ShuffleboardRoot {
*
* @param title the title of the tab to select
*/
virtual void SelectTab(wpi::StringRef title) = 0;
virtual void SelectTab(std::string_view title) = 0;
};
} // namespace frc

View File

@@ -5,9 +5,9 @@
#pragma once
#include <memory>
#include <string_view>
#include <networktables/NetworkTable.h>
#include <wpi/StringRef.h>
#include "frc/shuffleboard/ShuffleboardContainer.h"
@@ -24,7 +24,7 @@ class ShuffleboardRoot;
*/
class ShuffleboardTab final : public ShuffleboardContainer {
public:
ShuffleboardTab(ShuffleboardRoot& root, wpi::StringRef title);
ShuffleboardTab(ShuffleboardRoot& root, std::string_view title);
ShuffleboardRoot& GetRoot();

View File

@@ -4,7 +4,7 @@
#pragma once
#include <wpi/StringRef.h>
#include <string_view>
namespace frc {
@@ -25,7 +25,7 @@ class WidgetType {
* Gets the string type of the widget as defined by that widget in
* Shuffleboard.
*/
wpi::StringRef GetWidgetName() const;
std::string_view GetWidgetName() const;
private:
const char* m_widgetName;

View File

@@ -5,15 +5,15 @@
#pragma once
#include <functional>
#include <string_view>
#include <hal/Value.h>
#include <wpi/StringRef.h>
namespace frc::sim {
using NotifyCallback = std::function<void(wpi::StringRef, const HAL_Value*)>;
using NotifyCallback = std::function<void(std::string_view, const HAL_Value*)>;
using ConstBufferCallback = std::function<void(
wpi::StringRef, const unsigned char* buffer, unsigned int count)>;
std::string_view, const unsigned char* buffer, unsigned int count)>;
using CancelCallbackFunc = void (*)(int32_t index, int32_t uid);
using CancelCallbackNoIndexFunc = void (*)(int32_t uid);
using CancelCallbackChannelFunc = void (*)(int32_t index, int32_t channel,

View File

@@ -59,7 +59,7 @@ class Mechanism2d : public Sendable, public SendableHelper<Mechanism2d> {
* @param y the root y coordinate
* @return a new root object, or the existing one with the given name.
*/
MechanismRoot2d* GetRoot(wpi::StringRef name, double x, double y);
MechanismRoot2d* GetRoot(std::string_view name, double x, double y);
/**
* Set the Mechanism2d background color.

View File

@@ -14,6 +14,8 @@
#include <networktables/NetworkTable.h>
#include <wpi/StringMap.h>
#include "frc/Errors.h"
namespace frc {
/**
@@ -63,13 +65,14 @@ class MechanismObject2d {
template <typename T, typename... Args,
typename =
std::enable_if_t<std::is_convertible_v<T*, MechanismObject2d*>>>
T* Append(wpi::StringRef name, Args&&... args) {
T* Append(std::string_view name, Args&&... args) {
std::scoped_lock lock(m_mutex);
auto& obj = m_objects[name];
if (obj) {
throw std::runtime_error(("MechanismObject names must be unique! `" +
name + "` was inserted twice!")
.str());
throw FRC_MakeError(
err::Error,
"MechanismObject names must be unique! `{}` was inserted twice!",
name);
}
obj = std::make_unique<T>(name, std::forward<Args>(args)...);
T* ex = static_cast<T*>(obj.get());

View File

@@ -96,7 +96,7 @@ class SendableBuilder {
*/
virtual void AddStringProperty(
std::string_view key, std::function<std::string()> getter,
std::function<void(wpi::StringRef)> setter) = 0;
std::function<void(std::string_view)> setter) = 0;
/**
* Add a boolean array property.
@@ -140,7 +140,7 @@ class SendableBuilder {
*/
virtual void AddRawProperty(std::string_view key,
std::function<std::string()> getter,
std::function<void(wpi::StringRef)> setter) = 0;
std::function<void(std::string_view)> setter) = 0;
/**
* Add a NetworkTableValue property.
@@ -162,8 +162,8 @@ class SendableBuilder {
*/
virtual void AddSmallStringProperty(
std::string_view key,
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
std::function<void(wpi::StringRef)> setter) = 0;
std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
std::function<void(std::string_view)> setter) = 0;
/**
* Add a boolean array property (SmallVector form).
@@ -213,8 +213,8 @@ class SendableBuilder {
*/
virtual void AddSmallRawProperty(
std::string_view key,
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
std::function<void(wpi::StringRef)> setter) = 0;
std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
std::function<void(std::string_view)> setter) = 0;
/**
* Get the network table.

View File

@@ -100,7 +100,7 @@ class SendableBuilderImpl : public SendableBuilder {
void AddStringProperty(std::string_view key,
std::function<std::string()> getter,
std::function<void(wpi::StringRef)> setter) override;
std::function<void(std::string_view)> setter) override;
void AddBooleanArrayProperty(
std::string_view key, std::function<std::vector<int>()> getter,
@@ -115,7 +115,7 @@ class SendableBuilderImpl : public SendableBuilder {
std::function<void(wpi::ArrayRef<std::string>)> setter) override;
void AddRawProperty(std::string_view key, std::function<std::string()> getter,
std::function<void(wpi::StringRef)> setter) override;
std::function<void(std::string_view)> setter) override;
void AddValueProperty(
std::string_view key, std::function<std::shared_ptr<nt::Value>()> getter,
@@ -123,8 +123,8 @@ class SendableBuilderImpl : public SendableBuilder {
void AddSmallStringProperty(
std::string_view key,
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
std::function<void(wpi::StringRef)> setter) override;
std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
std::function<void(std::string_view)> setter) override;
void AddSmallBooleanArrayProperty(
std::string_view key,
@@ -146,8 +146,8 @@ class SendableBuilderImpl : public SendableBuilder {
void AddSmallRawProperty(
std::string_view key,
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
std::function<void(wpi::StringRef)> setter) override;
std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
std::function<void(std::string_view)> setter) override;
private:
struct Property {

View File

@@ -5,9 +5,9 @@
#pragma once
#include <memory>
#include <string_view>
#include <wpi/StringMap.h>
#include <wpi/StringRef.h>
#include <wpi/deprecated.h>
#include "frc/smartdashboard/SendableBuilder.h"
@@ -56,7 +56,7 @@ class SendableChooser : public SendableChooserBase {
* @param name the name of the option
* @param object the option
*/
void AddOption(wpi::StringRef name, T object);
void AddOption(std::string_view name, T object);
/**
* Add the given object to the list of options and marks it as the default.
@@ -67,7 +67,7 @@ class SendableChooser : public SendableChooserBase {
* @param name the name of the option
* @param object the option
*/
void SetDefaultOption(wpi::StringRef name, T object);
void SetDefaultOption(std::string_view name, T object);
/**
* Adds the given object to the list of options.
@@ -75,13 +75,13 @@ class SendableChooser : public SendableChooserBase {
* On the SmartDashboard on the desktop, the object will appear as the given
* name.
*
* @deprecated use AddOption(wpi::StringRef name, T object) instead.
* @deprecated use AddOption(std::string_view name, T object) instead.
*
* @param name the name of the option
* @param object the option
*/
WPI_DEPRECATED("use AddOption() instead")
void AddObject(wpi::StringRef name, T object) { AddOption(name, object); }
void AddObject(std::string_view name, T object) { AddOption(name, object); }
/**
* Add the given object to the list of options and marks it as the default.
@@ -89,13 +89,13 @@ class SendableChooser : public SendableChooserBase {
* Functionally, this is very close to AddOption() except that it will use
* this as the default option if none other is explicitly selected.
*
* @deprecated use SetDefaultOption(wpi::StringRef name, T object) instead.
* @deprecated use SetDefaultOption(std::string_view name, T object) instead.
*
* @param name the name of the option
* @param object the option
*/
WPI_DEPRECATED("use SetDefaultOption() instead")
void AddDefault(wpi::StringRef name, T object) {
void AddDefault(std::string_view name, T object) {
SetDefaultOption(name, object);
}

View File

@@ -7,22 +7,21 @@
#include <algorithm>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include <wpi/StringRef.h>
#include "frc/smartdashboard/SendableChooser.h"
namespace frc {
template <class T>
void SendableChooser<T>::AddOption(wpi::StringRef name, T object) {
void SendableChooser<T>::AddOption(std::string_view name, T object) {
m_choices[name] = std::move(object);
}
template <class T>
void SendableChooser<T>::SetDefaultOption(wpi::StringRef name, T object) {
void SendableChooser<T>::SetDefaultOption(std::string_view name, T object) {
m_defaultChoice = name;
AddOption(name, std::move(object));
}
@@ -53,7 +52,7 @@ void SendableChooser<T>::InitSendable(SendableBuilder& builder) {
[=]() {
std::vector<std::string> keys;
for (const auto& choice : m_choices) {
keys.push_back(choice.first());
keys.emplace_back(choice.first());
}
// Unlike std::map, wpi::StringMap elements
@@ -65,17 +64,17 @@ void SendableChooser<T>::InitSendable(SendableBuilder& builder) {
nullptr);
builder.AddSmallStringProperty(
kDefault,
[=](wpi::SmallVectorImpl<char>&) -> wpi::StringRef {
[=](wpi::SmallVectorImpl<char>&) -> std::string_view {
return m_defaultChoice;
},
nullptr);
builder.AddSmallStringProperty(
kActive,
[=](wpi::SmallVectorImpl<char>& buf) -> wpi::StringRef {
[=](wpi::SmallVectorImpl<char>& buf) -> std::string_view {
std::scoped_lock lock(m_mutex);
if (m_haveSelected) {
buf.assign(m_selected.begin(), m_selected.end());
return wpi::StringRef(buf.data(), buf.size());
return {buf.data(), buf.size()};
} else {
return m_defaultChoice;
}
@@ -85,7 +84,7 @@ void SendableChooser<T>::InitSendable(SendableBuilder& builder) {
std::scoped_lock lock(m_mutex);
m_activeEntries.emplace_back(builder.GetEntry(kActive));
}
builder.AddStringProperty(kSelected, nullptr, [=](wpi::StringRef val) {
builder.AddStringProperty(kSelected, nullptr, [=](std::string_view val) {
std::scoped_lock lock(m_mutex);
m_haveSelected = true;
m_selected = val;

View File

@@ -298,8 +298,8 @@ class SendableRegistry {
* Data passed to ForeachLiveWindow() callback function
*/
struct CallbackData {
CallbackData(Sendable* sendable_, wpi::StringRef name_,
wpi::StringRef subsystem_, Sendable* parent_,
CallbackData(Sendable* sendable_, std::string_view name_,
std::string_view subsystem_, Sendable* parent_,
std::shared_ptr<void>& data_, SendableBuilderImpl& builder_)
: sendable(sendable_),
name(name_),
@@ -309,8 +309,8 @@ class SendableRegistry {
builder(builder_) {}
Sendable* sendable;
wpi::StringRef name;
wpi::StringRef subsystem;
std::string_view name;
std::string_view subsystem;
Sendable* parent;
std::shared_ptr<void>& data;
SendableBuilderImpl& builder;

View File

@@ -6,6 +6,7 @@
#include <memory>
#include <string>
#include <string_view>
#include <vector>
#include <networktables/NetworkTableEntry.h>
@@ -27,7 +28,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @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);
static bool ContainsKey(std::string_view key);
/**
* @param types bitmask of types; 0 is treated as a "don't care".
@@ -40,7 +41,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
*
* @param key the key to make persistent
*/
static void SetPersistent(wpi::StringRef key);
static void SetPersistent(std::string_view key);
/**
* Stop making a key's value persistent through program restarts.
@@ -48,7 +49,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
*
* @param key the key name
*/
static void ClearPersistent(wpi::StringRef key);
static void ClearPersistent(std::string_view key);
/**
* Returns whether the value is persistent through program restarts.
@@ -56,7 +57,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
*
* @param key the key name
*/
static bool IsPersistent(wpi::StringRef key);
static bool IsPersistent(std::string_view key);
/**
* Sets flags on the specified key in this table. The key can
@@ -65,7 +66,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @param key the key name
* @param flags the flags to set (bitmask)
*/
static void SetFlags(wpi::StringRef key, unsigned int flags);
static void SetFlags(std::string_view key, unsigned int flags);
/**
* Clears flags on the specified key in this table. The key can
@@ -74,7 +75,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @param key the key name
* @param flags the flags to clear (bitmask)
*/
static void ClearFlags(wpi::StringRef key, unsigned int flags);
static void ClearFlags(std::string_view key, unsigned int flags);
/**
* Returns the flags for the specified key.
@@ -82,14 +83,14 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @param key the key name
* @return the flags, or 0 if the key is not defined
*/
static unsigned int GetFlags(wpi::StringRef key);
static unsigned int GetFlags(std::string_view key);
/**
* Deletes the specified key in this table.
*
* @param key the key name
*/
static void Delete(wpi::StringRef key);
static void Delete(std::string_view key);
/**
* Returns an NT Entry mapping to the specified key
@@ -99,7 +100,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @param key the key
* @return the entry for the key
*/
static nt::NetworkTableEntry GetEntry(wpi::StringRef key);
static nt::NetworkTableEntry GetEntry(std::string_view key);
/**
* Maps the specified key to the specified value in this table.
@@ -113,7 +114,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @param keyName the key
* @param value the value
*/
static void PutData(wpi::StringRef key, Sendable* data);
static void PutData(std::string_view key, Sendable* data);
/**
* Maps the specified key (where the key is the name of the Sendable)
@@ -135,7 +136,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @param keyName the key
* @return the value
*/
static Sendable* GetData(wpi::StringRef keyName);
static Sendable* GetData(std::string_view keyName);
/**
* Maps the specified key to the specified value in this table.
@@ -147,7 +148,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @param value the value
* @return False if the table key already exists with a different type
*/
static bool PutBoolean(wpi::StringRef keyName, bool value);
static bool PutBoolean(std::string_view keyName, bool value);
/**
* Gets the current value in the table, setting it if it does not exist.
@@ -155,7 +156,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @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);
static bool SetDefaultBoolean(std::string_view key, bool defaultValue);
/**
* Returns the value at the specified key.
@@ -165,7 +166,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @param keyName the key
* @return the value
*/
static bool GetBoolean(wpi::StringRef keyName, bool defaultValue);
static bool GetBoolean(std::string_view keyName, bool defaultValue);
/**
* Maps the specified key to the specified value in this table.
@@ -177,7 +178,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @param value the value
* @return False if the table key already exists with a different type
*/
static bool PutNumber(wpi::StringRef keyName, double value);
static bool PutNumber(std::string_view keyName, double value);
/**
* Gets the current value in the table, setting it if it does not exist.
@@ -186,7 +187,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @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);
static bool SetDefaultNumber(std::string_view key, double defaultValue);
/**
* Returns the value at the specified key.
@@ -196,7 +197,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @param keyName the key
* @return the value
*/
static double GetNumber(wpi::StringRef keyName, double defaultValue);
static double GetNumber(std::string_view keyName, double defaultValue);
/**
* Maps the specified key to the specified value in this table.
@@ -208,7 +209,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @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);
static bool PutString(std::string_view keyName, std::string_view value);
/**
* Gets the current value in the table, setting it if it does not exist.
@@ -217,7 +218,8 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @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);
static bool SetDefaultString(std::string_view key,
std::string_view defaultValue);
/**
* Returns the value at the specified key.
@@ -227,8 +229,8 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @param keyName the key
* @return the value
*/
static std::string GetString(wpi::StringRef keyName,
wpi::StringRef defaultValue);
static std::string GetString(std::string_view keyName,
std::string_view defaultValue);
/**
* Put a boolean array in the table.
@@ -241,7 +243,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* 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);
static bool PutBooleanArray(std::string_view key, wpi::ArrayRef<int> value);
/**
* Gets the current value in the table, setting it if it does not exist.
@@ -250,7 +252,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @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,
static bool SetDefaultBooleanArray(std::string_view key,
wpi::ArrayRef<int> defaultValue);
/**
@@ -271,7 +273,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* 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,
static std::vector<int> GetBooleanArray(std::string_view key,
wpi::ArrayRef<int> defaultValue);
/**
@@ -281,7 +283,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @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);
static bool PutNumberArray(std::string_view key, wpi::ArrayRef<double> value);
/**
* Gets the current value in the table, setting it if it does not exist.
@@ -290,7 +292,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @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,
static bool SetDefaultNumberArray(std::string_view key,
wpi::ArrayRef<double> defaultValue);
/**
@@ -307,7 +309,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @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,
static std::vector<double> GetNumberArray(std::string_view key,
wpi::ArrayRef<double> defaultValue);
/**
@@ -317,7 +319,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @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,
static bool PutStringArray(std::string_view key,
wpi::ArrayRef<std::string> value);
/**
@@ -327,7 +329,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @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,
static bool SetDefaultStringArray(std::string_view key,
wpi::ArrayRef<std::string> defaultValue);
/**
@@ -345,7 +347,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* use GetValue() instead.
*/
static std::vector<std::string> GetStringArray(
wpi::StringRef key, wpi::ArrayRef<std::string> defaultValue);
std::string_view key, wpi::ArrayRef<std::string> defaultValue);
/**
* Put a raw value (byte array) in the table.
@@ -354,7 +356,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @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);
static bool PutRaw(std::string_view key, std::string_view value);
/**
* Gets the current value in the table, setting it if it does not exist.
@@ -363,7 +365,8 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @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);
static bool SetDefaultRaw(std::string_view key,
std::string_view defaultValue);
/**
* Returns the raw value (byte array) the key maps to.
@@ -379,7 +382,8 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @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);
static std::string GetRaw(std::string_view key,
std::string_view defaultValue);
/**
* Maps the specified key to the specified complex value (such as an array) in
@@ -392,7 +396,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @param value the value
* @return False if the table key already exists with a different type
*/
static bool PutValue(wpi::StringRef keyName,
static bool PutValue(std::string_view keyName,
std::shared_ptr<nt::Value> value);
/**
@@ -402,7 +406,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @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,
static bool SetDefaultValue(std::string_view key,
std::shared_ptr<nt::Value> defaultValue);
/**
@@ -412,7 +416,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
* @param keyName the key
* @param value the object to retrieve the value into
*/
static std::shared_ptr<nt::Value> GetValue(wpi::StringRef keyName);
static std::shared_ptr<nt::Value> GetValue(std::string_view keyName);
/**
* Posts a task from a listener to the ListenerExecutor, so that it can be run