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