Codechange: Use unique_ptr to manage drivers.

This commit is contained in:
Peter Nelson
2025-03-26 23:54:55 +00:00
committed by Peter Nelson
parent c3457cd4c0
commit d95422561b
27 changed files with 38 additions and 43 deletions

View File

@@ -81,10 +81,10 @@ private:
* @param type The type to get the driver for.
* @return The active driver.
*/
static Driver **GetActiveDriver(Driver::Type type)
static std::unique_ptr<Driver> &GetActiveDriver(Driver::Type type)
{
static Driver *s_driver[3] = { nullptr, nullptr, nullptr };
return &s_driver[type];
static std::array<std::unique_ptr<Driver>, Driver::DT_END> s_driver{};
return s_driver[type];
}
/**
@@ -123,7 +123,7 @@ public:
static void ShutdownDrivers()
{
for (Driver::Type dt = Driver::DT_BEGIN; dt < Driver::DT_END; dt++) {
Driver *driver = *GetActiveDriver(dt);
auto &driver = GetActiveDriver(dt);
if (driver != nullptr) driver->Stop();
}
}
@@ -144,7 +144,7 @@ public:
* Create an instance of this driver-class.
* @return The instance.
*/
virtual Driver *CreateInstance() const = 0;
virtual std::unique_ptr<Driver> CreateInstance() const = 0;
};
#endif /* DRIVER_H */