/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010-2012 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * ElementsTextQuery.cpp * * Created on: Oct 25, 2010 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include #include #include "TextUI/Query/TextQuery.hpp" #include "CodePatterns/Log.hpp" #include "CodePatterns/Verbose.hpp" #include "Element/element.hpp" #include "Element/periodentafel.hpp" #include "World.hpp" using boost::lexical_cast; using boost::bad_lexical_cast; TextDialog::ElementsTextQuery::ElementsTextQuery(Parameter > ¶m, std::string title, std::string _description) : Dialog::ElementsQuery(param, title,_description) {} TextDialog::ElementsTextQuery::~ElementsTextQuery() {} bool TextDialog::ElementsTextQuery::handle() { std::string shorthand; int Z=-1; std::cout << getDescription() << ": "; std::string line; getline(std::cin,line); // dissect by " " std::string::iterator olditer = line.begin(); std::vector temp_elements; for(std::string::iterator iter = line.begin(); iter != line.end(); ++iter) { if (*iter == ' ') { std::istringstream stream(std::string(iter, olditer)); stream >> shorthand; try { Z = lexical_cast(shorthand); temp = World::getInstance().getPeriode()->FindElement(Z); } catch (bad_lexical_cast) { temp = World::getInstance().getPeriode()->FindElement(shorthand.c_str()); }; if(!temp && Z!=-1){ std::cout << "Invalid Element" << shorthand << std::endl; break; } temp_elements.push_back(temp); olditer = iter; } } if (olditer != line.begin()) { // insert last part also std::istringstream stream(std::string(olditer, line.end())); stream >> shorthand; try { Z = lexical_cast(shorthand); temp = World::getInstance().getPeriode()->FindElement(Z); } catch (bad_lexical_cast) { temp = World::getInstance().getPeriode()->FindElement(shorthand.c_str()); }; if(!temp && Z!=-1) { std::cout << "Invalid Element" << shorthand << std::endl; temp_elements.push_back(temp); } } tmp.set(temp_elements); return (Z!=-1); }