OpenTTD: src/driver.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

driver.h
Go to the documentation of this file.
1 /* $Id: driver.h 26538 2014-04-28 21:06:51Z rubidium $ */
2
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 */
9
12 #ifndef DRIVER_H
13 #define DRIVER_H
14
15 #include "core/enum_type.hpp"
16 #include "core/string_compare_type.hpp"
17 #include <map>
18
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);
22
24 class Driver {
25 public:
31 virtual const char *Start(const char * const *parm) = 0;
32
36 virtual void Stop() = 0;
37
38 virtual ~Driver() { }
39
41 enum Type {
42 DT_BEGIN = 0,
43 DT_MUSIC = 0,
44 DT_SOUND,
45 DT_VIDEO,
46 DT_END,
47 };
48
53 virtual const char *GetName() const = 0;
54 };
55
56 DECLARE_POSTFIX_INCREMENT(Driver::Type)
57
58
59
60 class DriverFactoryBase {
61 private:
62 friend class MusicDriver;
63 friend class SoundDriver;
64 friend class VideoDriver;
65
66 Driver::Type type;
67 int priority;
68 const char *name;
69 const char *description;
70
71 typedef std::map<const char *, DriverFactoryBase *, StringCompare> Drivers;
72
76 static Drivers &GetDrivers()
77 {
78 static Drivers &s_drivers = *new Drivers();
79 return s_drivers;
80 }
81
87 static Driver **GetActiveDriver(Driver::Type type)
88 {
89 static Driver *s_driver[3] = { NULL, NULL, NULL };
90 return &s_driver[type];
91 }
92
98 static const char *GetDriverTypeName(Driver::Type type)
99 {
100 static const char * const driver_type_name[] = { "music", "sound", "video" };
101 return driver_type_name[type];
102 }
103
104 static bool SelectDriverImpl(const char *name, Driver::Type type);
105
106 protected:
107 DriverFactoryBase(Driver::Type type, int priority, const char *name, const char *description);
108
109 virtual ~DriverFactoryBase();
110
111 public:
115 static void ShutdownDrivers()
116 {
117 for (Driver::Type dt = Driver::DT_BEGIN; dt < Driver::DT_END; dt++) {
118 Driver *driver = *GetActiveDriver(dt);
119 if (driver != NULL) driver->Stop();
120 }
121 }
122
123 static void SelectDriver(const char *name, Driver::Type type);
124 static char *GetDriversInfo(char *p, const char *last);
125
130 const char *GetDescription() const
131 {
132 return this->description;
133 }
134
139 virtual Driver *CreateInstance() const = 0;
140 };
141
142 #endif /* DRIVER_H */