| 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 |  | 
|---|
| 15 | // include config.h | 
|---|
| 16 | #ifdef HAVE_CONFIG_H | 
|---|
| 17 | #include <config.h> | 
|---|
| 18 | #endif | 
|---|
| 19 |  | 
|---|
| 20 | #include "CodePatterns/MemDebug.hpp" | 
|---|
| 21 |  | 
|---|
| 22 | #include "Actions/ActionTraits.hpp" | 
|---|
| 23 |  | 
|---|
| 24 | #include "CodePatterns/Assert.hpp" | 
|---|
| 25 |  | 
|---|
| 26 | #include <iostream> | 
|---|
| 27 | #include <sstream> | 
|---|
| 28 | #include <string> | 
|---|
| 29 | #include <typeinfo> | 
|---|
| 30 |  | 
|---|
| 31 | using namespace MoleCuilder; | 
|---|
| 32 |  | 
|---|
| 33 | /** Copy constructor for base class ActionTraits. | 
|---|
| 34 | * \param &_Traits source ActionTraits class to copy | 
|---|
| 35 | */ | 
|---|
| 36 | ActionTraits::ActionTraits(const std::string &_token) : | 
|---|
| 37 | OptionTrait(_token, | 
|---|
| 38 | &typeid(void), | 
|---|
| 39 | "this is an invisible action", | 
|---|
| 40 | "", | 
|---|
| 41 | "" | 
|---|
| 42 | ) | 
|---|
| 43 | { | 
|---|
| 44 | //std::cout << "ActionTraits::ActionTraits(string &) with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl; | 
|---|
| 45 | } | 
|---|
| 46 |  | 
|---|
| 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 | 
|---|
| 50 | */ | 
|---|
| 51 | ActionTraits::ActionTraits(const ActionTraits &_Traits) : | 
|---|
| 52 | OptionTrait(_Traits), | 
|---|
| 53 | MenuTitle(_Traits.MenuTitle), | 
|---|
| 54 | MenuPosition(_Traits.MenuPosition) | 
|---|
| 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, | 
|---|
| 60 | new OptionTrait(*iter->second) | 
|---|
| 61 | ) | 
|---|
| 62 | ); | 
|---|
| 63 | } | 
|---|
| 64 | //std::cout << "ActionTraits::ActionTraits(ActionTraits &) with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl; | 
|---|
| 65 | } | 
|---|
| 66 |  | 
|---|
| 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 | 
|---|
| 70 | */ | 
|---|
| 71 | ActionTraits::ActionTraits(const OptionTrait &_Traits, const std::string _MenuTitle, const int _MenuPosition) : | 
|---|
| 72 | OptionTrait(_Traits), | 
|---|
| 73 | MenuTitle(_MenuTitle), | 
|---|
| 74 | MenuPosition(_MenuPosition) | 
|---|
| 75 | { | 
|---|
| 76 | //std::cout << "ActionTraits::ActionTraits(OptionTrait &) with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl; | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 | /** Constructor for base class ActionTraits. | 
|---|
| 80 | * Deletes all present Options. | 
|---|
| 81 | */ | 
|---|
| 82 | ActionTraits::~ActionTraits() | 
|---|
| 83 | { | 
|---|
| 84 | for (options_iterator iter = Options.begin(); !Options.empty(); iter = Options.begin()) { | 
|---|
| 85 | delete (iter->second); | 
|---|
| 86 | Options.erase(iter); | 
|---|
| 87 | } | 
|---|
| 88 | } | 
|---|
| 89 |  | 
|---|
| 90 |  | 
|---|
| 91 | /** Returns menu title for this ActionTrait. | 
|---|
| 92 | * \return ActionTraits::MenuTitle as std::string | 
|---|
| 93 | */ | 
|---|
| 94 | const std::string& ActionTraits::getMenuName() const | 
|---|
| 95 | { | 
|---|
| 96 | return MenuTitle; | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|
| 99 | /** Returns menu title for this ActionTrait. | 
|---|
| 100 | * \return ActionTraits::MenuPosition as std::string | 
|---|
| 101 | */ | 
|---|
| 102 | int ActionTraits::getMenuPosition() const | 
|---|
| 103 | { | 
|---|
| 104 | return MenuPosition; | 
|---|
| 105 | } | 
|---|
| 106 |  | 
|---|
| 107 | /** Returns Description for the given option of this ActionTrait. | 
|---|
| 108 | * \param &token token of option | 
|---|
| 109 | * \return reference to OptionTrait | 
|---|
| 110 | */ | 
|---|
| 111 | OptionTrait const & ActionTraits::getOption(const std::string &token) const | 
|---|
| 112 | { | 
|---|
| 113 | ASSERT(Options.find(token) != Options.end(), | 
|---|
| 114 | "ActionTraits::getOption() - Option not found!"); | 
|---|
| 115 | return *(Options.find(token)->second); | 
|---|
| 116 | } | 
|---|
| 117 |  | 
|---|
| 118 | /** States whether given option (token) is present or not. | 
|---|
| 119 | * \param &token name of option | 
|---|
| 120 | * \return true - option present, false - not | 
|---|
| 121 | */ | 
|---|
| 122 | bool ActionTraits::hasOption(const std::string &token) const | 
|---|
| 123 | { | 
|---|
| 124 | return (Options.find(token) != Options.end()); | 
|---|
| 125 | } | 
|---|
| 126 |  | 
|---|
| 127 | /** States whether this Action has options at all. | 
|---|
| 128 | * \return true - options present, false - no options | 
|---|
| 129 | */ | 
|---|
| 130 | bool ActionTraits::hasOptions() const | 
|---|
| 131 | { | 
|---|
| 132 | return (Options.begin() != Options.end()); | 
|---|
| 133 | } | 
|---|
| 134 |  | 
|---|
| 135 | /** Forward iterator from beginning of list of options. | 
|---|
| 136 | * \return iterator | 
|---|
| 137 | */ | 
|---|
| 138 | ActionTraits::options_iterator ActionTraits::getBeginIter() | 
|---|
| 139 | { | 
|---|
| 140 | return Options.begin(); | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 | /** Forward iterator at end of list of options. | 
|---|
| 144 | * \return iterator | 
|---|
| 145 | */ | 
|---|
| 146 | ActionTraits::options_iterator ActionTraits::getEndIter() | 
|---|
| 147 | { | 
|---|
| 148 | return Options.end(); | 
|---|
| 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 | { | 
|---|
| 156 | return Options.begin(); | 
|---|
| 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 | { | 
|---|
| 164 | return Options.end(); | 
|---|
| 165 | } | 
|---|
| 166 |  | 
|---|
| 167 |  | 
|---|