simulavr  1.1.0
avrfactory.h
Go to the documentation of this file.
1 /*
2  ****************************************************************************
3  *
4  * simulavr - A simulator for the Atmel AVR family of microcontrollers.
5  * Copyright (C) 2001, 2002, 2003 Klaus Rudolph
6  * Copyright (C) 2007 Onno Kortmann
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  ****************************************************************************
23  *
24  * $Id$
25  */
26 
27 #ifndef AVRFACTORY
28 #define AVRFACTORY
29 
30 #include <string>
31 
32 class AvrDevice;
33 
35 
39 class AvrFactory {
40 
41  public:
42  typedef AvrDevice*(*AvrDeviceCreator)();
43 
48  AvrDevice* makeDevice(const char *config);
49 
51  static AvrFactory& instance();
52 
55  static std::vector<std::string> &supportedDevices();
56 
58  static void reg(const std::string name,
59  AvrDeviceCreator create);
60 
61  private:
64  std::map<std::string, AvrFactory::AvrDeviceCreator> devmap;
65 };
66 
69 #define AVR_REGISTER(name, class) \
70  struct AVRFactoryEntryMaker_ ## name { \
71  public: \
72  static AvrDevice *create_one() { \
73  return new class; \
74  } \
75  AVRFactoryEntryMaker_ ## name() { \
76  AvrFactory::reg(#name, create_one); \
77  } \
78  }; \
79  AVRFactoryEntryMaker_ ## name maker_ ##name;
80 
81 #endif
Basic AVR device, contains the core functionality.
Definition: avrdevice.h:66
static std::vector< std::string > & supportedDevices()
Definition: avrfactory.cpp:64
Produces AVR devices.
Definition: avrfactory.h:39
static AvrFactory & instance()
Singleton class access.
Definition: avrfactory.cpp:73
static void reg(const std::string name, AvrDeviceCreator create)
Register a creation static method with the factory.
Definition: avrfactory.cpp:38
AvrDevice * makeDevice(const char *config)
Definition: avrfactory.cpp:51
std::map< std::string, AvrFactory::AvrDeviceCreator > devmap
map of registered AVR devices
Definition: avrfactory.h:64
AvrDevice *(* AvrDeviceCreator)()
Definition: avrfactory.h:42