[df32ee] | 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/>.
|
---|
[df32ee] | 21 | */
|
---|
| 22 |
|
---|
| 23 | /*
|
---|
[3139b2] | 24 | * ActionTrait.cpp
|
---|
[df32ee] | 25 | *
|
---|
| 26 | * Created on: Oct 26, 2010
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[d2b28f] | 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
[ad011c] | 35 | #include "CodePatterns/MemDebug.hpp"
|
---|
[d2b28f] | 36 |
|
---|
[3139b2] | 37 | #include "Actions/ActionTrait.hpp"
|
---|
[df32ee] | 38 |
|
---|
[ad011c] | 39 | #include "CodePatterns/Assert.hpp"
|
---|
[e4afb4] | 40 |
|
---|
| 41 | #include <iostream>
|
---|
| 42 | #include <sstream>
|
---|
[df32ee] | 43 | #include <string>
|
---|
[e4afb4] | 44 | #include <typeinfo>
|
---|
[df32ee] | 45 |
|
---|
[ce7fdc] | 46 | using namespace MoleCuilder;
|
---|
| 47 |
|
---|
[3139b2] | 48 | /** Copy constructor for base class ActionTrait.
|
---|
| 49 | * \param &_Traits source ActionTrait class to copy
|
---|
[df32ee] | 50 | */
|
---|
[3139b2] | 51 | ActionTrait::ActionTrait(const std::string &_token) :
|
---|
[e4afb4] | 52 | OptionTrait(_token,
|
---|
| 53 | &typeid(void),
|
---|
| 54 | "this is an invisible action",
|
---|
| 55 | "",
|
---|
| 56 | ""
|
---|
| 57 | )
|
---|
| 58 | {
|
---|
[955b91] | 59 | //std::cout << "ActionTrait::ActionTrait(std::string &) on instance " << this << " with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl;
|
---|
[e4afb4] | 60 | }
|
---|
[df32ee] | 61 |
|
---|
[3139b2] | 62 | /** Copy constructor for base class ActionTrait.
|
---|
[e4afb4] | 63 | * we have to make our own copy in order to avoid references and deep-copy everything.
|
---|
[3139b2] | 64 | * \param &_Traits source ActionTrait class to copy
|
---|
[df32ee] | 65 | */
|
---|
[3139b2] | 66 | ActionTrait::ActionTrait(const ActionTrait &_Traits) :
|
---|
[b22179] | 67 | OptionTrait(_Traits),
|
---|
[b59da6] | 68 | MenuTitle(_Traits.MenuTitle),
|
---|
| 69 | MenuPosition(_Traits.MenuPosition)
|
---|
[e4afb4] | 70 | {
|
---|
| 71 | for (options_const_iterator iter = _Traits.Options.begin(); iter != _Traits.Options.end(); ++iter) {
|
---|
| 72 | Options.insert(
|
---|
[dad802] | 73 | std::make_pair(
|
---|
[e4afb4] | 74 | iter->first,
|
---|
[b22179] | 75 | new OptionTrait(*iter->second)
|
---|
[e4afb4] | 76 | )
|
---|
| 77 | );
|
---|
| 78 | }
|
---|
[3139b2] | 79 | //std::cout << "ActionTrait::ActionTrait(ActionTrait &) on instance " << this << " with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl;
|
---|
[e4afb4] | 80 | }
|
---|
[df32ee] | 81 |
|
---|
[3139b2] | 82 | /** Copy constructor for base class ActionTrait.
|
---|
[e4afb4] | 83 | * we have to make our own copy in order to avoid references and deep-copy everything.
|
---|
| 84 | * \param &_Traits source OptionTrait class to copy
|
---|
[df32ee] | 85 | */
|
---|
[3139b2] | 86 | ActionTrait::ActionTrait(const OptionTrait &_Traits, const std::string _MenuTitle, const int _MenuPosition) :
|
---|
[b59da6] | 87 | OptionTrait(_Traits),
|
---|
| 88 | MenuTitle(_MenuTitle),
|
---|
| 89 | MenuPosition(_MenuPosition)
|
---|
[df32ee] | 90 | {
|
---|
[3139b2] | 91 | //std::cout << "ActionTrait::ActionTrait(OptionTrait &) on instance " << this << " with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl;
|
---|
[df32ee] | 92 | }
|
---|
| 93 |
|
---|
[3139b2] | 94 | /** Constructor for base class ActionTrait.
|
---|
[e4afb4] | 95 | * Deletes all present Options.
|
---|
[df32ee] | 96 | */
|
---|
[3139b2] | 97 | ActionTrait::~ActionTrait()
|
---|
[df32ee] | 98 | {
|
---|
[3139b2] | 99 | //std::cout << "ActionTrait::~ActionTrait() on instance " << this << " with name " << getName() << " called." << std::endl;
|
---|
[dad802] | 100 | for (options_iterator iter = Options.begin(); iter != Options.end(); ++iter) {
|
---|
[3139b2] | 101 | //std::cout << "ActionTrait::~ActionTrait() removes option instance " << iter->second << " with name " << iter->first << "." << std::endl;
|
---|
[dad802] | 102 | delete iter->second;
|
---|
[e4afb4] | 103 | }
|
---|
[dad802] | 104 | Options.clear();
|
---|
[df32ee] | 105 | }
|
---|
| 106 |
|
---|
[e4afb4] | 107 |
|
---|
[53be34] | 108 | /** Returns menu title for this ActionTrait.
|
---|
[3139b2] | 109 | * \return ActionTrait::MenuTitle as std::string
|
---|
[53be34] | 110 | */
|
---|
[3139b2] | 111 | const std::string& ActionTrait::getMenuName() const
|
---|
[53be34] | 112 | {
|
---|
| 113 | return MenuTitle;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | /** Returns menu title for this ActionTrait.
|
---|
[3139b2] | 117 | * \return ActionTrait::MenuPosition as std::string
|
---|
[53be34] | 118 | */
|
---|
[3139b2] | 119 | int ActionTrait::getMenuPosition() const
|
---|
[53be34] | 120 | {
|
---|
| 121 | return MenuPosition;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | /** Returns Description for the given option of this ActionTrait.
|
---|
[e4afb4] | 125 | * \param &token token of option
|
---|
| 126 | * \return reference to OptionTrait
|
---|
[53be34] | 127 | */
|
---|
[3139b2] | 128 | OptionTrait const & ActionTrait::getOption(const std::string &token) const
|
---|
[53be34] | 129 | {
|
---|
[e4afb4] | 130 | ASSERT(Options.find(token) != Options.end(),
|
---|
[3139b2] | 131 | "ActionTrait::getOption() - Option not found!");
|
---|
[e4afb4] | 132 | return *(Options.find(token)->second);
|
---|
[53be34] | 133 | }
|
---|
| 134 |
|
---|
[e4afb4] | 135 | /** States whether given option (token) is present or not.
|
---|
| 136 | * \param &token name of option
|
---|
| 137 | * \return true - option present, false - not
|
---|
[df32ee] | 138 | */
|
---|
[3139b2] | 139 | bool ActionTrait::hasOption(const std::string &token) const
|
---|
[df32ee] | 140 | {
|
---|
[e4afb4] | 141 | return (Options.find(token) != Options.end());
|
---|
[df32ee] | 142 | }
|
---|
| 143 |
|
---|
[e4afb4] | 144 | /** States whether this Action has options at all.
|
---|
| 145 | * \return true - options present, false - no options
|
---|
[df32ee] | 146 | */
|
---|
[3139b2] | 147 | bool ActionTrait::hasOptions() const
|
---|
[df32ee] | 148 | {
|
---|
[e4afb4] | 149 | return (Options.begin() != Options.end());
|
---|
[df32ee] | 150 | }
|
---|
| 151 |
|
---|
[53be34] | 152 | /** Forward iterator from beginning of list of options.
|
---|
| 153 | * \return iterator
|
---|
| 154 | */
|
---|
[3139b2] | 155 | ActionTrait::options_iterator ActionTrait::getBeginIter()
|
---|
[53be34] | 156 | {
|
---|
[e4afb4] | 157 | return Options.begin();
|
---|
[53be34] | 158 | }
|
---|
| 159 |
|
---|
| 160 | /** Forward iterator at end of list of options.
|
---|
| 161 | * \return iterator
|
---|
| 162 | */
|
---|
[3139b2] | 163 | ActionTrait::options_iterator ActionTrait::getEndIter()
|
---|
[53be34] | 164 | {
|
---|
[e4afb4] | 165 | return Options.end();
|
---|
[53be34] | 166 | }
|
---|
| 167 |
|
---|
| 168 | /** Constant forward iterator from beginning of list of options.
|
---|
| 169 | * \return constant iterator
|
---|
| 170 | */
|
---|
[3139b2] | 171 | ActionTrait::options_const_iterator ActionTrait::getBeginIter() const
|
---|
[53be34] | 172 | {
|
---|
[e4afb4] | 173 | return Options.begin();
|
---|
[53be34] | 174 | }
|
---|
| 175 |
|
---|
| 176 | /** Constant forward iterator at end of list of options.
|
---|
| 177 | * \return constant iterator
|
---|
| 178 | */
|
---|
[3139b2] | 179 | ActionTrait::options_const_iterator ActionTrait::getEndIter() const
|
---|
[53be34] | 180 | {
|
---|
[e4afb4] | 181 | return Options.end();
|
---|
[53be34] | 182 | }
|
---|
| 183 |
|
---|
[d41313] | 184 | /** Output operator for ActionTrait.
|
---|
| 185 | *
|
---|
| 186 | * \param &out stream to output to
|
---|
| 187 | */
|
---|
[3139b2] | 188 | std::ostream &operator<<(std::ostream &out, const ActionTrait &a)
|
---|
[d41313] | 189 | {
|
---|
| 190 | out << "ActionTrait(" << &a << ") with " << static_cast<const OptionTrait &>(a) << " has the following options: " << std::endl;
|
---|
[3139b2] | 191 | for (ActionTrait::options_const_iterator iter = a.getBeginIter();
|
---|
[d41313] | 192 | iter != a.getEndIter();
|
---|
| 193 | ++iter) {
|
---|
| 194 | out << "\t - " << *iter->second << ")" << std::endl;
|
---|
| 195 | }
|
---|
| 196 | return out;
|
---|
| 197 | }
|
---|
[53be34] | 198 |
|
---|