1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
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/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * Registry<Action>.cpp
|
---|
25 | *
|
---|
26 | * Created on: Jan 7, 2010
|
---|
27 | * Author: crueger
|
---|
28 | */
|
---|
29 |
|
---|
30 | // include config.h
|
---|
31 | #ifdef HAVE_CONFIG_H
|
---|
32 | #include <config.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #include "CodePatterns/MemDebug.hpp"
|
---|
36 |
|
---|
37 | #include "Actions/ActionRegistry.hpp"
|
---|
38 | #include "CodePatterns/Singleton_impl.hpp"
|
---|
39 | #include "CodePatterns/Registry_impl.hpp"
|
---|
40 |
|
---|
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 |
|
---|
49 | using namespace MoleCuilder;
|
---|
50 |
|
---|
51 | // static entities
|
---|
52 | bool ActionRegistry::completely_instatiated = false;
|
---|
53 |
|
---|
54 | /** Constructor for class ActionRegistry.
|
---|
55 | */
|
---|
56 | ActionRegistry::ActionRegistry()
|
---|
57 | {
|
---|
58 | //std::cout << "ActionRegistry::ActionRegistry() called, instance is " << this << "." << std::endl;
|
---|
59 | fillRegistry();
|
---|
60 | completely_instatiated = true;
|
---|
61 | }
|
---|
62 |
|
---|
63 | /** Destructor for class ActionRegistry.
|
---|
64 | */
|
---|
65 | ActionRegistry::~ActionRegistry()
|
---|
66 | {
|
---|
67 | //std::cout << "ActionRegistry::~ActionRegistry() called, instance is " << this << "." << std::endl;
|
---|
68 | cleanup();
|
---|
69 | }
|
---|
70 |
|
---|
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 |
|
---|
90 | /** Just passes on call to Registry<Action>::getByName().
|
---|
91 | * \param name name of Action
|
---|
92 | * \return pointer to Action
|
---|
93 | */
|
---|
94 | Action* ActionRegistry::getActionByName(const std::string name)
|
---|
95 | {
|
---|
96 | return getByName(name);
|
---|
97 | }
|
---|
98 |
|
---|
99 | /** Just passes on call to Registry<Action>::isPresentByName().
|
---|
100 | * \param name name of Action
|
---|
101 | * \return true - Action instance present, false - not
|
---|
102 | */
|
---|
103 | bool ActionRegistry::isActionPresentByName(const std::string name) const
|
---|
104 | {
|
---|
105 | return isPresentByName(name);
|
---|
106 | }
|
---|
107 |
|
---|
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 |
|
---|
127 | CONSTRUCT_SINGLETON(ActionRegistry)
|
---|
128 | CONSTRUCT_REGISTRY(Action)
|
---|