| 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 | 
 | 
|---|
| 11 | class MainWindow;
 | 
|---|
| 12 | class Dialog;
 | 
|---|
| 13 | class DialogDescription;
 | 
|---|
| 14 | 
 | 
|---|
| 15 | #include "Patterns/Singleton.hpp"
 | 
|---|
| 16 | 
 | 
|---|
| 17 | #include <string>
 | 
|---|
| 18 | #include <map>
 | 
|---|
| 19 | #include <boost/smart_ptr.hpp>
 | 
|---|
| 20 | 
 | 
|---|
| 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.
 | 
|---|
| 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 |  *
 | 
|---|
| 37 |  */
 | 
|---|
| 38 | class UIFactory : public Singleton<UIFactory,false>
 | 
|---|
| 39 | {
 | 
|---|
| 40 |   friend class Singleton<UIFactory,false>;
 | 
|---|
| 41 | public:
 | 
|---|
| 42 | 
 | 
|---|
| 43 |   /**
 | 
|---|
| 44 |    * Produce some kind of main window, of whichever type was chosen when the factory was created
 | 
|---|
| 45 |    */
 | 
|---|
| 46 |   virtual MainWindow* makeMainWindow()=0;
 | 
|---|
| 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 |    */
 | 
|---|
| 52 |   virtual Dialog* makeDialog()=0;
 | 
|---|
| 53 | 
 | 
|---|
| 54 | protected:
 | 
|---|
| 55 |   UIFactory();
 | 
|---|
| 56 |   virtual ~UIFactory();
 | 
|---|
| 57 | 
 | 
|---|
| 58 | public:
 | 
|---|
| 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 |   };
 | 
|---|
| 68 |   /**
 | 
|---|
| 69 |    * create a Factory of a certain type. From that moment on only those UIElements can be produced by the factory
 | 
|---|
| 70 |    */
 | 
|---|
| 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;
 | 
|---|
| 76 | };
 | 
|---|
| 77 | 
 | 
|---|
| 78 | #endif /* UIFACTORY_HPP_ */
 | 
|---|