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