source: src/UIElements/TextUI/TextDialog.cpp@ e588312

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since e588312 was e588312, checked in by Tillmann Crueger <crueger@…>, 14 years ago

Merge branch 'stable' into StructureRefactoring

  • Property mode set to 100644
File size: 18.5 KB
Line 
1/*
2 * TextDialog.cpp
3 *
4 * Created on: Jan 5, 2010
5 * Author: crueger
6 */
7
8#include "Helpers/MemDebug.hpp"
9
10#include <iostream>
11
12#include <Descriptors/AtomDescriptor.hpp>
13#include <Descriptors/AtomIdDescriptor.hpp>
14#include <Descriptors/MoleculeDescriptor.hpp>
15#include <Descriptors/MoleculeIdDescriptor.hpp>
16#include <boost/lexical_cast.hpp>
17#include "TextUI/TextDialog.hpp"
18
19#include "World.hpp"
20#include "periodentafel.hpp"
21#include "Helpers/Log.hpp"
22#include "Helpers/Verbose.hpp"
23
24#include "atom.hpp"
25#include "element.hpp"
26#include "molecule.hpp"
27#include "LinearAlgebra/Vector.hpp"
28#include "LinearAlgebra/Matrix.hpp"
29#include "Box.hpp"
30
31#include <boost/lexical_cast.hpp>
32
33using namespace std;
34
35using boost::lexical_cast;
36using boost::bad_lexical_cast;
37
38
39TextDialog::TextDialog()
40{
41}
42
43TextDialog::~TextDialog()
44{
45}
46
47
48void TextDialog::queryEmpty(const char* title, string description){
49 registerQuery(new EmptyTextQuery(title,description));
50}
51
52void TextDialog::queryBoolean(const char* title, string description){
53 registerQuery(new BooleanTextQuery(title,description));
54}
55
56void TextDialog::queryInt(const char* title, string description){
57 registerQuery(new IntTextQuery(title,description));
58}
59
60void TextDialog::queryInts(const char* title, string description){
61 registerQuery(new IntsTextQuery(title,description));
62}
63
64void TextDialog::queryDouble(const char* title, string description){
65 registerQuery(new DoubleTextQuery(title,description));
66}
67
68void TextDialog::queryDoubles(const char* title, string description){
69 registerQuery(new DoublesTextQuery(title,description));
70}
71
72void TextDialog::queryString(const char* title, string description){
73 registerQuery(new StringTextQuery(title,description));
74}
75
76void TextDialog::queryStrings(const char* title, string description){
77 registerQuery(new StringsTextQuery(title,description));
78}
79
80void TextDialog::queryAtom(const char* title, string description) {
81 registerQuery(new AtomTextQuery(title,description));
82}
83
84void TextDialog::queryAtoms(const char* title, string description) {
85 registerQuery(new AtomsTextQuery(title,description));
86}
87
88void TextDialog::queryMolecule(const char* title, string description) {
89 registerQuery(new MoleculeTextQuery(title,description));
90}
91
92void TextDialog::queryMolecules(const char* title, string description) {
93 registerQuery(new MoleculesTextQuery(title,description));
94}
95
96void TextDialog::queryVector(const char* title, bool check, string description) {
97 registerQuery(new VectorTextQuery(title,check,description));
98}
99
100void TextDialog::queryVectors(const char* title, bool check, string description) {
101 registerQuery(new VectorsTextQuery(title,check,description));
102}
103
104void TextDialog::queryBox(const char* title, string description) {
105 registerQuery(new BoxTextQuery(title,description));
106}
107
108void TextDialog::queryElement(const char* title, string description){
109 registerQuery(new ElementTextQuery(title,description));
110}
111
112void TextDialog::queryElements(const char* title, string description){
113 registerQuery(new ElementsTextQuery(title,description));
114}
115
116/************************** Query Infrastructure ************************/
117
118TextDialog::EmptyTextQuery::EmptyTextQuery(string title, std::string _description) :
119 Dialog::EmptyQuery(title,_description)
120{}
121
122TextDialog::EmptyTextQuery::~EmptyTextQuery() {}
123
124bool TextDialog::EmptyTextQuery::handle() {
125 cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n";
126 return true;
127}
128
129TextDialog::IntTextQuery::IntTextQuery(string title, std::string _description) :
130 Dialog::IntQuery(title,_description)
131{}
132
133TextDialog::IntTextQuery::~IntTextQuery() {}
134
135bool TextDialog::IntTextQuery::handle() {
136 bool badInput = false;
137 do{
138 badInput = false;
139 Log() << Verbose(0) << getTitle();
140 cin >> tmp;
141 if(cin.fail()){
142 badInput=true;
143 cin.clear();
144 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
145 Log() << Verbose(0) << "Input was not a number!" << endl;
146 }
147 } while(badInput);
148 // clear the input buffer of anything still in the line
149 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
150 return true;
151}
152
153TextDialog::IntsTextQuery::IntsTextQuery(string title, std::string _description) :
154 Dialog::IntsQuery(title,_description)
155{}
156
157TextDialog::IntsTextQuery::~IntsTextQuery() {}
158
159bool TextDialog::IntsTextQuery::handle() {
160 Log() << Verbose(0) << getTitle();
161 std::string line;
162 getline(cin,line);
163 // dissect by " "
164 string::iterator olditer = line.begin();
165 for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
166 if (*iter == ' ') {
167 std::istringstream stream(string(iter, olditer));
168 stream >> temp;
169 tmp.push_back(temp);
170 olditer = iter;
171 }
172 }
173 if (olditer != line.begin()) { // insert last part also
174 std::istringstream stream(string(olditer, line.end()));
175 stream >> temp;
176 tmp.push_back(temp);
177 }
178
179 return true;
180}
181
182TextDialog::BooleanTextQuery::BooleanTextQuery(string title, std::string _description) :
183 Dialog::BooleanQuery(title,_description)
184{}
185
186TextDialog::BooleanTextQuery::~BooleanTextQuery() {}
187
188bool TextDialog::BooleanTextQuery::handle() {
189 bool badInput = false;
190 char input = ' ';
191 do{
192 badInput = false;
193 Log() << Verbose(0) << getTitle();
194 cin >> input;
195 if ((input == 'y' ) || (input == 'Y')) {
196 tmp = true;
197 } else if ((input == 'n' ) || (input == 'N')) {
198 tmp = false;
199 } else {
200 badInput=true;
201 cin.clear();
202 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
203 Log() << Verbose(0) << "Input was not of [yYnN]!" << endl;
204 }
205 } while(badInput);
206 // clear the input buffer of anything still in the line
207 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
208 return true;
209}
210
211TextDialog::StringTextQuery::StringTextQuery(string title, std::string _description) :
212 Dialog::StringQuery(title,_description)
213{}
214
215TextDialog::StringTextQuery::~StringTextQuery() {}
216
217bool TextDialog::StringTextQuery::handle() {
218 Log() << Verbose(0) << getTitle();
219 getline(cin,tmp);
220 return true;
221}
222
223TextDialog::StringsTextQuery::StringsTextQuery(string title, std::string _description) :
224 Dialog::StringsQuery(title,_description)
225{}
226
227TextDialog::StringsTextQuery::~StringsTextQuery() {}
228
229bool TextDialog::StringsTextQuery::handle() {
230 Log() << Verbose(0) << getTitle();
231 getline(cin,temp);
232 // dissect by " "
233 string::iterator olditer = temp.begin();
234 for(string::iterator iter = temp.begin(); iter != temp.end(); ++iter) {
235 if (*iter == ' ') {
236 tmp.push_back(string(iter, olditer));
237 olditer = iter;
238 }
239 }
240 if (olditer != temp.begin()) // insert last part also
241 tmp.push_back(string(olditer, temp.end()));
242
243 return true;
244}
245
246TextDialog::DoubleTextQuery::DoubleTextQuery(string title, std::string _description) :
247 Dialog::DoubleQuery(title,_description)
248{}
249
250TextDialog::DoubleTextQuery::~DoubleTextQuery() {}
251
252bool TextDialog::DoubleTextQuery::handle() {
253 bool badInput = false;
254 do{
255 badInput = false;
256 Log() << Verbose(0) << getTitle();
257 cin >> tmp;
258 if(cin.fail()){
259 badInput = true;
260 cin.clear();
261 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
262 Log() << Verbose(0) << "Input was not a number!" << endl;
263 }
264 }while(badInput);
265 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
266 return true;
267}
268
269
270TextDialog::DoublesTextQuery::DoublesTextQuery(string title, std::string _description) :
271 Dialog::DoublesQuery(title,_description)
272{}
273
274TextDialog::DoublesTextQuery::~DoublesTextQuery() {}
275
276bool TextDialog::DoublesTextQuery::handle() {
277 Log() << Verbose(0) << getTitle();
278 std::string line;
279 getline(cin,line);
280 // dissect by " "
281 string::iterator olditer = line.begin();
282 for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
283 if (*iter == ' ') {
284 std::istringstream stream(string(iter, olditer));
285 stream >> temp;
286 tmp.push_back(temp);
287 olditer = iter;
288 }
289 }
290 if (olditer != line.begin()) { // insert last part also
291 std::istringstream stream(string(olditer, line.end()));
292 stream >> temp;
293 tmp.push_back(temp);
294 }
295
296 return true;
297}
298
299TextDialog::AtomTextQuery::AtomTextQuery(string title, std::string _description) :
300 Dialog::AtomQuery(title,_description)
301{}
302
303TextDialog::AtomTextQuery::~AtomTextQuery() {}
304
305bool TextDialog::AtomTextQuery::handle() {
306 int idxOfAtom=-1;
307 bool badInput = false;
308 do{
309 badInput = false;
310 Log() << Verbose(0) << getTitle();
311 cin >> idxOfAtom;
312 if(cin.fail()){
313 badInput = true;
314 cin.clear();
315 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
316 Log() << Verbose(0) << "Input was not a number!" << endl;
317 continue;
318 }
319
320 tmp = World::getInstance().getAtom(AtomById(idxOfAtom));
321 if(!tmp && idxOfAtom!=-1){
322 Log() << Verbose(0) << "Invalid Atom Index" << idxOfAtom << endl;
323 badInput = true;
324 }
325
326 } while(badInput);
327 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
328 return (idxOfAtom!=-1);
329}
330
331
332TextDialog::AtomsTextQuery::AtomsTextQuery(string title, std::string _description) :
333 Dialog::AtomsQuery(title,_description)
334{}
335
336TextDialog::AtomsTextQuery::~AtomsTextQuery() {}
337
338bool TextDialog::AtomsTextQuery::handle() {
339 int idxOfAtom=-1;
340 Log() << Verbose(0) << getTitle();
341 std::string line;
342 getline(cin,line);
343 // dissect by " "
344 string::iterator olditer = line.begin();
345 for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
346 if (*iter == ' ') {
347 std::istringstream stream(string(iter, olditer));
348 stream >> idxOfAtom;
349 temp = World::getInstance().getAtom(AtomById(idxOfAtom));
350 if(!temp && idxOfAtom!=-1){
351 Log() << Verbose(0) << "Invalid Atom Index" << idxOfAtom << endl;
352 break;
353 }
354 tmp.push_back(temp);
355 olditer = iter;
356 }
357 }
358 if (olditer != line.begin()) { // insert last part also
359 std::istringstream stream(string(olditer, line.end()));
360 stream >> idxOfAtom;
361 temp = World::getInstance().getAtom(AtomById(idxOfAtom));
362 if(!temp && idxOfAtom!=-1) {
363 Log() << Verbose(0) << "Invalid Atom Index" << idxOfAtom << endl;
364 tmp.push_back(temp);
365 }
366 }
367
368 return (idxOfAtom!=-1);
369}
370
371TextDialog::MoleculeTextQuery::MoleculeTextQuery(string title, std::string _description) :
372 Dialog::MoleculeQuery(title,_description)
373{}
374
375TextDialog::MoleculeTextQuery::~MoleculeTextQuery() {}
376
377bool TextDialog::MoleculeTextQuery::handle() {
378 int idxOfMol=0;
379 bool badInput = false;
380 do{
381 badInput = false;
382 Log() << Verbose(0) << getTitle();
383 cin >> idxOfMol;
384 if(cin.fail()){
385 badInput = true;
386 cin.clear();
387 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
388 Log() << Verbose(0) << "Input was not a number!" << endl;
389 continue;
390 }
391
392 tmp = World::getInstance().getMolecule(MoleculeById(idxOfMol));
393 if(!tmp && idxOfMol!=-1){
394 Log() << Verbose(0) << "Invalid Molecule Index" << endl;
395 badInput = true;
396 }
397
398 } while(badInput);
399 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
400 return (idxOfMol!=-1);
401}
402
403
404TextDialog::MoleculesTextQuery::MoleculesTextQuery(string title, std::string _description) :
405 Dialog::MoleculesQuery(title,_description)
406{}
407
408TextDialog::MoleculesTextQuery::~MoleculesTextQuery() {}
409
410bool TextDialog::MoleculesTextQuery::handle() {
411 int idxOfMol=-1;
412 Log() << Verbose(0) << getTitle();
413 std::string line;
414 getline(cin,line);
415 // dissect by " "
416 string::iterator olditer = line.begin();
417 for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
418 if (*iter == ' ') {
419 std::istringstream stream(string(iter, olditer));
420 stream >> idxOfMol;
421 temp = World::getInstance().getMolecule(MoleculeById(idxOfMol));
422 if(!temp && idxOfMol!=-1){
423 Log() << Verbose(0) << "Invalid Molecule Index" << idxOfMol << endl;
424 break;
425 }
426 tmp.push_back(temp);
427 olditer = iter;
428 }
429 }
430 if (olditer != line.begin()) { // insert last part also
431 std::istringstream stream(string(olditer, line.end()));
432 stream >> idxOfMol;
433 temp = World::getInstance().getMolecule(MoleculeById(idxOfMol));
434 if(!temp && idxOfMol!=-1){
435 Log() << Verbose(0) << "Invalid Molecule Index" << idxOfMol << endl;
436 tmp.push_back(temp);
437 }
438 }
439
440 return (idxOfMol!=-1);
441}
442
443TextDialog::VectorTextQuery::VectorTextQuery(std::string title, bool _check, std::string _description) :
444 Dialog::VectorQuery(title,_check,_description)
445{}
446
447TextDialog::VectorTextQuery::~VectorTextQuery()
448{}
449
450bool TextDialog::VectorTextQuery::handle() {
451 std::cout << getTitle();
452 const Matrix &M = World::getInstance().getDomain().getM();
453 char coords[3] = {'x', 'y', 'z'};
454 for (int i=0;i<3;i++)
455 std::cout << coords[i] << "[0.." << M.at(i,i) << ( (i!=2) ? "], " : "]: ");
456
457 std::string line;
458 getline(cin,line);
459
460 // dissect by ","
461 double coord = 0.;
462 int counter = 0;
463 string::iterator olditer = line.begin();
464 for(string::iterator iter = line.begin(); (iter != line.end()) && (counter != 3); ++iter) {
465 if (*iter == ',') {
466 std::istringstream stream(string(iter, olditer));
467 stream >> coord;
468 tmp[counter++] = coord;
469 olditer = iter;
470 }
471 }
472 if ((olditer != line.begin()) && (counter != 3)) { // insert last part also
473 std::istringstream stream(string(olditer, line.end()));
474 stream >> coord;
475 tmp[counter++] = coord;
476 }
477
478 // check vector
479 return World::getInstance().getDomain().isInside(tmp);
480}
481
482TextDialog::VectorsTextQuery::VectorsTextQuery(std::string title, bool _check, std::string _description) :
483 Dialog::VectorsQuery(title,_check,_description)
484{}
485
486TextDialog::VectorsTextQuery::~VectorsTextQuery()
487{}
488
489bool TextDialog::VectorsTextQuery::handle() {
490 std::cout << getTitle();
491 char coords[3] = {'x', 'y', 'z'};
492 const Matrix &M = World::getInstance().getDomain().getM();
493 for (int i=0;i<3;i++)
494 std::cout << coords[i] << "[0.." << M.at(i,i) << ( (i!=2) ? "], " : "]: ");
495
496 std::string line;
497 getline(cin,line);
498
499 // dissect by ","
500 double coord = 0.;
501 string::iterator olditerspace = line.begin();
502 string::iterator olditercomma = line.begin();
503 int counter = 0;
504 for(string::iterator vectoriter = line.begin(); vectoriter != line.end(); ++vectoriter) {
505 if (*vectoriter == ',')
506 counter++;
507 if ((*vectoriter == ' ') && (counter == 2)) {
508 counter = 0;
509 for(string::iterator componentiter = olditerspace; (componentiter != vectoriter) && (counter !=3); ++componentiter) {
510 if (*componentiter == ',') {
511 std::istringstream stream(string(componentiter, olditercomma));
512 stream >> coord;
513 temp[counter++] = coord;
514 olditercomma = componentiter;
515 }
516 }
517 if ((olditercomma != line.begin()) && (counter != 3)) { // insert last part also
518 std::istringstream stream(string(olditercomma, vectoriter));
519 stream >> coord;
520 temp[counter++] = coord;
521 }
522 if (World::getInstance().getDomain().isInside(temp))
523 tmp.push_back(temp);
524 olditerspace = vectoriter;
525 }
526 }
527 return true;
528}
529
530TextDialog::BoxTextQuery::BoxTextQuery(std::string title, std::string _description) :
531 Dialog::BoxQuery(title,_description)
532{}
533
534TextDialog::BoxTextQuery::~BoxTextQuery()
535{}
536
537bool TextDialog::BoxTextQuery::handle() {
538 Log() << Verbose(0) << getTitle();
539
540 double temp[6];
541 std::string coords[6] = {"xx","yx","yy", "zx", "zy", "zz"};
542 for (int i=0;i<6;i++) {
543 Log() << Verbose(0) << coords[i] << ": ";
544 cin >> temp[i];
545 }
546 Matrix M;
547 M.set(0,0, temp[0]);
548 M.set(0,1, temp[1]);
549 M.set(0,2, temp[2]);
550 M.set(1,0, temp[1]);
551 M.set(1,1, temp[3]);
552 M.set(1,2, temp[4]);
553 M.set(2,0, temp[2]);
554 M.set(2,1, temp[4]);
555 M.set(2,2, temp[5]);
556 tmp.setM(M);
557 return true;
558}
559
560TextDialog::ElementTextQuery::ElementTextQuery(std::string title, std::string _description) :
561 Dialog::ElementQuery(title,_description)
562{}
563
564TextDialog::ElementTextQuery::~ElementTextQuery()
565{}
566
567bool TextDialog::ElementTextQuery::handle() {
568 bool badInput=false;
569 bool aborted = false;
570 const element * temp = NULL;
571 do{
572 badInput = false;
573 Log() << Verbose(0) << getTitle();
574
575 // try to read as Atomic number
576 int Z;
577 cin >> Z;
578 if(!cin.fail()){
579 if(Z==-1){
580 aborted = true;
581 }
582 else{
583 temp = World::getInstance().getPeriode()->FindElement(Z);
584 if(!temp){
585 Log() << Verbose(0) << "No element with this atomic number!" << endl;
586 badInput = true;
587 }
588 }
589 continue;
590 }
591 else{
592 cin.clear();
593 }
594
595 // Try to read as shorthand
596 // the last buffer content was not removed, so we read the
597 // same thing again, this time as a string
598 string shorthand;
599 cin >> shorthand;
600 if(!cin.fail()){
601 if(shorthand.empty()){
602 aborted = true;
603 }
604 else{
605 temp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
606 if(!temp){
607 Log() << Verbose(0) << "No element with this shorthand!" << endl;
608 badInput = true;
609 }
610 }
611 }
612 else{
613 Log() << Verbose(0) << "Could not read input. Try Again." << endl;
614 cin.clear();
615 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
616 badInput = true;
617 }
618
619 }while(badInput);
620 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
621 return !aborted;
622}
623
624TextDialog::ElementsTextQuery::ElementsTextQuery(std::string title, std::string _description) :
625 Dialog::ElementsQuery(title,_description)
626{}
627
628TextDialog::ElementsTextQuery::~ElementsTextQuery()
629{}
630
631bool TextDialog::ElementsTextQuery::handle() {
632 std::string shorthand;
633 int Z=-1;
634 Log() << Verbose(0) << getTitle();
635 std::string line;
636 getline(cin,line);
637 // dissect by " "
638 string::iterator olditer = line.begin();
639 for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
640 if (*iter == ' ') {
641 std::istringstream stream(string(iter, olditer));
642 stream >> shorthand;
643 try {
644 Z = lexical_cast<int>(shorthand);
645 temp = World::getInstance().getPeriode()->FindElement(Z);
646 } catch (bad_lexical_cast) {
647 temp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
648 };
649 if(!temp && Z!=-1){
650 Log() << Verbose(0) << "Invalid Element" << shorthand << endl;
651 break;
652 }
653 tmp.push_back(temp);
654 olditer = iter;
655 }
656 }
657 if (olditer != line.begin()) { // insert last part also
658 std::istringstream stream(string(olditer, line.end()));
659 stream >> shorthand;
660 try {
661 Z = lexical_cast<int>(shorthand);
662 temp = World::getInstance().getPeriode()->FindElement(Z);
663 } catch (bad_lexical_cast) {
664 temp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
665 };
666 if(!temp && Z!=-1) {
667 Log() << Verbose(0) << "Invalid Element" << shorthand << endl;
668 tmp.push_back(temp);
669 }
670 }
671
672 return (Z!=-1);
673}
Note: See TracBrowser for help on using the repository browser.