Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/UIFactory.cpp

    r112b09 rbcf653  
     1/*
     2 * Project: MoleCuilder
     3 * Description: creates and alters molecular systems
     4 * Copyright (C)  2010 University of Bonn. All rights reserved.
     5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
     6 */
     7
    18/*
    29 * UIFactory.cpp
     
    613 */
    714
     15// include config.h
     16#ifdef HAVE_CONFIG_H
     17#include <config.h>
     18#endif
     19
    820#include "Helpers/MemDebug.hpp"
    921
    10 #include <cassert>
     22#include <utility>
    1123#include "Patterns/Singleton_impl.hpp"
    12 #include "UIFactory.hpp"
     24#include "UIElements/UIFactory.hpp"
     25#include "Helpers/Assert.hpp"
     26#include "Helpers/MemDebug.hpp"
    1327
    14 // all factories that can be used:
    15 #include "TextUI/TextUIFactory.hpp"
    16 #include "CommandLineUI/CommandLineUIFactory.hpp"
     28using namespace std;
     29
     30std::map<std::string,boost::shared_ptr<UIFactory::factoryDescription> > UIFactory::factories;
    1731
    1832UIFactory::UIFactory()
    19 {
    20   // TODO Auto-generated constructor stub
     33{}
    2134
     35UIFactory::~UIFactory()
     36{}
     37
     38void UIFactory::makeUserInterface(std::string type) {
     39  ASSERT(factories.count(type),"Selected factory was not registered before creation.");
     40  // call the factory factory
     41  setInstance(factories[type]->makeFactory());
    2242}
    2343
    24 UIFactory::~UIFactory()
    25 {
    26   // TODO Auto-generated destructor stub
    27 }
    28 
    29 void UIFactory::makeUserInterface(InterfaceTypes type) {
    30   switch(type) {
    31     case Text :
    32       setInstance(new TextUIFactory());
    33       break;
    34     case CommandLine:
    35       setInstance(new CommandLineUIFactory());
    36       break;
    37 
    38     default:
    39       assert(0 && "No such Factory in stock");
    40       break;
    41   }
     44void UIFactory::registerFactory(factoryDescription *factoryDesc) {
     45  ASSERT(!factories.count(factoryDesc->name),"Trying to re-register an already registered factory.");
     46  factories.insert(make_pair(factoryDesc->name,
     47                             boost::shared_ptr<factoryDescription>(factoryDesc)));
    4248}
    4349
    4450CONSTRUCT_SINGLETON(UIFactory)
     51
     52UIFactory::factoryDescription::factoryDescription(string _name) :
     53  name(_name)
     54{}
     55
     56UIFactory::factoryDescription::~factoryDescription()
     57{}
Note: See TracChangeset for help on using the changeset viewer.