driver.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef DRIVER_H
00013 #define DRIVER_H
00014
00015 #include "core/enum_type.hpp"
00016 #include "core/string_compare_type.hpp"
00017 #include <map>
00018
00019 const char *GetDriverParam(const char * const *parm, const char *name);
00020 bool GetDriverParamBool(const char * const *parm, const char *name);
00021 int GetDriverParamInt(const char * const *parm, const char *name, int def);
00022
00023 class Driver {
00024 public:
00025 virtual const char *Start(const char * const *parm) = 0;
00026
00027 virtual void Stop() = 0;
00028
00029 virtual ~Driver() { }
00030
00031 enum Type {
00032 DT_BEGIN = 0,
00033 DT_SOUND = 0,
00034 DT_MUSIC,
00035 DT_VIDEO,
00036 DT_END,
00037 };
00038
00039 virtual const char *GetName() const = 0;
00040 };
00041
00042 DECLARE_POSTFIX_INCREMENT(Driver::Type);
00043
00044
00045 class DriverFactoryBase {
00046 private:
00047 Driver::Type type;
00048 const char *name;
00049 int priority;
00050
00051 typedef std::map<const char *, DriverFactoryBase *, StringCompare> Drivers;
00052
00053 static Drivers &GetDrivers()
00054 {
00055 static Drivers &s_drivers = *new Drivers();
00056 return s_drivers;
00057 }
00058
00059 static Driver **GetActiveDriver(Driver::Type type)
00060 {
00061 static Driver *s_driver[3] = { NULL, NULL, NULL };
00062 return &s_driver[type];
00063 }
00064
00065 static const char *GetDriverTypeName(Driver::Type type)
00066 {
00067 static const char * const driver_type_name[] = { "sound", "music", "video" };
00068 return driver_type_name[type];
00069 }
00070
00071 protected:
00072 void RegisterDriver(const char *name, Driver::Type type, int priority);
00073
00074 public:
00075 DriverFactoryBase() :
00076 name(NULL)
00077 {}
00078
00079 virtual ~DriverFactoryBase();
00080
00083 static void ShutdownDrivers()
00084 {
00085 for (Driver::Type dt = Driver::DT_BEGIN; dt < Driver::DT_END; dt++) {
00086 Driver *driver = *GetActiveDriver(dt);
00087 if (driver != NULL) driver->Stop();
00088 }
00089 }
00090
00091 static Driver *SelectDriver(const char *name, Driver::Type type);
00092 static char *GetDriversInfo(char *p, const char *last);
00093
00097 virtual const char *GetDescription() = 0;
00098
00102 virtual Driver *CreateInstance() = 0;
00103 };
00104
00105 #endif