| [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 | 
 | 
|---|
| [e4afb4] | 31 | /** Copy constructor for base class ActionTraits.
 | 
|---|
 | 32 |  * \param &_Traits source ActionTraits class to copy
 | 
|---|
| [df32ee] | 33 |  */
 | 
|---|
| [e4afb4] | 34 | ActionTraits::ActionTraits(const std::string &_token) :
 | 
|---|
 | 35 |   OptionTrait(_token,
 | 
|---|
 | 36 |       &typeid(void),
 | 
|---|
 | 37 |       "this is an invisible action",
 | 
|---|
 | 38 |       "",
 | 
|---|
 | 39 |       ""
 | 
|---|
 | 40 |   )
 | 
|---|
 | 41 | {
 | 
|---|
| [c38826] | 42 |   //std::cout << "ActionTraits::ActionTraits(string &) with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl;
 | 
|---|
| [e4afb4] | 43 | }
 | 
|---|
| [df32ee] | 44 | 
 | 
|---|
| [e4afb4] | 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
 | 
|---|
| [df32ee] | 48 |  */
 | 
|---|
| [e4afb4] | 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() : ""
 | 
|---|
| [b59da6] | 55 |   ),
 | 
|---|
 | 56 |   MenuTitle(_Traits.MenuTitle),
 | 
|---|
 | 57 |   MenuPosition(_Traits.MenuPosition)
 | 
|---|
| [e4afb4] | 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 |   }
 | 
|---|
| [c38826] | 67 |   //std::cout << "ActionTraits::ActionTraits(ActionTraits &) with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl;
 | 
|---|
| [e4afb4] | 68 | }
 | 
|---|
| [df32ee] | 69 | 
 | 
|---|
| [e4afb4] | 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
 | 
|---|
| [df32ee] | 73 |  */
 | 
|---|
| [b59da6] | 74 | ActionTraits::ActionTraits(const OptionTrait &_Traits, const std::string _MenuTitle, const int _MenuPosition) :
 | 
|---|
 | 75 |   OptionTrait(_Traits),
 | 
|---|
 | 76 |   MenuTitle(_MenuTitle),
 | 
|---|
 | 77 |   MenuPosition(_MenuPosition)
 | 
|---|
| [df32ee] | 78 | {
 | 
|---|
| [c38826] | 79 |   //std::cout << "ActionTraits::ActionTraits(OptionTrait &) with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl;
 | 
|---|
| [df32ee] | 80 | }
 | 
|---|
 | 81 | 
 | 
|---|
| [e4afb4] | 82 | /** Constructor for base class ActionTraits.
 | 
|---|
 | 83 |  * Deletes all present Options.
 | 
|---|
| [df32ee] | 84 |  */
 | 
|---|
| [e4afb4] | 85 | ActionTraits::~ActionTraits()
 | 
|---|
| [df32ee] | 86 | {
 | 
|---|
| [e4afb4] | 87 |   for (options_iterator iter = Options.begin(); !Options.empty(); iter = Options.begin()) {
 | 
|---|
 | 88 |     delete (iter->second);
 | 
|---|
 | 89 |     Options.erase(iter);
 | 
|---|
 | 90 |   }
 | 
|---|
| [df32ee] | 91 | }
 | 
|---|
 | 92 | 
 | 
|---|
| [e4afb4] | 93 | 
 | 
|---|
| [53be34] | 94 | /** Returns menu title for this ActionTrait.
 | 
|---|
 | 95 |  * \return ActionTraits::MenuTitle as std::string
 | 
|---|
 | 96 |  */
 | 
|---|
| [e4afb4] | 97 | const std::string& ActionTraits::getMenuName() const
 | 
|---|
| [53be34] | 98 | {
 | 
|---|
 | 99 |   return MenuTitle;
 | 
|---|
 | 100 | }
 | 
|---|
 | 101 | 
 | 
|---|
 | 102 | /** Returns menu title for this ActionTrait.
 | 
|---|
 | 103 |  * \return ActionTraits::MenuPosition as std::string
 | 
|---|
 | 104 |  */
 | 
|---|
| [b59da6] | 105 | int ActionTraits::getMenuPosition() const
 | 
|---|
| [53be34] | 106 | {
 | 
|---|
 | 107 |   return MenuPosition;
 | 
|---|
 | 108 | }
 | 
|---|
 | 109 | 
 | 
|---|
 | 110 | /** Returns Description for the given option of this ActionTrait.
 | 
|---|
| [e4afb4] | 111 |  * \param &token token of option
 | 
|---|
 | 112 |  * \return reference to OptionTrait
 | 
|---|
| [53be34] | 113 |  */
 | 
|---|
| [e4afb4] | 114 | OptionTrait const & ActionTraits::getOption(const std::string &token) const
 | 
|---|
| [53be34] | 115 | {
 | 
|---|
| [e4afb4] | 116 |   ASSERT(Options.find(token) != Options.end(),
 | 
|---|
 | 117 |       "ActionTraits::getOption() - Option not found!");
 | 
|---|
 | 118 |   return *(Options.find(token)->second);
 | 
|---|
| [53be34] | 119 | }
 | 
|---|
 | 120 | 
 | 
|---|
| [e4afb4] | 121 | /** States whether given option (token) is present or not.
 | 
|---|
 | 122 |  * \param &token name of option
 | 
|---|
 | 123 |  * \return true - option present, false - not
 | 
|---|
| [df32ee] | 124 |  */
 | 
|---|
| [e4afb4] | 125 | bool ActionTraits::hasOption(const std::string &token) const
 | 
|---|
| [df32ee] | 126 | {
 | 
|---|
| [e4afb4] | 127 |   return (Options.find(token) != Options.end());
 | 
|---|
| [df32ee] | 128 | }
 | 
|---|
 | 129 | 
 | 
|---|
| [e4afb4] | 130 | /** States whether this Action has options at all.
 | 
|---|
 | 131 |  * \return true - options present, false - no options
 | 
|---|
| [df32ee] | 132 |  */
 | 
|---|
| [e4afb4] | 133 | bool ActionTraits::hasOptions() const
 | 
|---|
| [df32ee] | 134 | {
 | 
|---|
| [e4afb4] | 135 |   return (Options.begin() != Options.end());
 | 
|---|
| [df32ee] | 136 | }
 | 
|---|
 | 137 | 
 | 
|---|
| [53be34] | 138 | /** Forward iterator from beginning of list of options.
 | 
|---|
 | 139 |  * \return iterator
 | 
|---|
 | 140 |  */
 | 
|---|
 | 141 | ActionTraits::options_iterator ActionTraits::getBeginIter()
 | 
|---|
 | 142 | {
 | 
|---|
| [e4afb4] | 143 |   return Options.begin();
 | 
|---|
| [53be34] | 144 | }
 | 
|---|
 | 145 | 
 | 
|---|
 | 146 | /** Forward iterator at end of list of options.
 | 
|---|
 | 147 |  * \return iterator
 | 
|---|
 | 148 |  */
 | 
|---|
 | 149 | ActionTraits::options_iterator ActionTraits::getEndIter()
 | 
|---|
 | 150 | {
 | 
|---|
| [e4afb4] | 151 |   return Options.end();
 | 
|---|
| [53be34] | 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 | {
 | 
|---|
| [e4afb4] | 159 |   return Options.begin();
 | 
|---|
| [53be34] | 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 | {
 | 
|---|
| [e4afb4] | 167 |   return Options.end();
 | 
|---|
| [53be34] | 168 | }
 | 
|---|
 | 169 | 
 | 
|---|
 | 170 | 
 | 
|---|