mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilibc] Add mechanism to reset various global structures (#4007)
This commit is contained in:
@@ -30,6 +30,14 @@ static Instance& GetInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
#ifndef __FRC_ROBORIO__
|
||||
namespace frc::impl {
|
||||
void ResetPreferencesInstance() {
|
||||
GetInstance() = Instance();
|
||||
}
|
||||
} // namespace frc::impl
|
||||
#endif
|
||||
|
||||
Preferences* Preferences::GetInstance() {
|
||||
::GetInstance();
|
||||
static Preferences instance;
|
||||
|
||||
@@ -48,11 +48,23 @@ struct Instance {
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static Instance& GetInstance() {
|
||||
static Instance instance;
|
||||
static std::unique_ptr<Instance>& GetInstanceHolder() {
|
||||
static std::unique_ptr<Instance> instance = std::make_unique<Instance>();
|
||||
return instance;
|
||||
}
|
||||
|
||||
static Instance& GetInstance() {
|
||||
return *GetInstanceHolder();
|
||||
}
|
||||
|
||||
#ifndef __FRC_ROBORIO__
|
||||
namespace frc::impl {
|
||||
void ResetLiveWindow() {
|
||||
std::make_unique<Instance>().swap(GetInstanceHolder());
|
||||
}
|
||||
} // namespace frc::impl
|
||||
#endif
|
||||
|
||||
std::shared_ptr<Component> Instance::GetOrAdd(wpi::Sendable* sendable) {
|
||||
auto data = std::static_pointer_cast<Component>(
|
||||
wpi::SendableRegistry::GetData(sendable, dataHandle));
|
||||
|
||||
@@ -29,11 +29,23 @@ struct Instance {
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static Instance& GetInstance() {
|
||||
static Instance instance;
|
||||
static std::unique_ptr<Instance>& GetInstanceHolder() {
|
||||
static std::unique_ptr<Instance> instance = std::make_unique<Instance>();
|
||||
return instance;
|
||||
}
|
||||
|
||||
static Instance& GetInstance() {
|
||||
return *GetInstanceHolder();
|
||||
}
|
||||
|
||||
#ifndef __FRC_ROBORIO__
|
||||
namespace frc::impl {
|
||||
void ResetSmartDashboardInstance() {
|
||||
std::make_unique<Instance>().swap(GetInstanceHolder());
|
||||
}
|
||||
} // namespace frc::impl
|
||||
#endif
|
||||
|
||||
void SmartDashboard::init() {
|
||||
GetInstance();
|
||||
}
|
||||
|
||||
@@ -60,11 +60,24 @@ Component& SendableRegistryInst::GetOrAdd(void* sendable,
|
||||
return *components[compUid - 1];
|
||||
}
|
||||
|
||||
static SendableRegistryInst& GetInstance() {
|
||||
static SendableRegistryInst instance;
|
||||
static std::unique_ptr<SendableRegistryInst>& GetInstanceHolder() {
|
||||
static std::unique_ptr<SendableRegistryInst> instance =
|
||||
std::make_unique<SendableRegistryInst>();
|
||||
return instance;
|
||||
}
|
||||
|
||||
static SendableRegistryInst& GetInstance() {
|
||||
return *GetInstanceHolder();
|
||||
}
|
||||
|
||||
#ifndef __FRC_ROBORIO__
|
||||
namespace wpi::impl {
|
||||
void ResetSendableRegistry() {
|
||||
std::make_unique<SendableRegistryInst>().swap(GetInstanceHolder());
|
||||
}
|
||||
} // namespace wpi::impl
|
||||
#endif
|
||||
|
||||
void SendableRegistry::SetLiveWindowBuilderFactory(
|
||||
std::function<std::unique_ptr<SendableBuilder>()> factory) {
|
||||
GetInstance().liveWindowFactory = std::move(factory);
|
||||
|
||||
Reference in New Issue
Block a user