mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use fmt::format to create type prefixed driver names
parent
37a3fc4df3
commit
0ab7bc7a2b
|
@ -210,13 +210,11 @@ DriverFactoryBase::DriverFactoryBase(Driver::Type type, int priority, const char
|
||||||
type(type), priority(priority), name(name), description(description)
|
type(type), priority(priority), name(name), description(description)
|
||||||
{
|
{
|
||||||
/* Prefix the name with driver type to make it unique */
|
/* Prefix the name with driver type to make it unique */
|
||||||
char buf[32];
|
std::string typed_name = fmt::format("{}{}", GetDriverTypeName(type), name);
|
||||||
strecpy(buf, GetDriverTypeName(type), lastof(buf));
|
|
||||||
strecpy(buf + 5, name, lastof(buf));
|
|
||||||
|
|
||||||
Drivers &drivers = GetDrivers();
|
Drivers &drivers = GetDrivers();
|
||||||
assert(drivers.find(buf) == drivers.end());
|
assert(drivers.find(typed_name) == drivers.end());
|
||||||
drivers.insert(Drivers::value_type(buf, this));
|
drivers.insert(Drivers::value_type(typed_name, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -225,11 +223,9 @@ DriverFactoryBase::DriverFactoryBase(Driver::Type type, int priority, const char
|
||||||
DriverFactoryBase::~DriverFactoryBase()
|
DriverFactoryBase::~DriverFactoryBase()
|
||||||
{
|
{
|
||||||
/* Prefix the name with driver type to make it unique */
|
/* Prefix the name with driver type to make it unique */
|
||||||
char buf[32];
|
std::string typed_name = fmt::format("{}{}", GetDriverTypeName(type), name);
|
||||||
strecpy(buf, GetDriverTypeName(type), lastof(buf));
|
|
||||||
strecpy(buf + 5, this->name, lastof(buf));
|
|
||||||
|
|
||||||
Drivers::iterator it = GetDrivers().find(buf);
|
Drivers::iterator it = GetDrivers().find(typed_name);
|
||||||
assert(it != GetDrivers().end());
|
assert(it != GetDrivers().end());
|
||||||
|
|
||||||
GetDrivers().erase(it);
|
GetDrivers().erase(it);
|
||||||
|
|
Loading…
Reference in New Issue