Add support for deleted functions
[openttd/fttd.git] / src / driver.h
bloba466d67d008470a44d0c8767dbf572067545e532
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file driver.h Base for all drivers (video, sound, music, etc). */
12 #ifndef DRIVER_H
13 #define DRIVER_H
15 #include "core/enum_type.hpp"
16 #include "core/string_compare_type.hpp"
17 #include <map>
19 const char *GetDriverParam(const char * const *parm, const char *name);
20 bool GetDriverParamBool(const char * const *parm, const char *name);
21 int GetDriverParamInt(const char * const *parm, const char *name, int def);
23 /** A driver for communicating with the user. */
24 class Driver {
25 public:
26 /**
27 * Start this driver.
28 * @param parm Parameters passed to the driver.
29 * @return NULL if everything went okay, otherwise an error message.
31 virtual const char *Start(const char * const *parm) = 0;
33 /**
34 * Stop this driver.
36 virtual void Stop() = 0;
38 virtual ~Driver() { }
40 /** The type of driver */
41 enum Type {
42 DT_BEGIN = 0, ///< Helper for iteration
43 DT_MUSIC = 0, ///< A music driver, needs to be before sound to properly shut down extmidi forked music players
44 DT_SOUND, ///< A sound driver
45 DT_VIDEO, ///< A video driver
46 DT_END, ///< Helper for iteration
49 /**
50 * Get the name of this driver.
51 * @return The name of the driver.
53 virtual const char *GetName() const = 0;
56 DECLARE_POSTFIX_INCREMENT(Driver::Type)
59 /** Base for all driver factories. */
60 class DriverFactoryBase {
61 private:
62 Driver::Type type; ///< The type of driver.
63 int priority; ///< The priority of this factory.
64 const char *name; ///< The name of the drivers of this factory.
65 const char *description; ///< The description of this driver.
67 typedef std::map<const char *, DriverFactoryBase *, StringCompare> Drivers; ///< Type for a map of drivers.
69 /**
70 * Get the map with drivers.
72 static Drivers &GetDrivers()
74 static Drivers &s_drivers = *new Drivers();
75 return s_drivers;
78 /**
79 * Get the active driver for the given type.
80 * @param type The type to get the driver for.
81 * @return The active driver.
83 static Driver **GetActiveDriver(Driver::Type type)
85 static Driver *s_driver[3] = { NULL, NULL, NULL };
86 return &s_driver[type];
89 /**
90 * Get the driver type name.
91 * @param type The type of driver to get the name of.
92 * @return The name of the type.
94 static const char *GetDriverTypeName(Driver::Type type)
96 static const char * const driver_type_name[] = { "music", "sound", "video" };
97 return driver_type_name[type];
100 protected:
101 DriverFactoryBase(Driver::Type type, int priority, const char *name, const char *description);
103 virtual ~DriverFactoryBase();
105 public:
107 * Shuts down all active drivers
109 static void ShutdownDrivers()
111 for (Driver::Type dt = Driver::DT_BEGIN; dt < Driver::DT_END; dt++) {
112 Driver *driver = *GetActiveDriver(dt);
113 if (driver != NULL) driver->Stop();
117 static Driver *SelectDriver(const char *name, Driver::Type type);
118 static char *GetDriversInfo(char *p, const char *last);
121 * Get a nice description of the driver-class.
122 * @return The description.
124 const char *GetDescription() const
126 return this->description;
130 * Create an instance of this driver-class.
131 * @return The instance.
133 virtual Driver *CreateInstance() const = 0;
136 #endif /* DRIVER_H */