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