source: src/UIElements/TextUI/TextDialog.cpp@ 8bc733

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 8bc733 was 8bc733, checked in by Frederik Heber <heber@…>, 14 years ago

BoxQuery contains Box not double[6].

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