| [f5a86a] | 1 | /* | 
|---|
|  | 2 | * UIFactory.hpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: Jan 5, 2010 | 
|---|
|  | 5 | *      Author: crueger | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #ifndef UIFACTORY_HPP_ | 
|---|
|  | 9 | #define UIFACTORY_HPP_ | 
|---|
|  | 10 |  | 
|---|
| [cc04b7] | 11 | class MainWindow; | 
|---|
| [f5a86a] | 12 | class Dialog; | 
|---|
| [a2ab15] | 13 | class DialogDescription; | 
|---|
| [d7940e] | 14 |  | 
|---|
|  | 15 | #include "Patterns/Singleton.hpp" | 
|---|
|  | 16 |  | 
|---|
| [9cf88c] | 17 | #include <string> | 
|---|
|  | 18 | #include <map> | 
|---|
|  | 19 | #include <boost/smart_ptr.hpp> | 
|---|
|  | 20 |  | 
|---|
| [dbb474] | 21 | /** | 
|---|
|  | 22 | * Abstract Factory to create any kind of User interface object needed by the programm. | 
|---|
|  | 23 | * | 
|---|
|  | 24 | * The factory can be created and has to be set to a certain type upon creation. It will then | 
|---|
|  | 25 | * only create UIelements of that certain type, so that all UIElements match. This way different | 
|---|
|  | 26 | * UIs can be handled in a concise abstract way. | 
|---|
| [de8e45] | 27 | * | 
|---|
|  | 28 | * The main functionality is the MainWindow and the Dialog. | 
|---|
|  | 29 | * | 
|---|
|  | 30 | * MainWindow basically is the framework if the UI. The MainWindow has a run function which is | 
|---|
|  | 31 | * called MainWindow::Display(), which will listen for user input and react to it via actions for | 
|---|
|  | 32 | * as long as the user desires or tells the MainWindow to quit. | 
|---|
|  | 33 | * | 
|---|
|  | 34 | * Within the MainWindow Dialog classes may be instantiated which ask the user for input to | 
|---|
|  | 35 | * certain actions he wants to perform. | 
|---|
|  | 36 | * | 
|---|
| [dbb474] | 37 | */ | 
|---|
| [d7940e] | 38 | class UIFactory : public Singleton<UIFactory,false> | 
|---|
| [f5a86a] | 39 | { | 
|---|
| [9cf88c] | 40 | friend class Singleton<UIFactory,false>; | 
|---|
| [f5a86a] | 41 | public: | 
|---|
|  | 42 |  | 
|---|
| [dbb474] | 43 | /** | 
|---|
|  | 44 | * Produce some kind of main window, of whichever type was chosen when the factory was created | 
|---|
|  | 45 | */ | 
|---|
| [d893f79] | 46 | virtual MainWindow* makeMainWindow()=0; | 
|---|
| [dbb474] | 47 |  | 
|---|
|  | 48 | /** | 
|---|
|  | 49 | * Produce a User Interaction Dialog, that can query values from the User. | 
|---|
|  | 50 | * Again the type is determined upon factory creation. | 
|---|
|  | 51 | */ | 
|---|
| [f5a86a] | 52 | virtual Dialog* makeDialog()=0; | 
|---|
|  | 53 |  | 
|---|
|  | 54 | protected: | 
|---|
|  | 55 | UIFactory(); | 
|---|
| [9cf88c] | 56 | virtual ~UIFactory(); | 
|---|
| [f5a86a] | 57 |  | 
|---|
|  | 58 | public: | 
|---|
| [9cf88c] | 59 | struct factoryDescription { | 
|---|
|  | 60 | factoryDescription(std::string _name); | 
|---|
|  | 61 | virtual ~factoryDescription(); | 
|---|
|  | 62 |  | 
|---|
|  | 63 | const std::string name; | 
|---|
|  | 64 | // yes this method really is a factory factory, to allow insertion of | 
|---|
|  | 65 | // arbitrary factories | 
|---|
|  | 66 | virtual UIFactory* makeFactory()=0; | 
|---|
|  | 67 | }; | 
|---|
| [dbb474] | 68 | /** | 
|---|
|  | 69 | * create a Factory of a certain type. From that moment on only those UIElements can be produced by the factory | 
|---|
|  | 70 | */ | 
|---|
| [9cf88c] | 71 | static void makeUserInterface(std::string type); | 
|---|
|  | 72 | static void registerFactory(factoryDescription *factoryDesc); | 
|---|
|  | 73 | protected: | 
|---|
|  | 74 | private: | 
|---|
|  | 75 | static std::map<std::string,boost::shared_ptr<factoryDescription> > factories; | 
|---|
| [f5a86a] | 76 | }; | 
|---|
|  | 77 |  | 
|---|
|  | 78 | #endif /* UIFACTORY_HPP_ */ | 
|---|