[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[94d5ac6] | 5 | *
|
---|
| 6 | *
|
---|
| 7 | * This file is part of MoleCuilder.
|
---|
| 8 | *
|
---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 12 | * (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU General Public License
|
---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
[bcf653] | 21 | */
|
---|
| 22 |
|
---|
[cc04b7] | 23 | /*
|
---|
[b2d8d0] | 24 | * Registry<Action>.cpp
|
---|
[cc04b7] | 25 | *
|
---|
| 26 | * Created on: Jan 7, 2010
|
---|
| 27 | * Author: crueger
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[bf3817] | 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
[ad011c] | 35 | #include "CodePatterns/MemDebug.hpp"
|
---|
[112b09] | 36 |
|
---|
[cc04b7] | 37 | #include "Actions/ActionRegistry.hpp"
|
---|
[ad011c] | 38 | #include "CodePatterns/Singleton_impl.hpp"
|
---|
| 39 | #include "CodePatterns/Registry_impl.hpp"
|
---|
[cc04b7] | 40 |
|
---|
[83e90c] | 41 | #include "GlobalListOfActions.hpp"
|
---|
| 42 |
|
---|
| 43 | #include "AllActionHeaders.hpp"
|
---|
| 44 |
|
---|
| 45 | #include <boost/preprocessor/iteration/local.hpp>
|
---|
| 46 | #include <boost/preprocessor/seq/elem.hpp>
|
---|
| 47 | #include <boost/preprocessor/seq/size.hpp>
|
---|
| 48 |
|
---|
[ce7fdc] | 49 | using namespace MoleCuilder;
|
---|
| 50 |
|
---|
[2aad5a] | 51 | // static entities
|
---|
| 52 | bool ActionRegistry::completely_instatiated = false;
|
---|
| 53 |
|
---|
[d0fbec] | 54 | /** Constructor for class ActionRegistry.
|
---|
| 55 | */
|
---|
[cc04b7] | 56 | ActionRegistry::ActionRegistry()
|
---|
[83e90c] | 57 | {
|
---|
| 58 | //std::cout << "ActionRegistry::ActionRegistry() called, instance is " << this << "." << std::endl;
|
---|
| 59 | fillRegistry();
|
---|
[2aad5a] | 60 | completely_instatiated = true;
|
---|
[83e90c] | 61 | }
|
---|
[cc04b7] | 62 |
|
---|
[d0fbec] | 63 | /** Destructor for class ActionRegistry.
|
---|
| 64 | */
|
---|
[cc04b7] | 65 | ActionRegistry::~ActionRegistry()
|
---|
[95c0ab] | 66 | {
|
---|
[83e90c] | 67 | //std::cout << "ActionRegistry::~ActionRegistry() called, instance is " << this << "." << std::endl;
|
---|
[95c0ab] | 68 | cleanup();
|
---|
| 69 | }
|
---|
[cc04b7] | 70 |
|
---|
[83e90c] | 71 |
|
---|
| 72 | /** Instantiates each existing Action.
|
---|
| 73 | *
|
---|
| 74 | */
|
---|
| 75 | void ActionRegistry::fillRegistry()
|
---|
| 76 | {
|
---|
| 77 | #define instance_print(z,n,list) \
|
---|
| 78 | { \
|
---|
| 79 | Action * presentAction = new \
|
---|
| 80 | BOOST_PP_CAT(BOOST_PP_SEQ_ELEM(n, list), Action) \
|
---|
| 81 | (); \
|
---|
| 82 | registerInstance(presentAction); \
|
---|
| 83 | }
|
---|
| 84 | #define BOOST_PP_LOCAL_MACRO(n) instance_print(~, n, GLOBALLISTOFACTIONS)
|
---|
| 85 | #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(GLOBALLISTOFACTIONS)))
|
---|
| 86 | #include BOOST_PP_LOCAL_ITERATE()
|
---|
| 87 | #undef instance_print
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[b2d8d0] | 90 | /** Just passes on call to Registry<Action>::getByName().
|
---|
| 91 | * \param name name of Action
|
---|
[d0fbec] | 92 | * \return pointer to Action
|
---|
| 93 | */
|
---|
[b2d8d0] | 94 | Action* ActionRegistry::getActionByName(const std::string name)
|
---|
[d0fbec] | 95 | {
|
---|
[b2d8d0] | 96 | return getByName(name);
|
---|
[d0fbec] | 97 | }
|
---|
| 98 |
|
---|
[b2d8d0] | 99 | /** Just passes on call to Registry<Action>::isPresentByName().
|
---|
| 100 | * \param name name of Action
|
---|
| 101 | * \return true - Action instance present, false - not
|
---|
[d0fbec] | 102 | */
|
---|
[e4afb4] | 103 | bool ActionRegistry::isActionPresentByName(const std::string name) const
|
---|
[d0fbec] | 104 | {
|
---|
[b2d8d0] | 105 | return isPresentByName(name);
|
---|
[d0fbec] | 106 | }
|
---|
| 107 |
|
---|
[b59da6] | 108 | /** Returns the last present action position in the requested menu.
|
---|
| 109 | * \param &token token of the menu
|
---|
| 110 | * \return last used position
|
---|
| 111 | */
|
---|
| 112 | int ActionRegistry::getLastPosition(const std::string &token) const
|
---|
| 113 | {
|
---|
| 114 | int position = 0;
|
---|
| 115 | for (const_iterator iter = getBeginIter();
|
---|
| 116 | iter != getEndIter();
|
---|
| 117 | ++iter) {
|
---|
| 118 | const std::string &MenuName = (iter->second)->Traits.getMenuName();
|
---|
| 119 | const int &MenuPosition = (iter->second)->Traits.getMenuPosition();
|
---|
| 120 | if ((MenuName == token) && (position < MenuPosition))
|
---|
| 121 | position = MenuPosition;
|
---|
| 122 | }
|
---|
| 123 | return position;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 |
|
---|
[e73a8a2] | 127 | CONSTRUCT_SINGLETON(ActionRegistry)
|
---|
[b2d8d0] | 128 | CONSTRUCT_REGISTRY(Action)
|
---|