| [df32ee] | 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 |  | 
|---|
|  | 8 | /* | 
|---|
|  | 9 | * ActionTraits.cpp | 
|---|
|  | 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 |  | 
|---|
| [df32ee] | 22 | #include "Actions/ActionTraits.hpp" | 
|---|
|  | 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 |  | 
|---|
| [e4afb4] | 33 | /** Copy constructor for base class ActionTraits. | 
|---|
|  | 34 | * \param &_Traits source ActionTraits class to copy | 
|---|
| [df32ee] | 35 | */ | 
|---|
| [e4afb4] | 36 | ActionTraits::ActionTraits(const std::string &_token) : | 
|---|
|  | 37 | OptionTrait(_token, | 
|---|
|  | 38 | &typeid(void), | 
|---|
|  | 39 | "this is an invisible action", | 
|---|
|  | 40 | "", | 
|---|
|  | 41 | "" | 
|---|
|  | 42 | ) | 
|---|
|  | 43 | { | 
|---|
| [c38826] | 44 | //std::cout << "ActionTraits::ActionTraits(string &) with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl; | 
|---|
| [e4afb4] | 45 | } | 
|---|
| [df32ee] | 46 |  | 
|---|
| [e4afb4] | 47 | /** Copy constructor for base class ActionTraits. | 
|---|
|  | 48 | * we have to make our own copy in order to avoid references and deep-copy everything. | 
|---|
|  | 49 | * \param &_Traits source ActionTraits class to copy | 
|---|
| [df32ee] | 50 | */ | 
|---|
| [e4afb4] | 51 | ActionTraits::ActionTraits(const ActionTraits &_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( | 
|---|
|  | 58 | std::pair< std::string, OptionTrait *> ( | 
|---|
|  | 59 | iter->first, | 
|---|
| [b22179] | 60 | new OptionTrait(*iter->second) | 
|---|
| [e4afb4] | 61 | ) | 
|---|
|  | 62 | ); | 
|---|
|  | 63 | } | 
|---|
| [c38826] | 64 | //std::cout << "ActionTraits::ActionTraits(ActionTraits &) with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl; | 
|---|
| [e4afb4] | 65 | } | 
|---|
| [df32ee] | 66 |  | 
|---|
| [e4afb4] | 67 | /** Copy constructor for base class ActionTraits. | 
|---|
|  | 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 | */ | 
|---|
| [b59da6] | 71 | ActionTraits::ActionTraits(const OptionTrait &_Traits, const std::string _MenuTitle, const int _MenuPosition) : | 
|---|
|  | 72 | OptionTrait(_Traits), | 
|---|
|  | 73 | MenuTitle(_MenuTitle), | 
|---|
|  | 74 | MenuPosition(_MenuPosition) | 
|---|
| [df32ee] | 75 | { | 
|---|
| [c38826] | 76 | //std::cout << "ActionTraits::ActionTraits(OptionTrait &) with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl; | 
|---|
| [df32ee] | 77 | } | 
|---|
|  | 78 |  | 
|---|
| [e4afb4] | 79 | /** Constructor for base class ActionTraits. | 
|---|
|  | 80 | * Deletes all present Options. | 
|---|
| [df32ee] | 81 | */ | 
|---|
| [e4afb4] | 82 | ActionTraits::~ActionTraits() | 
|---|
| [df32ee] | 83 | { | 
|---|
| [e4afb4] | 84 | for (options_iterator iter = Options.begin(); !Options.empty(); iter = Options.begin()) { | 
|---|
|  | 85 | delete (iter->second); | 
|---|
|  | 86 | Options.erase(iter); | 
|---|
|  | 87 | } | 
|---|
| [df32ee] | 88 | } | 
|---|
|  | 89 |  | 
|---|
| [e4afb4] | 90 |  | 
|---|
| [53be34] | 91 | /** Returns menu title for this ActionTrait. | 
|---|
|  | 92 | * \return ActionTraits::MenuTitle as std::string | 
|---|
|  | 93 | */ | 
|---|
| [e4afb4] | 94 | const std::string& ActionTraits::getMenuName() const | 
|---|
| [53be34] | 95 | { | 
|---|
|  | 96 | return MenuTitle; | 
|---|
|  | 97 | } | 
|---|
|  | 98 |  | 
|---|
|  | 99 | /** Returns menu title for this ActionTrait. | 
|---|
|  | 100 | * \return ActionTraits::MenuPosition as std::string | 
|---|
|  | 101 | */ | 
|---|
| [b59da6] | 102 | int ActionTraits::getMenuPosition() const | 
|---|
| [53be34] | 103 | { | 
|---|
|  | 104 | return MenuPosition; | 
|---|
|  | 105 | } | 
|---|
|  | 106 |  | 
|---|
|  | 107 | /** Returns Description for the given option of this ActionTrait. | 
|---|
| [e4afb4] | 108 | * \param &token token of option | 
|---|
|  | 109 | * \return reference to OptionTrait | 
|---|
| [53be34] | 110 | */ | 
|---|
| [e4afb4] | 111 | OptionTrait const & ActionTraits::getOption(const std::string &token) const | 
|---|
| [53be34] | 112 | { | 
|---|
| [e4afb4] | 113 | ASSERT(Options.find(token) != Options.end(), | 
|---|
|  | 114 | "ActionTraits::getOption() - Option not found!"); | 
|---|
|  | 115 | return *(Options.find(token)->second); | 
|---|
| [53be34] | 116 | } | 
|---|
|  | 117 |  | 
|---|
| [e4afb4] | 118 | /** States whether given option (token) is present or not. | 
|---|
|  | 119 | * \param &token name of option | 
|---|
|  | 120 | * \return true - option present, false - not | 
|---|
| [df32ee] | 121 | */ | 
|---|
| [e4afb4] | 122 | bool ActionTraits::hasOption(const std::string &token) const | 
|---|
| [df32ee] | 123 | { | 
|---|
| [e4afb4] | 124 | return (Options.find(token) != Options.end()); | 
|---|
| [df32ee] | 125 | } | 
|---|
|  | 126 |  | 
|---|
| [e4afb4] | 127 | /** States whether this Action has options at all. | 
|---|
|  | 128 | * \return true - options present, false - no options | 
|---|
| [df32ee] | 129 | */ | 
|---|
| [e4afb4] | 130 | bool ActionTraits::hasOptions() const | 
|---|
| [df32ee] | 131 | { | 
|---|
| [e4afb4] | 132 | return (Options.begin() != Options.end()); | 
|---|
| [df32ee] | 133 | } | 
|---|
|  | 134 |  | 
|---|
| [53be34] | 135 | /** Forward iterator from beginning of list of options. | 
|---|
|  | 136 | * \return iterator | 
|---|
|  | 137 | */ | 
|---|
|  | 138 | ActionTraits::options_iterator ActionTraits::getBeginIter() | 
|---|
|  | 139 | { | 
|---|
| [e4afb4] | 140 | return Options.begin(); | 
|---|
| [53be34] | 141 | } | 
|---|
|  | 142 |  | 
|---|
|  | 143 | /** Forward iterator at end of list of options. | 
|---|
|  | 144 | * \return iterator | 
|---|
|  | 145 | */ | 
|---|
|  | 146 | ActionTraits::options_iterator ActionTraits::getEndIter() | 
|---|
|  | 147 | { | 
|---|
| [e4afb4] | 148 | return Options.end(); | 
|---|
| [53be34] | 149 | } | 
|---|
|  | 150 |  | 
|---|
|  | 151 | /** Constant forward iterator from beginning of list of options. | 
|---|
|  | 152 | * \return constant iterator | 
|---|
|  | 153 | */ | 
|---|
|  | 154 | ActionTraits::options_const_iterator ActionTraits::getBeginIter() const | 
|---|
|  | 155 | { | 
|---|
| [e4afb4] | 156 | return Options.begin(); | 
|---|
| [53be34] | 157 | } | 
|---|
|  | 158 |  | 
|---|
|  | 159 | /** Constant forward iterator at end of list of options. | 
|---|
|  | 160 | * \return constant iterator | 
|---|
|  | 161 | */ | 
|---|
|  | 162 | ActionTraits::options_const_iterator ActionTraits::getEndIter() const | 
|---|
|  | 163 | { | 
|---|
| [e4afb4] | 164 | return Options.end(); | 
|---|
| [53be34] | 165 | } | 
|---|
|  | 166 |  | 
|---|
|  | 167 |  | 
|---|