mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
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:
@@ -9,13 +9,11 @@
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/SmallVector.h>
|
||||
#include <wpi/StringMap.h>
|
||||
#include <wpi/StringRef.h>
|
||||
#include <wpi/Twine.h>
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "PropertyImpl.h"
|
||||
@@ -23,6 +21,8 @@
|
||||
|
||||
namespace wpi {
|
||||
class Logger;
|
||||
template <typename T>
|
||||
class SmallVectorImpl;
|
||||
class json;
|
||||
} // namespace wpi
|
||||
|
||||
@@ -32,28 +32,29 @@ class PropertyContainer {
|
||||
public:
|
||||
virtual ~PropertyContainer() = default;
|
||||
|
||||
int GetPropertyIndex(const wpi::Twine& name) const;
|
||||
int GetPropertyIndex(std::string_view name) const;
|
||||
wpi::ArrayRef<int> EnumerateProperties(wpi::SmallVectorImpl<int>& vec,
|
||||
CS_Status* status) const;
|
||||
CS_PropertyKind GetPropertyKind(int property) const;
|
||||
wpi::StringRef GetPropertyName(int property, wpi::SmallVectorImpl<char>& buf,
|
||||
CS_Status* status) const;
|
||||
std::string_view GetPropertyName(int property,
|
||||
wpi::SmallVectorImpl<char>& buf,
|
||||
CS_Status* status) const;
|
||||
int GetProperty(int property, CS_Status* status) const;
|
||||
virtual void SetProperty(int property, int value, CS_Status* status);
|
||||
int GetPropertyMin(int property, CS_Status* status) const;
|
||||
int GetPropertyMax(int property, CS_Status* status) const;
|
||||
int GetPropertyStep(int property, CS_Status* status) const;
|
||||
int GetPropertyDefault(int property, CS_Status* status) const;
|
||||
wpi::StringRef GetStringProperty(int property,
|
||||
wpi::SmallVectorImpl<char>& buf,
|
||||
CS_Status* status) const;
|
||||
virtual void SetStringProperty(int property, const wpi::Twine& value,
|
||||
std::string_view GetStringProperty(int property,
|
||||
wpi::SmallVectorImpl<char>& buf,
|
||||
CS_Status* status) const;
|
||||
virtual void SetStringProperty(int property, std::string_view value,
|
||||
CS_Status* status);
|
||||
std::vector<std::string> GetEnumPropertyChoices(int property,
|
||||
CS_Status* status) const;
|
||||
|
||||
bool SetPropertiesJson(const wpi::json& config, wpi::Logger& logger,
|
||||
wpi::StringRef logName, CS_Status* status);
|
||||
std::string_view logName, CS_Status* status);
|
||||
wpi::json GetPropertiesJsonObject(CS_Status* status);
|
||||
|
||||
protected:
|
||||
@@ -76,10 +77,9 @@ class PropertyContainer {
|
||||
// @tparam NewFunc functor that returns a std::unique_ptr<PropertyImpl>
|
||||
// @tparam UpdateFunc functor that takes a PropertyImpl&.
|
||||
template <typename NewFunc, typename UpdateFunc>
|
||||
int CreateOrUpdateProperty(const wpi::Twine& name, NewFunc newFunc,
|
||||
int CreateOrUpdateProperty(std::string_view name, NewFunc newFunc,
|
||||
UpdateFunc updateFunc) {
|
||||
wpi::SmallVector<char, 64> nameBuf;
|
||||
int& ndx = m_properties[name.toStringRef(nameBuf)];
|
||||
int& ndx = m_properties[name];
|
||||
if (ndx == 0) {
|
||||
// create a new index
|
||||
ndx = m_propertyData.size() + 1;
|
||||
@@ -91,7 +91,7 @@ class PropertyContainer {
|
||||
return ndx;
|
||||
}
|
||||
template <typename NewFunc>
|
||||
int CreateProperty(const wpi::Twine& name, NewFunc newFunc) {
|
||||
int CreateProperty(std::string_view name, NewFunc newFunc) {
|
||||
return CreateOrUpdateProperty(name, newFunc, [](PropertyImpl&) {});
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ class PropertyContainer {
|
||||
// Note: called with m_mutex held.
|
||||
// The default implementation simply creates a PropertyImpl object.
|
||||
virtual std::unique_ptr<PropertyImpl> CreateEmptyProperty(
|
||||
const wpi::Twine& name) const;
|
||||
std::string_view name) const;
|
||||
|
||||
// Cache properties. Implementations must return false and set status to
|
||||
// CS_SOURCE_IS_DISCONNECTED if not possible to cache.
|
||||
@@ -111,7 +111,7 @@ class PropertyContainer {
|
||||
|
||||
// Update property value; must be called with m_mutex held.
|
||||
virtual void UpdatePropertyValue(int property, bool setString, int value,
|
||||
const wpi::Twine& valueStr) = 0;
|
||||
std::string_view valueStr) = 0;
|
||||
|
||||
// Whether CacheProperties() has been successful at least once (and thus
|
||||
// should not be called again)
|
||||
|
||||
Reference in New Issue
Block a user