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