Async  0.18.0
AsyncAudioDeviceFactory.h
Go to the documentation of this file.
1 
34 #ifndef ASYNC_AUDIO_DEVICE_FACTORY_INCLUDED
35 #define ASYNC_AUDIO_DEVICE_FACTORY_INCLUDED
36 
37 
38 /****************************************************************************
39  *
40  * System Includes
41  *
42  ****************************************************************************/
43 
44 #include <string>
45 #include <map>
46 
47 
48 /****************************************************************************
49  *
50  * Project Includes
51  *
52  ****************************************************************************/
53 
54 
55 
56 /****************************************************************************
57  *
58  * Local Includes
59  *
60  ****************************************************************************/
61 
62 
63 
64 /****************************************************************************
65  *
66  * Forward declarations
67  *
68  ****************************************************************************/
69 
70 
71 
72 /****************************************************************************
73  *
74  * Namespace
75  *
76  ****************************************************************************/
77 
78 namespace Async
79 {
80 
81 
82 /****************************************************************************
83  *
84  * Forward declarations of classes inside of the declared namespace
85  *
86  ****************************************************************************/
87 
88 class AudioDevice;
89 
90 
91 /****************************************************************************
92  *
93  * Defines & typedefs
94  *
95  ****************************************************************************/
96 
97 #define REGISTER_AUDIO_DEVICE_TYPE(_name, _class) \
98  AudioDevice *create_ ## _class(const string& dev_name) \
99  { return new _class(dev_name); } \
100  static bool _class ## _creator_registered = \
101  AudioDeviceFactory::instance()->registerCreator(_name, \
102  create_ ## _class)
103 
104 
105 
106 /****************************************************************************
107  *
108  * Exported Global Variables
109  *
110  ****************************************************************************/
111 
112 
113 
114 /****************************************************************************
115  *
116  * Class definitions
117  *
118  ****************************************************************************/
119 
130 {
131  public:
132  typedef AudioDevice* (*CreatorFunc)(const std::string &dev_designator);
133 
135  {
136  if (_instance == 0)
137  {
138  _instance = new AudioDeviceFactory;
139  }
140  return _instance;
141  }
142 
146  ~AudioDeviceFactory(void);
147 
153  bool registerCreator(const std::string &name, CreatorFunc creator);
154 
155  AudioDevice *create(const std::string &name, const std::string &dev_name);
156 
157  std::string validDevTypes(void) const;
158 
159  protected:
163  AudioDeviceFactory(void);
164 
165 
166  private:
167  typedef std::map<std::string, CreatorFunc> CreatorMap;
168 
169  static AudioDeviceFactory *_instance;
170 
171  CreatorMap creator_map;
172 
174  AudioDeviceFactory& operator=(const AudioDeviceFactory&);
175 
176 }; /* class AudioDeviceFactory */
177 
178 
179 } /* namespace */
180 
181 #endif /* ASYNC_AUDIO_DEVICE_FACTORY_INCLUDED */
182 
183 
184 
185 /*
186  * This file has not been truncated
187  */
188