00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef AVRFACTORY
00028 #define AVRFACTORY
00029
00030 #include <string>
00031
00032 class AvrDevice;
00033
00035
00039 class AvrFactory {
00040
00041 public:
00042 typedef AvrDevice*(*AvrDeviceCreator)();
00043
00048 AvrDevice* makeDevice(const char *config);
00049
00051 static AvrFactory& instance();
00052
00055 static std::string supportedDevices();
00056
00058 static void reg(const std::string name,
00059 AvrDeviceCreator create);
00060
00061 private:
00062 AvrFactory() {}
00064 std::map<std::string, AvrFactory::AvrDeviceCreator> devmap;
00065 };
00066
00069 #define AVR_REGISTER(name, class) \
00070 struct AVRFactoryEntryMaker_ ## name { \
00071 public: \
00072 static AvrDevice *create_one() { \
00073 return new class; \
00074 } \
00075 AVRFactoryEntryMaker_ ## name() { \
00076 AvrFactory::reg(#name, create_one); \
00077 } \
00078 }; \
00079 AVRFactoryEntryMaker_ ## name maker_ ##name;
00080
00081 #endif