mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
[wpilib] Deprecate getInstance() in favor of static functions (#3440)
Co-authored-by: Noam Zaks <imnoamzaks@gmail.com>
This commit is contained in:
@@ -22,25 +22,16 @@ class SendableBuilder;
|
||||
*/
|
||||
class SendableRegistry {
|
||||
public:
|
||||
SendableRegistry(const SendableRegistry&) = delete;
|
||||
SendableRegistry& operator=(const SendableRegistry&) = delete;
|
||||
SendableRegistry() = delete;
|
||||
|
||||
using UID = size_t;
|
||||
|
||||
/**
|
||||
* Gets an instance of the SendableRegistry class.
|
||||
*
|
||||
* This is a singleton to guarantee that there is only a single instance
|
||||
* regardless of how many times GetInstance is called.
|
||||
*/
|
||||
static SendableRegistry& GetInstance();
|
||||
|
||||
/**
|
||||
* Sets the factory for LiveWindow builders.
|
||||
*
|
||||
* @param factory factory function
|
||||
*/
|
||||
void SetLiveWindowBuilderFactory(
|
||||
static void SetLiveWindowBuilderFactory(
|
||||
std::function<std::unique_ptr<SendableBuilder>()> factory);
|
||||
|
||||
/**
|
||||
@@ -49,7 +40,7 @@ class SendableRegistry {
|
||||
* @param sendable object to add
|
||||
* @param name component name
|
||||
*/
|
||||
void Add(Sendable* sendable, std::string_view name);
|
||||
static void Add(Sendable* sendable, std::string_view name);
|
||||
|
||||
/**
|
||||
* Adds an object to the registry.
|
||||
@@ -59,7 +50,7 @@ class SendableRegistry {
|
||||
* the value
|
||||
* @param channel The channel number the device is plugged into
|
||||
*/
|
||||
void Add(Sendable* sendable, std::string_view moduleType, int channel);
|
||||
static void Add(Sendable* sendable, std::string_view moduleType, int channel);
|
||||
|
||||
/**
|
||||
* Adds an object to the registry.
|
||||
@@ -70,8 +61,8 @@ class SendableRegistry {
|
||||
* @param moduleNumber The number of the particular module type
|
||||
* @param channel The channel number the device is plugged into
|
||||
*/
|
||||
void Add(Sendable* sendable, std::string_view moduleType, int moduleNumber,
|
||||
int channel);
|
||||
static void Add(Sendable* sendable, std::string_view moduleType,
|
||||
int moduleNumber, int channel);
|
||||
|
||||
/**
|
||||
* Adds an object to the registry.
|
||||
@@ -80,8 +71,8 @@ class SendableRegistry {
|
||||
* @param subsystem subsystem name
|
||||
* @param name component name
|
||||
*/
|
||||
void Add(Sendable* sendable, std::string_view subsystem,
|
||||
std::string_view name);
|
||||
static void Add(Sendable* sendable, std::string_view subsystem,
|
||||
std::string_view name);
|
||||
|
||||
/**
|
||||
* Adds an object to the registry and LiveWindow.
|
||||
@@ -89,7 +80,7 @@ class SendableRegistry {
|
||||
* @param sendable object to add
|
||||
* @param name component name
|
||||
*/
|
||||
void AddLW(Sendable* sendable, std::string_view name);
|
||||
static void AddLW(Sendable* sendable, std::string_view name);
|
||||
|
||||
/**
|
||||
* Adds an object to the registry and LiveWindow.
|
||||
@@ -99,7 +90,8 @@ class SendableRegistry {
|
||||
* the value
|
||||
* @param channel The channel number the device is plugged into
|
||||
*/
|
||||
void AddLW(Sendable* sendable, std::string_view moduleType, int channel);
|
||||
static void AddLW(Sendable* sendable, std::string_view moduleType,
|
||||
int channel);
|
||||
|
||||
/**
|
||||
* Adds an object to the registry and LiveWindow.
|
||||
@@ -110,8 +102,8 @@ class SendableRegistry {
|
||||
* @param moduleNumber The number of the particular module type
|
||||
* @param channel The channel number the device is plugged into
|
||||
*/
|
||||
void AddLW(Sendable* sendable, std::string_view moduleType, int moduleNumber,
|
||||
int channel);
|
||||
static void AddLW(Sendable* sendable, std::string_view moduleType,
|
||||
int moduleNumber, int channel);
|
||||
|
||||
/**
|
||||
* Adds an object to the registry and LiveWindow.
|
||||
@@ -120,8 +112,8 @@ class SendableRegistry {
|
||||
* @param subsystem subsystem name
|
||||
* @param name component name
|
||||
*/
|
||||
void AddLW(Sendable* sendable, std::string_view subsystem,
|
||||
std::string_view name);
|
||||
static void AddLW(Sendable* sendable, std::string_view subsystem,
|
||||
std::string_view name);
|
||||
|
||||
/**
|
||||
* Adds a child object to an object. Adds the child object to the registry
|
||||
@@ -130,7 +122,7 @@ class SendableRegistry {
|
||||
* @param parent parent object
|
||||
* @param child child object
|
||||
*/
|
||||
void AddChild(Sendable* parent, Sendable* child);
|
||||
static void AddChild(Sendable* parent, Sendable* child);
|
||||
|
||||
/**
|
||||
* Adds a child object to an object. Adds the child object to the registry
|
||||
@@ -139,7 +131,7 @@ class SendableRegistry {
|
||||
* @param parent parent object
|
||||
* @param child child object
|
||||
*/
|
||||
void AddChild(Sendable* parent, void* child);
|
||||
static void AddChild(Sendable* parent, void* child);
|
||||
|
||||
/**
|
||||
* Removes an object from the registry.
|
||||
@@ -147,7 +139,7 @@ class SendableRegistry {
|
||||
* @param sendable object to remove
|
||||
* @return true if the object was removed; false if it was not present
|
||||
*/
|
||||
bool Remove(Sendable* sendable);
|
||||
static bool Remove(Sendable* sendable);
|
||||
|
||||
/**
|
||||
* Moves an object in the registry (for use in move constructors/assignments).
|
||||
@@ -155,7 +147,7 @@ class SendableRegistry {
|
||||
* @param to new object
|
||||
* @param from old object
|
||||
*/
|
||||
void Move(Sendable* to, Sendable* from);
|
||||
static void Move(Sendable* to, Sendable* from);
|
||||
|
||||
/**
|
||||
* Determines if an object is in the registry.
|
||||
@@ -163,7 +155,7 @@ class SendableRegistry {
|
||||
* @param sendable object to check
|
||||
* @return True if in registry, false if not.
|
||||
*/
|
||||
bool Contains(const Sendable* sendable) const;
|
||||
static bool Contains(const Sendable* sendable);
|
||||
|
||||
/**
|
||||
* Gets the name of an object.
|
||||
@@ -171,7 +163,7 @@ class SendableRegistry {
|
||||
* @param sendable object
|
||||
* @return Name (empty if object is not in registry)
|
||||
*/
|
||||
std::string GetName(const Sendable* sendable) const;
|
||||
static std::string GetName(const Sendable* sendable);
|
||||
|
||||
/**
|
||||
* Sets the name of an object.
|
||||
@@ -179,7 +171,7 @@ class SendableRegistry {
|
||||
* @param sendable object
|
||||
* @param name name
|
||||
*/
|
||||
void SetName(Sendable* sendable, std::string_view name);
|
||||
static void SetName(Sendable* sendable, std::string_view name);
|
||||
|
||||
/**
|
||||
* Sets the name of an object with a channel number.
|
||||
@@ -189,7 +181,8 @@ class SendableRegistry {
|
||||
* the value
|
||||
* @param channel The channel number the device is plugged into
|
||||
*/
|
||||
void SetName(Sendable* sendable, std::string_view moduleType, int channel);
|
||||
static void SetName(Sendable* sendable, std::string_view moduleType,
|
||||
int channel);
|
||||
|
||||
/**
|
||||
* Sets the name of an object with a module and channel number.
|
||||
@@ -200,8 +193,8 @@ class SendableRegistry {
|
||||
* @param moduleNumber The number of the particular module type
|
||||
* @param channel The channel number the device is plugged into
|
||||
*/
|
||||
void SetName(Sendable* sendable, std::string_view moduleType,
|
||||
int moduleNumber, int channel);
|
||||
static void SetName(Sendable* sendable, std::string_view moduleType,
|
||||
int moduleNumber, int channel);
|
||||
|
||||
/**
|
||||
* Sets both the subsystem name and device name of an object.
|
||||
@@ -210,8 +203,8 @@ class SendableRegistry {
|
||||
* @param subsystem subsystem name
|
||||
* @param name device name
|
||||
*/
|
||||
void SetName(Sendable* sendable, std::string_view subsystem,
|
||||
std::string_view name);
|
||||
static void SetName(Sendable* sendable, std::string_view subsystem,
|
||||
std::string_view name);
|
||||
|
||||
/**
|
||||
* Gets the subsystem name of an object.
|
||||
@@ -219,7 +212,7 @@ class SendableRegistry {
|
||||
* @param sendable object
|
||||
* @return Subsystem name (empty if object is not in registry)
|
||||
*/
|
||||
std::string GetSubsystem(const Sendable* sendable) const;
|
||||
static std::string GetSubsystem(const Sendable* sendable);
|
||||
|
||||
/**
|
||||
* Sets the subsystem name of an object.
|
||||
@@ -227,14 +220,14 @@ class SendableRegistry {
|
||||
* @param sendable object
|
||||
* @param subsystem subsystem name
|
||||
*/
|
||||
void SetSubsystem(Sendable* sendable, std::string_view subsystem);
|
||||
static void SetSubsystem(Sendable* sendable, std::string_view subsystem);
|
||||
|
||||
/**
|
||||
* Gets a unique handle for setting/getting data with SetData() and GetData().
|
||||
*
|
||||
* @return Handle
|
||||
*/
|
||||
int GetDataHandle();
|
||||
static int GetDataHandle();
|
||||
|
||||
/**
|
||||
* Associates arbitrary data with an object in the registry.
|
||||
@@ -244,8 +237,8 @@ class SendableRegistry {
|
||||
* @param data data to set
|
||||
* @return Previous data (may be null)
|
||||
*/
|
||||
std::shared_ptr<void> SetData(Sendable* sendable, int handle,
|
||||
std::shared_ptr<void> data);
|
||||
static std::shared_ptr<void> SetData(Sendable* sendable, int handle,
|
||||
std::shared_ptr<void> data);
|
||||
|
||||
/**
|
||||
* Gets arbitrary data associated with an object in the registry.
|
||||
@@ -254,21 +247,21 @@ class SendableRegistry {
|
||||
* @param handle data handle returned by GetDataHandle()
|
||||
* @return data (may be null if none associated)
|
||||
*/
|
||||
std::shared_ptr<void> GetData(Sendable* sendable, int handle);
|
||||
static std::shared_ptr<void> GetData(Sendable* sendable, int handle);
|
||||
|
||||
/**
|
||||
* Enables LiveWindow for an object.
|
||||
*
|
||||
* @param sendable object
|
||||
*/
|
||||
void EnableLiveWindow(Sendable* sendable);
|
||||
static void EnableLiveWindow(Sendable* sendable);
|
||||
|
||||
/**
|
||||
* Disables LiveWindow for an object.
|
||||
*
|
||||
* @param sendable object
|
||||
*/
|
||||
void DisableLiveWindow(Sendable* sendable);
|
||||
static void DisableLiveWindow(Sendable* sendable);
|
||||
|
||||
/**
|
||||
* Get unique id for an object. Since objects can move, use this instead
|
||||
@@ -277,7 +270,7 @@ class SendableRegistry {
|
||||
* @param sendable object
|
||||
* @return unique id
|
||||
*/
|
||||
UID GetUniqueId(Sendable* sendable);
|
||||
static UID GetUniqueId(Sendable* sendable);
|
||||
|
||||
/**
|
||||
* Get sendable object for a given unique id.
|
||||
@@ -285,7 +278,7 @@ class SendableRegistry {
|
||||
* @param uid unique id
|
||||
* @return sendable object (may be null)
|
||||
*/
|
||||
Sendable* GetSendable(UID uid);
|
||||
static Sendable* GetSendable(UID uid);
|
||||
|
||||
/**
|
||||
* Publishes an object in the registry.
|
||||
@@ -293,14 +286,15 @@ class SendableRegistry {
|
||||
* @param sendableUid sendable unique id
|
||||
* @param builder publisher backend
|
||||
*/
|
||||
void Publish(UID sendableUid, std::unique_ptr<SendableBuilder> builder);
|
||||
static void Publish(UID sendableUid,
|
||||
std::unique_ptr<SendableBuilder> builder);
|
||||
|
||||
/**
|
||||
* Updates published information from an object.
|
||||
*
|
||||
* @param sendableUid sendable unique id
|
||||
*/
|
||||
void Update(UID sendableUid);
|
||||
static void Update(UID sendableUid);
|
||||
|
||||
/**
|
||||
* Data passed to ForeachLiveWindow() callback function
|
||||
@@ -332,15 +326,8 @@ class SendableRegistry {
|
||||
* @param dataHandle data handle to get data pointer passed to callback
|
||||
* @param callback function to call for each object
|
||||
*/
|
||||
void ForeachLiveWindow(
|
||||
int dataHandle,
|
||||
wpi::function_ref<void(CallbackData& cbdata)> callback) const;
|
||||
|
||||
private:
|
||||
SendableRegistry();
|
||||
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> m_impl;
|
||||
static void ForeachLiveWindow(
|
||||
int dataHandle, wpi::function_ref<void(CallbackData& cbdata)> callback);
|
||||
};
|
||||
|
||||
} // namespace wpi
|
||||
|
||||
Reference in New Issue
Block a user