Async  0.18.0
AsyncAudioDeviceFactory.h
Go to the documentation of this file.
00001 
00034 #ifndef ASYNC_AUDIO_DEVICE_FACTORY_INCLUDED
00035 #define ASYNC_AUDIO_DEVICE_FACTORY_INCLUDED
00036 
00037 
00038 /****************************************************************************
00039  *
00040  * System Includes
00041  *
00042  ****************************************************************************/
00043 
00044 #include <string>
00045 #include <map>
00046 
00047 
00048 /****************************************************************************
00049  *
00050  * Project Includes
00051  *
00052  ****************************************************************************/
00053 
00054 
00055 
00056 /****************************************************************************
00057  *
00058  * Local Includes
00059  *
00060  ****************************************************************************/
00061 
00062 
00063 
00064 /****************************************************************************
00065  *
00066  * Forward declarations
00067  *
00068  ****************************************************************************/
00069 
00070 
00071 
00072 /****************************************************************************
00073  *
00074  * Namespace
00075  *
00076  ****************************************************************************/
00077 
00078 namespace Async
00079 {
00080 
00081 
00082 /****************************************************************************
00083  *
00084  * Forward declarations of classes inside of the declared namespace
00085  *
00086  ****************************************************************************/
00087 
00088 class AudioDevice;
00089 
00090 
00091 /****************************************************************************
00092  *
00093  * Defines & typedefs
00094  *
00095  ****************************************************************************/
00096 
00097 #define REGISTER_AUDIO_DEVICE_TYPE(_name, _class) \
00098   AudioDevice *create_ ## _class(const string& dev_name) \
00099           { return new _class(dev_name); } \
00100   static bool _class ## _creator_registered = \
00101           AudioDeviceFactory::instance()->registerCreator(_name, \
00102                                                           create_ ## _class)
00103 
00104 
00105 
00106 /****************************************************************************
00107  *
00108  * Exported Global Variables
00109  *
00110  ****************************************************************************/
00111 
00112 
00113 
00114 /****************************************************************************
00115  *
00116  * Class definitions
00117  *
00118  ****************************************************************************/
00119 
00129 class AudioDeviceFactory
00130 {
00131   public:
00132     typedef AudioDevice* (*CreatorFunc)(const std::string &dev_designator);
00133     
00134     static AudioDeviceFactory *instance(void)
00135     {
00136       if (_instance == 0)
00137       {
00138         _instance = new AudioDeviceFactory;
00139       }
00140       return _instance;
00141     }
00142 
00146     ~AudioDeviceFactory(void);
00147   
00153     bool registerCreator(const std::string &name, CreatorFunc creator);
00154 
00155     AudioDevice *create(const std::string &name, const std::string &dev_name);
00156 
00157     std::string validDevTypes(void) const;
00158     
00159   protected:
00163     AudioDeviceFactory(void);
00164   
00165     
00166   private:
00167     typedef std::map<std::string, CreatorFunc> CreatorMap;
00168     
00169     static AudioDeviceFactory *_instance;
00170 
00171     CreatorMap creator_map;
00172     
00173     AudioDeviceFactory(const AudioDeviceFactory&);
00174     AudioDeviceFactory& operator=(const AudioDeviceFactory&);
00175     
00176 };  /* class AudioDeviceFactory */
00177 
00178 
00179 } /* namespace */
00180 
00181 #endif /* ASYNC_AUDIO_DEVICE_FACTORY_INCLUDED */
00182 
00183 
00184 
00185 /*
00186  * This file has not been truncated
00187  */
00188