/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010-2012 University of Bonn. All rights reserved. * * * This file is part of MoleCuilder. * * MoleCuilder is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * MoleCuilder is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MoleCuilder. If not, see . */ /* * ActionTrait.cpp * * Created on: Oct 26, 2010 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include "Actions/ActionTrait.hpp" #include "CodePatterns/Assert.hpp" #include #include #include #include using namespace MoleCuilder; /** Copy constructor for base class ActionTrait. * \param &_Traits source ActionTrait class to copy */ ActionTrait::ActionTrait(const std::string &_token) : OptionTrait(_token, &typeid(void), "this is an invisible action", "", "" ) { //std::cout << "ActionTrait::ActionTrait(std::string &) on instance " << this << " with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl; } /** Copy constructor for base class ActionTrait. * we have to make our own copy in order to avoid references and deep-copy everything. * \param &_Traits source ActionTrait class to copy */ ActionTrait::ActionTrait(const ActionTrait &_Traits) : OptionTrait(_Traits), MenuTitle(_Traits.MenuTitle), MenuPosition(_Traits.MenuPosition) { for (options_const_iterator iter = _Traits.Options.begin(); iter != _Traits.Options.end(); ++iter) { Options.insert( std::make_pair( iter->first, new OptionTrait(*iter->second) ) ); } //std::cout << "ActionTrait::ActionTrait(ActionTrait &) on instance " << this << " with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl; } /** Copy constructor for base class ActionTrait. * we have to make our own copy in order to avoid references and deep-copy everything. * \param &_Traits source OptionTrait class to copy */ ActionTrait::ActionTrait(const OptionTrait &_Traits, const std::string _MenuTitle, const int _MenuPosition) : OptionTrait(_Traits), MenuTitle(_MenuTitle), MenuPosition(_MenuPosition) { //std::cout << "ActionTrait::ActionTrait(OptionTrait &) on instance " << this << " with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl; } /** Constructor for base class ActionTrait. * Deletes all present Options. */ ActionTrait::~ActionTrait() { //std::cout << "ActionTrait::~ActionTrait() on instance " << this << " with name " << getName() << " called." << std::endl; for (options_iterator iter = Options.begin(); iter != Options.end(); ++iter) { //std::cout << "ActionTrait::~ActionTrait() removes option instance " << iter->second << " with name " << iter->first << "." << std::endl; delete iter->second; } Options.clear(); } /** Returns menu title for this ActionTrait. * \return ActionTrait::MenuTitle as std::string */ const std::string& ActionTrait::getMenuName() const { return MenuTitle; } /** Returns menu title for this ActionTrait. * \return ActionTrait::MenuPosition as std::string */ int ActionTrait::getMenuPosition() const { return MenuPosition; } /** Returns Description for the given option of this ActionTrait. * \param &token token of option * \return reference to OptionTrait */ OptionTrait const & ActionTrait::getOption(const std::string &token) const { ASSERT(Options.find(token) != Options.end(), "ActionTrait::getOption() - Option not found!"); return *(Options.find(token)->second); } /** States whether given option (token) is present or not. * \param &token name of option * \return true - option present, false - not */ bool ActionTrait::hasOption(const std::string &token) const { return (Options.find(token) != Options.end()); } /** States whether this Action has options at all. * \return true - options present, false - no options */ bool ActionTrait::hasOptions() const { return (Options.begin() != Options.end()); } /** Forward iterator from beginning of list of options. * \return iterator */ ActionTrait::options_iterator ActionTrait::getBeginIter() { return Options.begin(); } /** Forward iterator at end of list of options. * \return iterator */ ActionTrait::options_iterator ActionTrait::getEndIter() { return Options.end(); } /** Constant forward iterator from beginning of list of options. * \return constant iterator */ ActionTrait::options_const_iterator ActionTrait::getBeginIter() const { return Options.begin(); } /** Constant forward iterator at end of list of options. * \return constant iterator */ ActionTrait::options_const_iterator ActionTrait::getEndIter() const { return Options.end(); } /** Output operator for ActionTrait. * * \param &out stream to output to */ std::ostream &operator<<(std::ostream &out, const ActionTrait &a) { out << "ActionTrait(" << &a << ") with " << static_cast(a) << " has the following options: " << std::endl; for (ActionTrait::options_const_iterator iter = a.getBeginIter(); iter != a.getEndIter(); ++iter) { out << "\t - " << *iter->second << ")" << std::endl; } return out; }