Changeset 4fc41a


Ignore:
Timestamp:
Mar 11, 2010, 10:37:32 AM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
Children:
ff1812
Parents:
4c60ef
Message:

Made the UIFactory an instance of the Singleton Pattern

Location:
molecuilder/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/Actions/small_actions.cpp

    r4c60ef r4fc41a  
    2727  string filename;
    2828  molecule *mol = NULL;
    29   Dialog *dialog = UIFactory::get()->makeDialog();
     29  Dialog *dialog = UIFactory::getInstance().makeDialog();
    3030
    3131  dialog->queryMolecule("Enter index of molecule: ",&mol,molecules);
  • molecuilder/src/Legacy/oldmenu.cpp

    r4c60ef r4fc41a  
    912912void oldmenu::SimpleAddMolecules(MoleculeListClass *molecules) {
    913913  molecule *srcmol = NULL, *destmol = NULL;
    914   Dialog *dialog = UIFactory::get()->makeDialog();
     914  Dialog *dialog = UIFactory::getInstance().makeDialog();
    915915  dialog->queryMolecule("Enter index of destination molecule: ",&destmol, molecules);
    916916  dialog->queryMolecule("Enter index of source molecule to add from: ",&srcmol, molecules);
     
    926926void oldmenu::embeddMolecules(MoleculeListClass *molecules) {
    927927  molecule *srcmol = NULL, *destmol = NULL;
    928   Dialog *dialog = UIFactory::get()->makeDialog();
     928  Dialog *dialog = UIFactory::getInstance().makeDialog();
    929929  dialog->queryMolecule("Enter index of matrix molecule (the variable one): ",&srcmol,molecules);
    930930  dialog->queryMolecule("Enter index of molecule to merge into (the fixed one): ",&destmol,molecules);
  • molecuilder/src/Patterns/Singleton.hpp

    r4c60ef r4fc41a  
    99#define SINGLETON_HPP_
    1010
    11 #include <memory>
     11#include <cassert>
     12#include <boost/thread.hpp>
    1213
    1314#include "defs.hpp"
  • molecuilder/src/Patterns/Singleton_impl.hpp

    r4c60ef r4fc41a  
    99#define SINGLETON_IMPL_HPP_
    1010
    11 #include <cassert>
     11#include "Patterns/Singleton.hpp"
    1212
    1313template <class T,bool _may_create>
  • molecuilder/src/UIElements/UIFactory.cpp

    r4c60ef r4fc41a  
    88
    99#include <cassert>
     10#include "Patterns/Singleton_impl.hpp"
    1011#include "UIElements/UIFactory.hpp"
    1112
    1213// all factories that can be used:
    1314#include "UIElements/TextUIFactory.hpp"
    14 
    15 UIFactory *UIFactory::theFactory = 0;
    1615
    1716UIFactory::UIFactory()
     
    2726
    2827void UIFactory::makeUserInterface(InterfaceTypes type) {
    29   assert(theFactory == 0 && "makeUserInterface should only be called once");
    3028  switch(type) {
    3129    case Text :
    32       theFactory = new TextUIFactory();
     30      setInstance(new TextUIFactory());
    3331      break;
    3432
     
    3937}
    4038
    41 UIFactory* UIFactory::get(){
    42   assert(theFactory != 0 && "No UserInterface created prior to factory access");
    43   return theFactory;
    44 }
    45 
    46 
    47 void UIFactory::purgeInstance(){
    48   if(theFactory) {
    49     delete theFactory;
    50     theFactory = 0;
    51   }
    52 }
     39CONSTRUCT_SINGLETON(UIFactory)
  • molecuilder/src/UIElements/UIFactory.hpp

    r4c60ef r4fc41a  
    1717
    1818struct menuPopulaters;
     19
     20#include "Patterns/Singleton.hpp"
     21
    1922/**
    2023 * Abstract Factory to create any kind of User interface object needed by the programm.
     
    2427 * UIs can be handled in a concise abstract way.
    2528 */
    26 class UIFactory
     29class UIFactory : public Singleton<UIFactory,false>
    2730{
    2831
     
    4548  UIFactory();
    4649
    47 // singleton stuff
    48 private:
    49   static UIFactory *theFactory;
    50 
    5150public:
    5251  /**
     
    5554  static void makeUserInterface(InterfaceTypes type);
    5655
    57   /**
    58    * get the previously created factory
    59    */
    60   static UIFactory* get();
    61 
    62   /**
    63    * Destroy the created factory.
    64    *
    65    * Make sure that all UIElements that were created by the factory are destroyed before calling this method.
    66    */
    67   static void purgeInstance();
    6856};
    6957
  • molecuilder/src/builder.cpp

    r4c60ef r4fc41a  
    22252225
    22262226      UIFactory::makeUserInterface(UIFactory::Text);
    2227       MainWindow *mainWindow = UIFactory::get()->makeMainWindow(populaters,World::getInstance().getMolecules(), configuration, World::getInstance().getPeriode(), ConfigFileName);
     2227      MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow(populaters,World::getInstance().getMolecules(), configuration, World::getInstance().getPeriode(), ConfigFileName);
    22282228      mainWindow->display();
    22292229      delete mainWindow;
Note: See TracChangeset for help on using the changeset viewer.