mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +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:
@@ -8,12 +8,12 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/StringMap.h>
|
||||
#include <wpi/Twine.h>
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
@@ -54,7 +54,7 @@ class NetworkTable final {
|
||||
* @param key key
|
||||
* @return base name
|
||||
*/
|
||||
static wpi::StringRef BasenameKey(wpi::StringRef key);
|
||||
static std::string_view BasenameKey(std::string_view key);
|
||||
|
||||
/**
|
||||
* Normalizes an network table key to contain no consecutive slashes and
|
||||
@@ -72,12 +72,12 @@ class NetworkTable final {
|
||||
* with a leading slash
|
||||
* @return normalized key
|
||||
*/
|
||||
static std::string NormalizeKey(const wpi::Twine& key,
|
||||
static std::string NormalizeKey(std::string_view key,
|
||||
bool withLeadingSlash = true);
|
||||
|
||||
static wpi::StringRef NormalizeKey(const wpi::Twine& key,
|
||||
wpi::SmallVectorImpl<char>& buf,
|
||||
bool withLeadingSlash = true);
|
||||
static std::string_view NormalizeKey(std::string_view key,
|
||||
wpi::SmallVectorImpl<char>& buf,
|
||||
bool withLeadingSlash = true);
|
||||
|
||||
/**
|
||||
* Gets a list of the names of all the super tables of a given key. For
|
||||
@@ -87,13 +87,13 @@ class NetworkTable final {
|
||||
* @param key the key
|
||||
* @return List of super tables
|
||||
*/
|
||||
static std::vector<std::string> GetHierarchy(const wpi::Twine& key);
|
||||
static std::vector<std::string> GetHierarchy(std::string_view key);
|
||||
|
||||
/**
|
||||
* Constructor. Use NetworkTableInstance::GetTable() or GetSubTable()
|
||||
* instead.
|
||||
*/
|
||||
NetworkTable(NT_Inst inst, const wpi::Twine& path, const private_init&);
|
||||
NetworkTable(NT_Inst inst, std::string_view path, const private_init&);
|
||||
virtual ~NetworkTable();
|
||||
|
||||
/**
|
||||
@@ -114,7 +114,7 @@ class NetworkTable final {
|
||||
* @param key the key name
|
||||
* @return Network table entry.
|
||||
*/
|
||||
NetworkTableEntry GetEntry(const wpi::Twine& key) const;
|
||||
NetworkTableEntry GetEntry(std::string_view key) const;
|
||||
|
||||
/**
|
||||
* Listen to keys only within this table.
|
||||
@@ -134,7 +134,7 @@ class NetworkTable final {
|
||||
* @param flags EntryListenerFlags bitmask
|
||||
* @return Listener handle
|
||||
*/
|
||||
NT_EntryListener AddEntryListener(const wpi::Twine& key,
|
||||
NT_EntryListener AddEntryListener(std::string_view key,
|
||||
TableEntryListener listener,
|
||||
unsigned int flags) const;
|
||||
|
||||
@@ -171,7 +171,7 @@ class NetworkTable final {
|
||||
* @param key the key name
|
||||
* @return the networktable to be returned
|
||||
*/
|
||||
std::shared_ptr<NetworkTable> GetSubTable(const wpi::Twine& key) const;
|
||||
std::shared_ptr<NetworkTable> GetSubTable(std::string_view key) const;
|
||||
|
||||
/**
|
||||
* Determines whether the given key is in this table.
|
||||
@@ -179,7 +179,7 @@ class NetworkTable final {
|
||||
* @param key the key to search for
|
||||
* @return true if the table as a value assigned to the given key
|
||||
*/
|
||||
bool ContainsKey(const wpi::Twine& key) const;
|
||||
bool ContainsKey(std::string_view key) const;
|
||||
|
||||
/**
|
||||
* Determines whether there exists a non-empty subtable for this key
|
||||
@@ -189,7 +189,7 @@ class NetworkTable final {
|
||||
* @return true if there is a subtable with the key which contains at least
|
||||
* one key/subtable of its own
|
||||
*/
|
||||
bool ContainsSubTable(const wpi::Twine& key) const;
|
||||
bool ContainsSubTable(std::string_view key) const;
|
||||
|
||||
/**
|
||||
* Gets all keys in the table (not including sub-tables).
|
||||
@@ -211,7 +211,7 @@ class NetworkTable final {
|
||||
*
|
||||
* @param key the key to make persistent
|
||||
*/
|
||||
void SetPersistent(wpi::StringRef key);
|
||||
void SetPersistent(std::string_view key);
|
||||
|
||||
/**
|
||||
* Stop making a key's value persistent through program restarts.
|
||||
@@ -219,7 +219,7 @@ class NetworkTable final {
|
||||
*
|
||||
* @param key the key name
|
||||
*/
|
||||
void ClearPersistent(wpi::StringRef key);
|
||||
void ClearPersistent(std::string_view key);
|
||||
|
||||
/**
|
||||
* Returns whether the value is persistent through program restarts.
|
||||
@@ -227,7 +227,7 @@ class NetworkTable final {
|
||||
*
|
||||
* @param key the key name
|
||||
*/
|
||||
bool IsPersistent(wpi::StringRef key) const;
|
||||
bool IsPersistent(std::string_view key) const;
|
||||
|
||||
/**
|
||||
* Sets flags on the specified key in this table. The key can
|
||||
@@ -236,7 +236,7 @@ class NetworkTable final {
|
||||
* @param key the key name
|
||||
* @param flags the flags to set (bitmask)
|
||||
*/
|
||||
void SetFlags(wpi::StringRef key, unsigned int flags);
|
||||
void SetFlags(std::string_view key, unsigned int flags);
|
||||
|
||||
/**
|
||||
* Clears flags on the specified key in this table. The key can
|
||||
@@ -245,7 +245,7 @@ class NetworkTable final {
|
||||
* @param key the key name
|
||||
* @param flags the flags to clear (bitmask)
|
||||
*/
|
||||
void ClearFlags(wpi::StringRef key, unsigned int flags);
|
||||
void ClearFlags(std::string_view key, unsigned int flags);
|
||||
|
||||
/**
|
||||
* Returns the flags for the specified key.
|
||||
@@ -253,14 +253,14 @@ class NetworkTable final {
|
||||
* @param key the key name
|
||||
* @return the flags, or 0 if the key is not defined
|
||||
*/
|
||||
unsigned int GetFlags(wpi::StringRef key) const;
|
||||
unsigned int GetFlags(std::string_view key) const;
|
||||
|
||||
/**
|
||||
* Deletes the specified key in this table.
|
||||
*
|
||||
* @param key the key name
|
||||
*/
|
||||
void Delete(const wpi::Twine& key);
|
||||
void Delete(std::string_view key);
|
||||
|
||||
/**
|
||||
* Put a number in the table
|
||||
@@ -269,7 +269,7 @@ class NetworkTable final {
|
||||
* @param value the value that will be assigned
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
bool PutNumber(wpi::StringRef key, double value);
|
||||
bool PutNumber(std::string_view key, double value);
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -278,7 +278,7 @@ class NetworkTable final {
|
||||
* @param defaultValue the default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
bool SetDefaultNumber(wpi::StringRef key, double defaultValue);
|
||||
bool SetDefaultNumber(std::string_view key, double defaultValue);
|
||||
|
||||
/**
|
||||
* Gets the number associated with the given name.
|
||||
@@ -288,7 +288,7 @@ class NetworkTable final {
|
||||
* @return the value associated with the given key or the given default value
|
||||
* if there is no value associated with the key
|
||||
*/
|
||||
double GetNumber(wpi::StringRef key, double defaultValue) const;
|
||||
double GetNumber(std::string_view key, double defaultValue) const;
|
||||
|
||||
/**
|
||||
* Put a string in the table
|
||||
@@ -297,7 +297,7 @@ class NetworkTable final {
|
||||
* @param value the value that will be assigned
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
bool PutString(wpi::StringRef key, wpi::StringRef value);
|
||||
bool PutString(std::string_view key, std::string_view value);
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -306,7 +306,7 @@ class NetworkTable final {
|
||||
* @param defaultValue the default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
bool SetDefaultString(wpi::StringRef key, wpi::StringRef defaultValue);
|
||||
bool SetDefaultString(std::string_view key, std::string_view defaultValue);
|
||||
|
||||
/**
|
||||
* Gets the string associated with the given name. If the key does not
|
||||
@@ -317,7 +317,8 @@ class NetworkTable final {
|
||||
* @return the value associated with the given key or the given default value
|
||||
* if there is no value associated with the key
|
||||
*/
|
||||
std::string GetString(wpi::StringRef key, wpi::StringRef defaultValue) const;
|
||||
std::string GetString(std::string_view key,
|
||||
std::string_view defaultValue) const;
|
||||
|
||||
/**
|
||||
* Put a boolean in the table
|
||||
@@ -326,7 +327,7 @@ class NetworkTable final {
|
||||
* @param value the value that will be assigned
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
bool PutBoolean(wpi::StringRef key, bool value);
|
||||
bool PutBoolean(std::string_view key, bool value);
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -335,7 +336,7 @@ class NetworkTable final {
|
||||
* @param defaultValue the default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
bool SetDefaultBoolean(wpi::StringRef key, bool defaultValue);
|
||||
bool SetDefaultBoolean(std::string_view key, bool defaultValue);
|
||||
|
||||
/**
|
||||
* Gets the boolean associated with the given name. If the key does not
|
||||
@@ -346,7 +347,7 @@ class NetworkTable final {
|
||||
* @return the value associated with the given key or the given default value
|
||||
* if there is no value associated with the key
|
||||
*/
|
||||
bool GetBoolean(wpi::StringRef key, bool defaultValue) const;
|
||||
bool GetBoolean(std::string_view key, bool defaultValue) const;
|
||||
|
||||
/**
|
||||
* Put a boolean array in the table
|
||||
@@ -359,7 +360,7 @@ class NetworkTable final {
|
||||
* std::vector<bool> is special-cased in C++. 0 is false, any
|
||||
* non-zero value is true.
|
||||
*/
|
||||
bool PutBooleanArray(wpi::StringRef key, wpi::ArrayRef<int> value);
|
||||
bool PutBooleanArray(std::string_view key, wpi::ArrayRef<int> value);
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -368,7 +369,7 @@ class NetworkTable final {
|
||||
* @param defaultValue the default value to set if key doesn't exist.
|
||||
* @return False if the table key exists with a different type
|
||||
*/
|
||||
bool SetDefaultBooleanArray(wpi::StringRef key,
|
||||
bool SetDefaultBooleanArray(std::string_view key,
|
||||
wpi::ArrayRef<int> defaultValue);
|
||||
|
||||
/**
|
||||
@@ -387,7 +388,7 @@ class NetworkTable final {
|
||||
* because std::vector<bool> is special-cased in C++. 0 is false, any
|
||||
* non-zero value is true.
|
||||
*/
|
||||
std::vector<int> GetBooleanArray(wpi::StringRef key,
|
||||
std::vector<int> GetBooleanArray(std::string_view key,
|
||||
wpi::ArrayRef<int> defaultValue) const;
|
||||
|
||||
/**
|
||||
@@ -397,7 +398,7 @@ class NetworkTable final {
|
||||
* @param value the value that will be assigned
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
bool PutNumberArray(wpi::StringRef key, wpi::ArrayRef<double> value);
|
||||
bool PutNumberArray(std::string_view key, wpi::ArrayRef<double> value);
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -406,7 +407,7 @@ class NetworkTable final {
|
||||
* @param defaultValue the default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
bool SetDefaultNumberArray(wpi::StringRef key,
|
||||
bool SetDefaultNumberArray(std::string_view key,
|
||||
wpi::ArrayRef<double> defaultValue);
|
||||
|
||||
/**
|
||||
@@ -421,7 +422,7 @@ class NetworkTable final {
|
||||
* @note This makes a copy of the array. If the overhead of this is a
|
||||
* concern, use GetValue() instead.
|
||||
*/
|
||||
std::vector<double> GetNumberArray(wpi::StringRef key,
|
||||
std::vector<double> GetNumberArray(std::string_view key,
|
||||
wpi::ArrayRef<double> defaultValue) const;
|
||||
|
||||
/**
|
||||
@@ -431,7 +432,7 @@ class NetworkTable final {
|
||||
* @param value the value that will be assigned
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
bool PutStringArray(wpi::StringRef key, wpi::ArrayRef<std::string> value);
|
||||
bool PutStringArray(std::string_view key, wpi::ArrayRef<std::string> value);
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -440,7 +441,7 @@ class NetworkTable final {
|
||||
* @param defaultValue the default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
bool SetDefaultStringArray(wpi::StringRef key,
|
||||
bool SetDefaultStringArray(std::string_view key,
|
||||
wpi::ArrayRef<std::string> defaultValue);
|
||||
|
||||
/**
|
||||
@@ -456,7 +457,7 @@ class NetworkTable final {
|
||||
* concern, use GetValue() instead.
|
||||
*/
|
||||
std::vector<std::string> GetStringArray(
|
||||
wpi::StringRef key, wpi::ArrayRef<std::string> defaultValue) const;
|
||||
std::string_view key, wpi::ArrayRef<std::string> defaultValue) const;
|
||||
|
||||
/**
|
||||
* Put a raw value (byte array) in the table
|
||||
@@ -465,7 +466,7 @@ class NetworkTable final {
|
||||
* @param value the value that will be assigned
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
bool PutRaw(wpi::StringRef key, wpi::StringRef value);
|
||||
bool PutRaw(std::string_view key, std::string_view value);
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -474,7 +475,7 @@ class NetworkTable final {
|
||||
* @param defaultValue the default value to set if key doesn't exist.
|
||||
* @return False if the table key exists with a different type
|
||||
*/
|
||||
bool SetDefaultRaw(wpi::StringRef key, wpi::StringRef defaultValue);
|
||||
bool SetDefaultRaw(std::string_view key, std::string_view defaultValue);
|
||||
|
||||
/**
|
||||
* Returns the raw value (byte array) the key maps to. If the key does not
|
||||
@@ -488,7 +489,7 @@ class NetworkTable final {
|
||||
* @note This makes a copy of the raw contents. If the overhead of this is a
|
||||
* concern, use GetValue() instead.
|
||||
*/
|
||||
std::string GetRaw(wpi::StringRef key, wpi::StringRef defaultValue) const;
|
||||
std::string GetRaw(std::string_view key, std::string_view defaultValue) const;
|
||||
|
||||
/**
|
||||
* Put a value in the table
|
||||
@@ -497,7 +498,7 @@ class NetworkTable final {
|
||||
* @param value the value that will be assigned
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
bool PutValue(const wpi::Twine& key, std::shared_ptr<Value> value);
|
||||
bool PutValue(std::string_view key, std::shared_ptr<Value> value);
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -506,7 +507,7 @@ class NetworkTable final {
|
||||
* @param defaultValue the default value to set if key doesn't exist.
|
||||
* @return False if the table key exists with a different type
|
||||
*/
|
||||
bool SetDefaultValue(const wpi::Twine& key,
|
||||
bool SetDefaultValue(std::string_view key,
|
||||
std::shared_ptr<Value> defaultValue);
|
||||
|
||||
/**
|
||||
@@ -516,14 +517,14 @@ class NetworkTable final {
|
||||
* @return the value associated with the given key, or nullptr if the key
|
||||
* does not exist
|
||||
*/
|
||||
std::shared_ptr<Value> GetValue(const wpi::Twine& key) const;
|
||||
std::shared_ptr<Value> GetValue(std::string_view key) const;
|
||||
|
||||
/**
|
||||
* Gets the full path of this table. Does not include the trailing "/".
|
||||
*
|
||||
* @return The path (e.g "", "/foo").
|
||||
*/
|
||||
wpi::StringRef GetPath() const;
|
||||
std::string_view GetPath() const;
|
||||
|
||||
/**
|
||||
* Save table values to a file. The file format used is identical to
|
||||
@@ -532,7 +533,7 @@ class NetworkTable final {
|
||||
* @param filename filename
|
||||
* @return error string, or nullptr if successful
|
||||
*/
|
||||
const char* SaveEntries(const wpi::Twine& filename) const;
|
||||
const char* SaveEntries(std::string_view filename) const;
|
||||
|
||||
/**
|
||||
* Load table values from a file. The file format used is identical to
|
||||
@@ -543,7 +544,7 @@ class NetworkTable final {
|
||||
* @return error string, or nullptr if successful
|
||||
*/
|
||||
const char* LoadEntries(
|
||||
const wpi::Twine& filename,
|
||||
std::string_view filename,
|
||||
std::function<void(size_t line, const char* msg)> warn);
|
||||
};
|
||||
|
||||
|
||||
@@ -10,11 +10,9 @@
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/StringRef.h>
|
||||
#include <wpi/Twine.h>
|
||||
|
||||
#include "networktables/NetworkTableType.h"
|
||||
#include "networktables/NetworkTableValue.h"
|
||||
#include "networktables/RpcCall.h"
|
||||
@@ -143,7 +141,7 @@ class NetworkTableEntry final {
|
||||
* @param defaultValue the value to be returned if no value is found
|
||||
* @return the entry's value or the given default value
|
||||
*/
|
||||
std::string GetString(wpi::StringRef defaultValue) const;
|
||||
std::string GetString(std::string_view defaultValue) const;
|
||||
|
||||
/**
|
||||
* Gets the entry's value as a raw. If the entry does not exist or is of
|
||||
@@ -152,7 +150,7 @@ class NetworkTableEntry final {
|
||||
* @param defaultValue the value to be returned if no value is found
|
||||
* @return the entry's value or the given default value
|
||||
*/
|
||||
std::string GetRaw(wpi::StringRef defaultValue) const;
|
||||
std::string GetRaw(std::string_view defaultValue) const;
|
||||
|
||||
/**
|
||||
* Gets the entry's value as a boolean array. If the entry does not exist
|
||||
@@ -268,7 +266,7 @@ class NetworkTableEntry final {
|
||||
* @param defaultValue the default value to set
|
||||
* @return False if the entry exists with a different type
|
||||
*/
|
||||
bool SetDefaultString(const wpi::Twine& defaultValue);
|
||||
bool SetDefaultString(std::string_view defaultValue);
|
||||
|
||||
/**
|
||||
* Sets the entry's value if it does not exist.
|
||||
@@ -276,7 +274,7 @@ class NetworkTableEntry final {
|
||||
* @param defaultValue the default value to set
|
||||
* @return False if the entry exists with a different type
|
||||
*/
|
||||
bool SetDefaultRaw(wpi::StringRef defaultValue);
|
||||
bool SetDefaultRaw(std::string_view defaultValue);
|
||||
|
||||
/**
|
||||
* Sets the entry's value if it does not exist.
|
||||
@@ -356,7 +354,7 @@ class NetworkTableEntry final {
|
||||
* @param value the value to set
|
||||
* @return False if the entry exists with a different type
|
||||
*/
|
||||
bool SetString(const wpi::Twine& value);
|
||||
bool SetString(std::string_view value);
|
||||
|
||||
/**
|
||||
* Sets the entry's value.
|
||||
@@ -364,7 +362,7 @@ class NetworkTableEntry final {
|
||||
* @param value the value to set
|
||||
* @return False if the entry exists with a different type
|
||||
*/
|
||||
bool SetRaw(wpi::StringRef value);
|
||||
bool SetRaw(std::string_view value);
|
||||
|
||||
/**
|
||||
* Sets the entry's value.
|
||||
@@ -460,7 +458,7 @@ class NetworkTableEntry final {
|
||||
*
|
||||
* @param value the value to set
|
||||
*/
|
||||
void ForceSetString(const wpi::Twine& value);
|
||||
void ForceSetString(std::string_view value);
|
||||
|
||||
/**
|
||||
* Sets the entry's value. If the value is of different type, the type is
|
||||
@@ -468,7 +466,7 @@ class NetworkTableEntry final {
|
||||
*
|
||||
* @param value the value to set
|
||||
*/
|
||||
void ForceSetRaw(wpi::StringRef value);
|
||||
void ForceSetRaw(std::string_view value);
|
||||
|
||||
/**
|
||||
* Sets the entry's value. If the value is of different type, the type is
|
||||
@@ -596,7 +594,7 @@ class NetworkTableEntry final {
|
||||
* @param params parameter
|
||||
* @return RPC call object.
|
||||
*/
|
||||
RpcCall CallRpc(wpi::StringRef params);
|
||||
RpcCall CallRpc(std::string_view params);
|
||||
|
||||
/**
|
||||
* Add a listener for changes to this entry.
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
@@ -67,21 +68,21 @@ inline double NetworkTableEntry::GetDouble(double defaultValue) const {
|
||||
}
|
||||
|
||||
inline std::string NetworkTableEntry::GetString(
|
||||
wpi::StringRef defaultValue) const {
|
||||
std::string_view defaultValue) const {
|
||||
auto value = GetEntryValue(m_handle);
|
||||
if (!value || value->type() != NT_STRING) {
|
||||
return defaultValue;
|
||||
return std::string{defaultValue};
|
||||
}
|
||||
return value->GetString();
|
||||
return std::string{value->GetString()};
|
||||
}
|
||||
|
||||
inline std::string NetworkTableEntry::GetRaw(
|
||||
wpi::StringRef defaultValue) const {
|
||||
std::string_view defaultValue) const {
|
||||
auto value = GetEntryValue(m_handle);
|
||||
if (!value || value->type() != NT_RAW) {
|
||||
return defaultValue;
|
||||
return std::string{defaultValue};
|
||||
}
|
||||
return value->GetRaw();
|
||||
return std::string{value->GetRaw()};
|
||||
}
|
||||
|
||||
inline std::vector<int> NetworkTableEntry::GetBooleanArray(
|
||||
@@ -141,12 +142,11 @@ inline bool NetworkTableEntry::SetDefaultDouble(double defaultValue) {
|
||||
return SetDefaultEntryValue(m_handle, Value::MakeDouble(defaultValue));
|
||||
}
|
||||
|
||||
inline bool NetworkTableEntry::SetDefaultString(
|
||||
const wpi::Twine& defaultValue) {
|
||||
inline bool NetworkTableEntry::SetDefaultString(std::string_view defaultValue) {
|
||||
return SetDefaultEntryValue(m_handle, Value::MakeString(defaultValue));
|
||||
}
|
||||
|
||||
inline bool NetworkTableEntry::SetDefaultRaw(wpi::StringRef defaultValue) {
|
||||
inline bool NetworkTableEntry::SetDefaultRaw(std::string_view defaultValue) {
|
||||
return SetDefaultEntryValue(m_handle, Value::MakeRaw(defaultValue));
|
||||
}
|
||||
|
||||
@@ -192,11 +192,11 @@ inline bool NetworkTableEntry::SetDouble(double value) {
|
||||
return SetEntryValue(m_handle, Value::MakeDouble(value));
|
||||
}
|
||||
|
||||
inline bool NetworkTableEntry::SetString(const wpi::Twine& value) {
|
||||
inline bool NetworkTableEntry::SetString(std::string_view value) {
|
||||
return SetEntryValue(m_handle, Value::MakeString(value));
|
||||
}
|
||||
|
||||
inline bool NetworkTableEntry::SetRaw(wpi::StringRef value) {
|
||||
inline bool NetworkTableEntry::SetRaw(std::string_view value) {
|
||||
return SetEntryValue(m_handle, Value::MakeRaw(value));
|
||||
}
|
||||
|
||||
@@ -249,11 +249,11 @@ inline void NetworkTableEntry::ForceSetDouble(double value) {
|
||||
SetEntryTypeValue(m_handle, Value::MakeDouble(value));
|
||||
}
|
||||
|
||||
inline void NetworkTableEntry::ForceSetString(const wpi::Twine& value) {
|
||||
inline void NetworkTableEntry::ForceSetString(std::string_view value) {
|
||||
SetEntryTypeValue(m_handle, Value::MakeString(value));
|
||||
}
|
||||
|
||||
inline void NetworkTableEntry::ForceSetRaw(wpi::StringRef value) {
|
||||
inline void NetworkTableEntry::ForceSetRaw(std::string_view value) {
|
||||
SetEntryTypeValue(m_handle, Value::MakeRaw(value));
|
||||
}
|
||||
|
||||
@@ -321,10 +321,10 @@ inline void NetworkTableEntry::Delete() {
|
||||
|
||||
inline void NetworkTableEntry::CreateRpc(
|
||||
std::function<void(const RpcAnswer& answer)> callback) {
|
||||
::nt::CreateRpc(m_handle, wpi::StringRef("\0", 1), callback);
|
||||
::nt::CreateRpc(m_handle, std::string_view("\0", 1), callback);
|
||||
}
|
||||
|
||||
inline RpcCall NetworkTableEntry::CallRpc(wpi::StringRef params) {
|
||||
inline RpcCall NetworkTableEntry::CallRpc(std::string_view params) {
|
||||
return RpcCall{m_handle, ::nt::CallRpc(m_handle, params)};
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,11 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/StringRef.h>
|
||||
#include <wpi/Twine.h>
|
||||
|
||||
#include "networktables/NetworkTable.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
@@ -131,7 +130,7 @@ class NetworkTableInstance final {
|
||||
* @param name Key
|
||||
* @return Network table entry.
|
||||
*/
|
||||
NetworkTableEntry GetEntry(const wpi::Twine& name);
|
||||
NetworkTableEntry GetEntry(std::string_view name);
|
||||
|
||||
/**
|
||||
* Get entries starting with the given prefix.
|
||||
@@ -144,7 +143,7 @@ class NetworkTableInstance final {
|
||||
* @param types bitmask of types; 0 is treated as a "don't care"
|
||||
* @return Array of entries.
|
||||
*/
|
||||
std::vector<NetworkTableEntry> GetEntries(const wpi::Twine& prefix,
|
||||
std::vector<NetworkTableEntry> GetEntries(std::string_view prefix,
|
||||
unsigned int types);
|
||||
|
||||
/**
|
||||
@@ -158,7 +157,7 @@ class NetworkTableInstance final {
|
||||
* @param types bitmask of types; 0 is treated as a "don't care"
|
||||
* @return Array of entry information.
|
||||
*/
|
||||
std::vector<EntryInfo> GetEntryInfo(const wpi::Twine& prefix,
|
||||
std::vector<EntryInfo> GetEntryInfo(std::string_view prefix,
|
||||
unsigned int types) const;
|
||||
|
||||
/**
|
||||
@@ -167,7 +166,7 @@ class NetworkTableInstance final {
|
||||
* @param key the key name
|
||||
* @return The network table
|
||||
*/
|
||||
std::shared_ptr<NetworkTable> GetTable(const wpi::Twine& key) const;
|
||||
std::shared_ptr<NetworkTable> GetTable(std::string_view key) const;
|
||||
|
||||
/**
|
||||
* Deletes ALL keys in ALL subtables (except persistent values).
|
||||
@@ -189,7 +188,7 @@ class NetworkTableInstance final {
|
||||
* @return Listener handle
|
||||
*/
|
||||
NT_EntryListener AddEntryListener(
|
||||
const wpi::Twine& prefix,
|
||||
std::string_view prefix,
|
||||
std::function<void(const EntryNotification& event)> callback,
|
||||
unsigned int flags) const;
|
||||
|
||||
@@ -283,7 +282,7 @@ class NetworkTableInstance final {
|
||||
*
|
||||
* @param name identity to advertise
|
||||
*/
|
||||
void SetNetworkIdentity(const wpi::Twine& name);
|
||||
void SetNetworkIdentity(std::string_view name);
|
||||
|
||||
/**
|
||||
* Get the current network mode.
|
||||
@@ -314,7 +313,7 @@ class NetworkTableInstance final {
|
||||
* address (UTF-8 string, null terminated)
|
||||
* @param port port to communicate over
|
||||
*/
|
||||
void StartServer(const wpi::Twine& persist_filename = "networktables.ini",
|
||||
void StartServer(std::string_view persist_filename = "networktables.ini",
|
||||
const char* listen_address = "",
|
||||
unsigned int port = kDefaultPort);
|
||||
|
||||
@@ -343,7 +342,7 @@ class NetworkTableInstance final {
|
||||
* @param servers array of server name and port pairs
|
||||
*/
|
||||
void StartClient(
|
||||
wpi::ArrayRef<std::pair<wpi::StringRef, unsigned int>> servers);
|
||||
wpi::ArrayRef<std::pair<std::string_view, unsigned int>> servers);
|
||||
|
||||
/**
|
||||
* Starts a client using the specified servers and port. The
|
||||
@@ -352,7 +351,7 @@ class NetworkTableInstance final {
|
||||
* @param servers array of server names
|
||||
* @param port port to communicate over
|
||||
*/
|
||||
void StartClient(wpi::ArrayRef<wpi::StringRef> servers,
|
||||
void StartClient(wpi::ArrayRef<std::string_view> servers,
|
||||
unsigned int port = kDefaultPort);
|
||||
|
||||
/**
|
||||
@@ -384,7 +383,7 @@ class NetworkTableInstance final {
|
||||
* @param servers array of server name and port pairs
|
||||
*/
|
||||
void SetServer(
|
||||
wpi::ArrayRef<std::pair<wpi::StringRef, unsigned int>> servers);
|
||||
wpi::ArrayRef<std::pair<std::string_view, unsigned int>> servers);
|
||||
|
||||
/**
|
||||
* Sets server addresses and port for client (without restarting client).
|
||||
@@ -393,7 +392,7 @@ class NetworkTableInstance final {
|
||||
* @param servers array of server names
|
||||
* @param port port to communicate over
|
||||
*/
|
||||
void SetServer(wpi::ArrayRef<wpi::StringRef> servers,
|
||||
void SetServer(wpi::ArrayRef<std::string_view> servers,
|
||||
unsigned int port = kDefaultPort);
|
||||
|
||||
/**
|
||||
@@ -465,7 +464,7 @@ class NetworkTableInstance final {
|
||||
* @param filename filename
|
||||
* @return error string, or nullptr if successful
|
||||
*/
|
||||
const char* SavePersistent(const wpi::Twine& filename) const;
|
||||
const char* SavePersistent(std::string_view filename) const;
|
||||
|
||||
/**
|
||||
* Load persistent values from a file. The server automatically does this
|
||||
@@ -477,7 +476,7 @@ class NetworkTableInstance final {
|
||||
* @return error string, or nullptr if successful
|
||||
*/
|
||||
const char* LoadPersistent(
|
||||
const wpi::Twine& filename,
|
||||
std::string_view filename,
|
||||
std::function<void(size_t line, const char* msg)> warn);
|
||||
|
||||
/**
|
||||
@@ -488,8 +487,8 @@ class NetworkTableInstance final {
|
||||
* @param prefix save only keys starting with this prefix
|
||||
* @return error string, or nullptr if successful
|
||||
*/
|
||||
const char* SaveEntries(const wpi::Twine& filename,
|
||||
const wpi::Twine& prefix) const;
|
||||
const char* SaveEntries(std::string_view filename,
|
||||
std::string_view prefix) const;
|
||||
|
||||
/**
|
||||
* Load table values from a file. The file format used is identical to
|
||||
@@ -501,7 +500,7 @@ class NetworkTableInstance final {
|
||||
* @return error string, or nullptr if successful
|
||||
*/
|
||||
const char* LoadEntries(
|
||||
const wpi::Twine& filename, const wpi::Twine& prefix,
|
||||
std::string_view filename, std::string_view prefix,
|
||||
std::function<void(size_t line, const char* msg)> warn);
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#ifndef NTCORE_NETWORKTABLES_NETWORKTABLEINSTANCE_INC_
|
||||
#define NTCORE_NETWORKTABLES_NETWORKTABLEINSTANCE_INC_
|
||||
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
@@ -35,13 +36,12 @@ inline NT_Inst NetworkTableInstance::GetHandle() const {
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
inline NetworkTableEntry NetworkTableInstance::GetEntry(
|
||||
const wpi::Twine& name) {
|
||||
inline NetworkTableEntry NetworkTableInstance::GetEntry(std::string_view name) {
|
||||
return NetworkTableEntry{::nt::GetEntry(m_handle, name)};
|
||||
}
|
||||
|
||||
inline std::vector<NetworkTableEntry> NetworkTableInstance::GetEntries(
|
||||
const wpi::Twine& prefix, unsigned int types) {
|
||||
std::string_view prefix, unsigned int types) {
|
||||
std::vector<NetworkTableEntry> entries;
|
||||
for (auto entry : ::nt::GetEntries(m_handle, prefix, types)) {
|
||||
entries.emplace_back(entry);
|
||||
@@ -50,7 +50,7 @@ inline std::vector<NetworkTableEntry> NetworkTableInstance::GetEntries(
|
||||
}
|
||||
|
||||
inline std::vector<EntryInfo> NetworkTableInstance::GetEntryInfo(
|
||||
const wpi::Twine& prefix, unsigned int types) const {
|
||||
std::string_view prefix, unsigned int types) const {
|
||||
return ::nt::GetEntryInfo(m_handle, prefix, types);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ inline bool NetworkTableInstance::WaitForRpcCallQueue(double timeout) {
|
||||
return ::nt::WaitForRpcCallQueue(m_handle, timeout);
|
||||
}
|
||||
|
||||
inline void NetworkTableInstance::SetNetworkIdentity(const wpi::Twine& name) {
|
||||
inline void NetworkTableInstance::SetNetworkIdentity(std::string_view name) {
|
||||
::nt::SetNetworkIdentity(m_handle, name);
|
||||
}
|
||||
|
||||
@@ -97,9 +97,9 @@ inline void NetworkTableInstance::StopLocal() {
|
||||
::nt::StopLocal(m_handle);
|
||||
}
|
||||
|
||||
inline void NetworkTableInstance::StartServer(
|
||||
const wpi::Twine& persist_filename, const char* listen_address,
|
||||
unsigned int port) {
|
||||
inline void NetworkTableInstance::StartServer(std::string_view persist_filename,
|
||||
const char* listen_address,
|
||||
unsigned int port) {
|
||||
::nt::StartServer(m_handle, persist_filename, listen_address, port);
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ inline void NetworkTableInstance::StartClient(const char* server_name,
|
||||
}
|
||||
|
||||
inline void NetworkTableInstance::StartClient(
|
||||
wpi::ArrayRef<std::pair<wpi::StringRef, unsigned int>> servers) {
|
||||
wpi::ArrayRef<std::pair<std::string_view, unsigned int>> servers) {
|
||||
::nt::StartClient(m_handle, servers);
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ inline void NetworkTableInstance::SetServer(const char* server_name,
|
||||
}
|
||||
|
||||
inline void NetworkTableInstance::SetServer(
|
||||
wpi::ArrayRef<std::pair<wpi::StringRef, unsigned int>> servers) {
|
||||
wpi::ArrayRef<std::pair<std::string_view, unsigned int>> servers) {
|
||||
::nt::SetServer(m_handle, servers);
|
||||
}
|
||||
|
||||
@@ -171,23 +171,23 @@ inline bool NetworkTableInstance::IsConnected() const {
|
||||
}
|
||||
|
||||
inline const char* NetworkTableInstance::SavePersistent(
|
||||
const wpi::Twine& filename) const {
|
||||
std::string_view filename) const {
|
||||
return ::nt::SavePersistent(m_handle, filename);
|
||||
}
|
||||
|
||||
inline const char* NetworkTableInstance::LoadPersistent(
|
||||
const wpi::Twine& filename,
|
||||
std::string_view filename,
|
||||
std::function<void(size_t line, const char* msg)> warn) {
|
||||
return ::nt::LoadPersistent(m_handle, filename, warn);
|
||||
}
|
||||
|
||||
inline const char* NetworkTableInstance::SaveEntries(
|
||||
const wpi::Twine& filename, const wpi::Twine& prefix) const {
|
||||
std::string_view filename, std::string_view prefix) const {
|
||||
return ::nt::SaveEntries(m_handle, filename, prefix);
|
||||
}
|
||||
|
||||
inline const char* NetworkTableInstance::LoadEntries(
|
||||
const wpi::Twine& filename, const wpi::Twine& prefix,
|
||||
std::string_view filename, std::string_view prefix,
|
||||
std::function<void(size_t line, const char* msg)> warn) {
|
||||
return ::nt::LoadEntries(m_handle, filename, prefix, warn);
|
||||
}
|
||||
|
||||
@@ -11,13 +11,12 @@
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/StringRef.h>
|
||||
#include <wpi/Twine.h>
|
||||
|
||||
#include "ntcore_c.h"
|
||||
|
||||
@@ -163,7 +162,7 @@ class Value final {
|
||||
*
|
||||
* @return The string value.
|
||||
*/
|
||||
wpi::StringRef GetString() const {
|
||||
std::string_view GetString() const {
|
||||
assert(m_val.type == NT_STRING);
|
||||
return m_string;
|
||||
}
|
||||
@@ -173,7 +172,7 @@ class Value final {
|
||||
*
|
||||
* @return The raw value.
|
||||
*/
|
||||
wpi::StringRef GetRaw() const {
|
||||
std::string_view GetRaw() const {
|
||||
assert(m_val.type == NT_RAW);
|
||||
return m_string;
|
||||
}
|
||||
@@ -183,7 +182,7 @@ class Value final {
|
||||
*
|
||||
* @return The rpc definition value.
|
||||
*/
|
||||
wpi::StringRef GetRpc() const {
|
||||
std::string_view GetRpc() const {
|
||||
assert(m_val.type == NT_RPC);
|
||||
return m_string;
|
||||
}
|
||||
@@ -263,10 +262,10 @@ class Value final {
|
||||
* time)
|
||||
* @return The entry value
|
||||
*/
|
||||
static std::shared_ptr<Value> MakeString(const wpi::Twine& value,
|
||||
static std::shared_ptr<Value> MakeString(std::string_view value,
|
||||
uint64_t time = 0) {
|
||||
auto val = std::make_shared<Value>(NT_STRING, time, private_init());
|
||||
val->m_string = value.str();
|
||||
val->m_string = value;
|
||||
val->m_val.data.v_string.str = const_cast<char*>(val->m_string.c_str());
|
||||
val->m_val.data.v_string.len = val->m_string.size();
|
||||
return val;
|
||||
@@ -298,7 +297,7 @@ class Value final {
|
||||
* time)
|
||||
* @return The entry value
|
||||
*/
|
||||
static std::shared_ptr<Value> MakeRaw(wpi::StringRef value,
|
||||
static std::shared_ptr<Value> MakeRaw(std::string_view value,
|
||||
uint64_t time = 0) {
|
||||
auto val = std::make_shared<Value>(NT_RAW, time, private_init());
|
||||
val->m_string = value;
|
||||
@@ -333,7 +332,7 @@ class Value final {
|
||||
* time)
|
||||
* @return The entry value
|
||||
*/
|
||||
static std::shared_ptr<Value> MakeRpc(wpi::StringRef value,
|
||||
static std::shared_ptr<Value> MakeRpc(std::string_view value,
|
||||
uint64_t time = 0) {
|
||||
auto val = std::make_shared<Value>(NT_RPC, time, private_init());
|
||||
val->m_string = value;
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/StringRef.h>
|
||||
#include <string_view>
|
||||
|
||||
namespace nt {
|
||||
|
||||
@@ -30,10 +29,9 @@ class Value;
|
||||
*
|
||||
* @ingroup ntcore_cpp_api
|
||||
*/
|
||||
typedef std::function<void(NetworkTable* table, wpi::StringRef name,
|
||||
NetworkTableEntry entry,
|
||||
std::shared_ptr<Value> value, int flags)>
|
||||
TableEntryListener;
|
||||
using TableEntryListener = std::function<void(
|
||||
NetworkTable* table, std::string_view name, NetworkTableEntry entry,
|
||||
std::shared_ptr<Value> value, int flags)>;
|
||||
|
||||
} // namespace nt
|
||||
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/StringRef.h>
|
||||
#include <string_view>
|
||||
|
||||
namespace nt {
|
||||
|
||||
@@ -25,9 +24,9 @@ class NetworkTable;
|
||||
*
|
||||
* @ingroup ntcore_cpp_api
|
||||
*/
|
||||
typedef std::function<void(NetworkTable* parent, wpi::StringRef name,
|
||||
std::shared_ptr<NetworkTable> table)>
|
||||
TableListener;
|
||||
using TableListener =
|
||||
std::function<void(NetworkTable* parent, std::string_view name,
|
||||
std::shared_ptr<NetworkTable> table)>;
|
||||
|
||||
} // namespace nt
|
||||
|
||||
|
||||
@@ -11,13 +11,12 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/StringRef.h>
|
||||
#include <wpi/Twine.h>
|
||||
|
||||
#include "networktables/NetworkTableValue.h"
|
||||
|
||||
@@ -98,7 +97,7 @@ struct ConnectionInfo {
|
||||
/** NetworkTables RPC Version 1 Definition Parameter */
|
||||
struct RpcParamDef {
|
||||
RpcParamDef() = default;
|
||||
RpcParamDef(wpi::StringRef name_, std::shared_ptr<Value> def_value_)
|
||||
RpcParamDef(std::string_view name_, std::shared_ptr<Value> def_value_)
|
||||
: name(name_), def_value(std::move(def_value_)) {}
|
||||
|
||||
std::string name;
|
||||
@@ -108,7 +107,7 @@ struct RpcParamDef {
|
||||
/** NetworkTables RPC Version 1 Definition Result */
|
||||
struct RpcResultDef {
|
||||
RpcResultDef() = default;
|
||||
RpcResultDef(wpi::StringRef name_, NT_Type type_)
|
||||
RpcResultDef(std::string_view name_, NT_Type type_)
|
||||
: name(name_), type(type_) {}
|
||||
|
||||
std::string name;
|
||||
@@ -127,8 +126,8 @@ struct RpcDefinition {
|
||||
class RpcAnswer {
|
||||
public:
|
||||
RpcAnswer() = default;
|
||||
RpcAnswer(NT_Entry entry_, NT_RpcCall call_, wpi::StringRef name_,
|
||||
wpi::StringRef params_, ConnectionInfo conn_)
|
||||
RpcAnswer(NT_Entry entry_, NT_RpcCall call_, std::string_view name_,
|
||||
std::string_view params_, ConnectionInfo conn_)
|
||||
: entry(entry_),
|
||||
call(call_),
|
||||
name(name_),
|
||||
@@ -161,7 +160,7 @@ class RpcAnswer {
|
||||
* @param result result raw data that will be provided to remote caller
|
||||
* @return True if posting the response is valid, otherwise false
|
||||
*/
|
||||
bool PostResponse(wpi::StringRef result) const;
|
||||
bool PostResponse(std::string_view result) const;
|
||||
|
||||
friend void swap(RpcAnswer& first, RpcAnswer& second) {
|
||||
using std::swap;
|
||||
@@ -178,7 +177,7 @@ class EntryNotification {
|
||||
public:
|
||||
EntryNotification() = default;
|
||||
EntryNotification(NT_EntryListener listener_, NT_Entry entry_,
|
||||
wpi::StringRef name_, std::shared_ptr<Value> value_,
|
||||
std::string_view name_, std::shared_ptr<Value> value_,
|
||||
unsigned int flags_)
|
||||
: listener(listener_),
|
||||
entry(entry_),
|
||||
@@ -245,7 +244,7 @@ class LogMessage {
|
||||
public:
|
||||
LogMessage() = default;
|
||||
LogMessage(NT_Logger logger_, unsigned int level_, const char* filename_,
|
||||
unsigned int line_, wpi::StringRef message_)
|
||||
unsigned int line_, std::string_view message_)
|
||||
: logger(logger_),
|
||||
level(level_),
|
||||
filename(filename_),
|
||||
@@ -327,7 +326,7 @@ NT_Inst GetInstanceFromHandle(NT_Handle handle);
|
||||
* @param name entry name (UTF-8 string)
|
||||
* @return entry handle
|
||||
*/
|
||||
NT_Entry GetEntry(NT_Inst inst, const wpi::Twine& name);
|
||||
NT_Entry GetEntry(NT_Inst inst, std::string_view name);
|
||||
|
||||
/**
|
||||
* Get Entry Handles.
|
||||
@@ -343,7 +342,7 @@ NT_Entry GetEntry(NT_Inst inst, const wpi::Twine& name);
|
||||
* as a "don't care"
|
||||
* @return Array of entry handles.
|
||||
*/
|
||||
std::vector<NT_Entry> GetEntries(NT_Inst inst, const wpi::Twine& prefix,
|
||||
std::vector<NT_Entry> GetEntries(NT_Inst inst, std::string_view prefix,
|
||||
unsigned int types);
|
||||
|
||||
/**
|
||||
@@ -484,7 +483,7 @@ void DeleteAllEntries(NT_Inst inst);
|
||||
* as a "don't care"
|
||||
* @return Array of entry information.
|
||||
*/
|
||||
std::vector<EntryInfo> GetEntryInfo(NT_Inst inst, const wpi::Twine& prefix,
|
||||
std::vector<EntryInfo> GetEntryInfo(NT_Inst inst, std::string_view prefix,
|
||||
unsigned int types);
|
||||
|
||||
/**
|
||||
@@ -516,9 +515,9 @@ EntryInfo GetEntryInfo(NT_Entry entry);
|
||||
* @param flags update flags; for example, NT_NOTIFY_NEW if the key
|
||||
* did not previously exist
|
||||
*/
|
||||
typedef std::function<void(NT_EntryListener entry_listener, wpi::StringRef name,
|
||||
std::shared_ptr<Value> value, unsigned int flags)>
|
||||
EntryListenerCallback;
|
||||
using EntryListenerCallback =
|
||||
std::function<void(NT_EntryListener entry_listener, std::string_view name,
|
||||
std::shared_ptr<Value> value, unsigned int flags)>;
|
||||
|
||||
/**
|
||||
* Add a listener for all entries starting with a certain prefix.
|
||||
@@ -530,7 +529,7 @@ typedef std::function<void(NT_EntryListener entry_listener, wpi::StringRef name,
|
||||
* @return Listener handle
|
||||
*/
|
||||
NT_EntryListener AddEntryListener(
|
||||
NT_Inst inst, const wpi::Twine& prefix,
|
||||
NT_Inst inst, std::string_view prefix,
|
||||
std::function<void(const EntryNotification& event)> callback,
|
||||
unsigned int flags);
|
||||
|
||||
@@ -578,7 +577,7 @@ void DestroyEntryListenerPoller(NT_EntryListenerPoller poller);
|
||||
* @return Listener handle
|
||||
*/
|
||||
NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller,
|
||||
const wpi::Twine& prefix,
|
||||
std::string_view prefix,
|
||||
unsigned int flags);
|
||||
|
||||
/**
|
||||
@@ -787,7 +786,7 @@ bool WaitForConnectionListenerQueue(NT_Inst inst, double timeout);
|
||||
* @param callback callback function; note the callback function must call
|
||||
* PostRpcResponse() to provide a response to the call
|
||||
*/
|
||||
void CreateRpc(NT_Entry entry, wpi::StringRef def,
|
||||
void CreateRpc(NT_Entry entry, std::string_view def,
|
||||
std::function<void(const RpcAnswer& answer)> callback);
|
||||
|
||||
/**
|
||||
@@ -820,7 +819,7 @@ void DestroyRpcCallPoller(NT_RpcCallPoller poller);
|
||||
* @param def RPC definition
|
||||
* @param poller poller handle
|
||||
*/
|
||||
void CreatePolledRpc(NT_Entry entry, wpi::StringRef def,
|
||||
void CreatePolledRpc(NT_Entry entry, std::string_view def,
|
||||
NT_RpcCallPoller poller);
|
||||
|
||||
/**
|
||||
@@ -884,7 +883,7 @@ bool WaitForRpcCallQueue(NT_Inst inst, double timeout);
|
||||
* @param result result raw data that will be provided to remote caller
|
||||
* @return true if the response was posted, otherwise false
|
||||
*/
|
||||
bool PostRpcResponse(NT_Entry entry, NT_RpcCall call, wpi::StringRef result);
|
||||
bool PostRpcResponse(NT_Entry entry, NT_RpcCall call, std::string_view result);
|
||||
|
||||
/**
|
||||
* Call a RPC function. May be used on either the client or server.
|
||||
@@ -897,7 +896,7 @@ bool PostRpcResponse(NT_Entry entry, NT_RpcCall call, wpi::StringRef result);
|
||||
* @return RPC call handle (for use with GetRpcResult() or
|
||||
* CancelRpcResult()).
|
||||
*/
|
||||
NT_RpcCall CallRpc(NT_Entry entry, wpi::StringRef params);
|
||||
NT_RpcCall CallRpc(NT_Entry entry, std::string_view params);
|
||||
|
||||
/**
|
||||
* Get the result (return value) of a RPC call. This function blocks until
|
||||
@@ -948,7 +947,7 @@ std::string PackRpcDefinition(const RpcDefinition& def);
|
||||
* @param def RPC version 1 definition (output)
|
||||
* @return True if successfully unpacked, false otherwise.
|
||||
*/
|
||||
bool UnpackRpcDefinition(wpi::StringRef packed, RpcDefinition* def);
|
||||
bool UnpackRpcDefinition(std::string_view packed, RpcDefinition* def);
|
||||
|
||||
/**
|
||||
* Pack RPC values as required for RPC version 1 definition messages.
|
||||
@@ -966,7 +965,7 @@ std::string PackRpcValues(wpi::ArrayRef<std::shared_ptr<Value>> values);
|
||||
* @return Array of values.
|
||||
*/
|
||||
std::vector<std::shared_ptr<Value>> UnpackRpcValues(
|
||||
wpi::StringRef packed, wpi::ArrayRef<NT_Type> types);
|
||||
std::string_view packed, wpi::ArrayRef<NT_Type> types);
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -983,7 +982,7 @@ std::vector<std::shared_ptr<Value>> UnpackRpcValues(
|
||||
* @param inst instance handle
|
||||
* @param name identity to advertise
|
||||
*/
|
||||
void SetNetworkIdentity(NT_Inst inst, const wpi::Twine& name);
|
||||
void SetNetworkIdentity(NT_Inst inst, std::string_view name);
|
||||
|
||||
/**
|
||||
* Get the current network mode.
|
||||
@@ -1016,7 +1015,7 @@ void StopLocal(NT_Inst inst);
|
||||
* address. (UTF-8 string, null terminated)
|
||||
* @param port port to communicate over.
|
||||
*/
|
||||
void StartServer(NT_Inst inst, const wpi::Twine& persist_filename,
|
||||
void StartServer(NT_Inst inst, std::string_view persist_filename,
|
||||
const char* listen_address, unsigned int port);
|
||||
|
||||
/**
|
||||
@@ -1051,7 +1050,7 @@ void StartClient(NT_Inst inst, const char* server_name, unsigned int port);
|
||||
*/
|
||||
void StartClient(
|
||||
NT_Inst inst,
|
||||
wpi::ArrayRef<std::pair<wpi::StringRef, unsigned int>> servers);
|
||||
wpi::ArrayRef<std::pair<std::string_view, unsigned int>> servers);
|
||||
|
||||
/**
|
||||
* Starts a client using commonly known robot addresses for the specified
|
||||
@@ -1086,8 +1085,9 @@ void SetServer(NT_Inst inst, const char* server_name, unsigned int port);
|
||||
* @param inst instance handle
|
||||
* @param servers array of server name and port pairs
|
||||
*/
|
||||
void SetServer(NT_Inst inst,
|
||||
wpi::ArrayRef<std::pair<wpi::StringRef, unsigned int>> servers);
|
||||
void SetServer(
|
||||
NT_Inst inst,
|
||||
wpi::ArrayRef<std::pair<std::string_view, unsigned int>> servers);
|
||||
|
||||
/**
|
||||
* Sets server addresses and port for client (without restarting client).
|
||||
@@ -1173,7 +1173,7 @@ bool IsConnected(NT_Inst inst);
|
||||
* @param filename filename
|
||||
* @return error string, or nullptr if successful
|
||||
*/
|
||||
const char* SavePersistent(NT_Inst inst, const wpi::Twine& filename);
|
||||
const char* SavePersistent(NT_Inst inst, std::string_view filename);
|
||||
|
||||
/**
|
||||
* Load persistent values from a file. The server automatically does this
|
||||
@@ -1186,7 +1186,7 @@ const char* SavePersistent(NT_Inst inst, const wpi::Twine& filename);
|
||||
* @return error string, or nullptr if successful
|
||||
*/
|
||||
const char* LoadPersistent(
|
||||
NT_Inst inst, const wpi::Twine& filename,
|
||||
NT_Inst inst, std::string_view filename,
|
||||
std::function<void(size_t line, const char* msg)> warn);
|
||||
|
||||
/**
|
||||
@@ -1198,8 +1198,8 @@ const char* LoadPersistent(
|
||||
* @param prefix save only keys starting with this prefix
|
||||
* @return error string, or nullptr if successful
|
||||
*/
|
||||
const char* SaveEntries(NT_Inst inst, const wpi::Twine& filename,
|
||||
const wpi::Twine& prefix);
|
||||
const char* SaveEntries(NT_Inst inst, std::string_view filename,
|
||||
std::string_view prefix);
|
||||
|
||||
/**
|
||||
* Load table values from a file. The file format used is identical to
|
||||
@@ -1211,8 +1211,8 @@ const char* SaveEntries(NT_Inst inst, const wpi::Twine& filename,
|
||||
* @param warn callback function for warnings
|
||||
* @return error string, or nullptr if successful
|
||||
*/
|
||||
const char* LoadEntries(NT_Inst inst, const wpi::Twine& filename,
|
||||
const wpi::Twine& prefix,
|
||||
const char* LoadEntries(NT_Inst inst, std::string_view filename,
|
||||
std::string_view prefix,
|
||||
std::function<void(size_t line, const char* msg)> warn);
|
||||
|
||||
/** @} */
|
||||
@@ -1339,7 +1339,7 @@ bool WaitForLoggerQueue(NT_Inst inst, double timeout);
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
||||
inline bool RpcAnswer::PostResponse(wpi::StringRef result) const {
|
||||
inline bool RpcAnswer::PostResponse(std::string_view result) const {
|
||||
auto ret = PostRpcResponse(entry, call, result);
|
||||
call = 0;
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user