diff options
author | rubidium <rubidium@openttd.org> | 2013-11-25 14:26:46 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2013-11-25 14:26:46 +0000 |
commit | 6996b441d9d104bc6d7041b64362f4426425f600 (patch) | |
tree | 074989fd03a7f672e137423688c40d1efc466a95 /src/driver.cpp | |
parent | a399fc667ce506abcdcfd853d1ad58f0bb8dbb4f (diff) | |
download | openttd-6996b441d9d104bc6d7041b64362f4426425f600.tar.xz |
(svn r26107) -Codechange/cleanup: remove some coding bloat and simplify the driver factory instatiations
Diffstat (limited to 'src/driver.cpp')
-rw-r--r-- | src/driver.cpp | 51 |
1 files changed, 21 insertions, 30 deletions
diff --git a/src/driver.cpp b/src/driver.cpp index 6419cdd4c..dd03e5e7b 100644 --- a/src/driver.cpp +++ b/src/driver.cpp @@ -165,33 +165,6 @@ Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type type) } /** - * Register a driver internally, based on its name. - * @param name the name of the driver. - * @param type the type of driver to register - * @param priority the priority; how badly do we want this as default? - * @note an assert() will be trigger if 2 driver with the same name try to register. - */ -void DriverFactoryBase::RegisterDriver(const char *name, Driver::Type type, int priority) -{ - /* Don't register nameless Drivers */ - if (name == NULL) return; - - this->name = strdup(name); - this->type = type; - this->priority = priority; - - /* Prefix the name with driver type to make it unique */ - char buf[32]; - strecpy(buf, GetDriverTypeName(type), lastof(buf)); - strecpy(buf + 5, name, lastof(buf)); - - const char *longname = strdup(buf); - - std::pair<Drivers::iterator, bool> P = GetDrivers().insert(Drivers::value_type(longname, this)); - assert(P.second); -} - -/** * Build a human readable list of available drivers, grouped by type. * @param p The buffer to write to. * @param last The last element in the buffer. @@ -219,12 +192,31 @@ char *DriverFactoryBase::GetDriversInfo(char *p, const char *last) } /** + * Construct a new DriverFactory. + * @param type The type of driver. + * @param priority The priority within the driver class. + * @param name The name of the driver. + * @param description A long-ish description of the driver. + */ +DriverFactoryBase::DriverFactoryBase(Driver::Type type, int priority, const char *name, const char *description) : + type(type), priority(priority), name(name), description(description) +{ + /* Prefix the name with driver type to make it unique */ + char buf[32]; + strecpy(buf, GetDriverTypeName(type), lastof(buf)); + strecpy(buf + 5, name, lastof(buf)); + + const char *longname = strdup(buf); + + std::pair<Drivers::iterator, bool> P = GetDrivers().insert(Drivers::value_type(longname, this)); + assert(P.second); +} + +/** * Frees memory used for this->name */ DriverFactoryBase::~DriverFactoryBase() { - if (this->name == NULL) return; - /* Prefix the name with driver type to make it unique */ char buf[32]; strecpy(buf, GetDriverTypeName(type), lastof(buf)); @@ -239,5 +231,4 @@ DriverFactoryBase::~DriverFactoryBase() free(longname); if (GetDrivers().empty()) delete &GetDrivers(); - free(this->name); } |