Changeset 3a21a7
- Timestamp:
- Dec 4, 2010, 11:42:39 PM (14 years ago)
- Branches:
- 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
- Children:
- 738ae1
- Parents:
- e9be39
- git-author:
- Frederik Heber <heber@…> (11/08/10 13:04:37)
- git-committer:
- Frederik Heber <heber@…> (12/04/10 23:42:39)
- Location:
- src/UIElements
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/CommandLineUI/CommandLineParser.cpp
re9be39 r3a21a7 21 21 22 22 #include <boost/filesystem.hpp> 23 #include <boost/lexical_cast.hpp>24 23 #include <boost/program_options.hpp> 25 24 #include <fstream> 26 25 #include <iostream> 27 26 #include <map> 28 #include <vector>29 27 30 28 #include "Actions/Action.hpp" … … 34 32 #include "Actions/OptionTrait.hpp" 35 33 #include "Actions/Values.hpp" 36 #include "Helpers/Assert.hpp"37 34 #include "Helpers/Log.hpp" 38 35 #include "Helpers/Verbose.hpp" 39 36 #include "CommandLineParser.hpp" 37 #include "CommandLineParser_validate.hpp" 40 38 41 39 #include "Patterns/Singleton_impl.hpp" 42 40 43 41 class element; 44 45 using namespace std;46 47 /** boost::program_options validator specialization for VectorValue.48 * \param &v reference for return value49 * \param &values string vector of scanned options50 * \param *51 * \param52 *53 */54 void validate(boost::any& v, const std::vector<std::string>& values, VectorValue *, int)55 {56 VectorValue VV;57 std::vector<std::string> components;58 59 // split comma-separated values60 if (values.size() != 1) {61 cerr << "Not one vector but " << values.size() << " given " << endl;62 throw boost::program_options::validation_error("Unequal to one vector given");63 }64 std::string argument(values.at(0));65 std::string::iterator Aiter = argument.begin();66 std::string::iterator Biter = argument.begin();67 for (; Aiter != argument.end(); ++Aiter) {68 if (*Aiter == ',') {69 components.push_back(string(Biter,Aiter));70 do {71 Aiter++;72 } while (*Aiter == ' ' || *Aiter == '\t');73 Biter = Aiter;74 }75 }76 components.push_back(string(Biter,argument.end()));77 78 if (components.size() != 3) {79 cerr << "Specified vector does not have three components but " << components.size() << endl;80 throw boost::program_options::validation_error("Specified vector does not have three components");81 }82 VV.x = boost::lexical_cast<double>(components.at(0));83 VV.y = boost::lexical_cast<double>(components.at(1));84 VV.z = boost::lexical_cast<double>(components.at(2));85 v = boost::any(VectorValue(VV));86 }87 88 void validate(boost::any& v, const std::vector<std::string>& values, BoxValue *, int)89 {90 BoxValue BV;91 std::vector<std::string> components;92 93 // split comma-separated values94 if (values.size() != 1) {95 cerr << "Not one vector but " << values.size() << " given " << endl;96 throw boost::program_options::validation_error("Unequal to one vector given");97 }98 std::string argument(values.at(0));99 std::string::iterator Aiter = argument.begin();100 std::string::iterator Biter = argument.begin();101 for (; Aiter != argument.end(); ++Aiter) {102 if (*Aiter == ',') {103 components.push_back(string(Biter,Aiter));104 do {105 Aiter++;106 } while (*Aiter == ' ' || *Aiter == '\t');107 Biter = Aiter;108 }109 }110 components.push_back(string(Biter,argument.end()));111 112 if (components.size() != 6) {113 cerr << "Specified vector does not have three components but " << components.size() << endl;114 throw boost::program_options::validation_error("Specified symmetric box matrix does not have six components");115 }116 BV.xx = boost::lexical_cast<double>(components.at(0));117 BV.yx = boost::lexical_cast<double>(components.at(1));118 BV.yy = boost::lexical_cast<double>(components.at(2));119 BV.zx = boost::lexical_cast<double>(components.at(3));120 BV.zy = boost::lexical_cast<double>(components.at(4));121 BV.zz = boost::lexical_cast<double>(components.at(5));122 v = boost::any(BoxValue(BV));123 }124 125 /** boost::program_options validator specialization for boost::filesystem::path.126 * \param &v reference for return value127 * \param &values string vector of scanned options128 * \param *129 * \param130 *131 */132 void validate(boost::any& v, const std::vector<std::string>& values, boost::filesystem::path *, int)133 {134 boost::filesystem::path filename;135 136 std::cout << "boost::filesystem::path validator used." << std::endl;137 138 // split comma-separated values139 if (values.size() != 1) {140 cerr << "Not one file but " << values.size() << " given " << endl;141 throw boost::program_options::validation_error("Unequal to one file given");142 }143 filename = values.at(0);144 v = boost::any(boost::filesystem::path(filename));145 }146 147 42 148 43 /** Constructor of class CommandLineParser. … … 461 356 { 462 357 po::store(po::command_line_parser(argc,argv).options(cmdline_options).run(), vm); 463 ifstream input;358 std::ifstream input; 464 359 input.open("example.cfg"); 465 360 if (!input.fail()) … … 473 368 void CommandLineParser::scanforSequenceOfArguments() 474 369 { 475 map <std::string, std::string> ShortFormToActionMap = getShortFormToActionMap();370 std::map <std::string, std::string> ShortFormToActionMap = getShortFormToActionMap(); 476 371 // go through all arguments 477 372 for (int i=1;i<argc;i++) { 478 ( cout << Verbose(1) << "Checking on " << argv[i] <<endl);373 (std::cout << Verbose(1) << "Checking on " << argv[i] << std::endl); 479 374 // check whether they 480 375 if (argv[i][0] == '-') { // .. begin with - … … 485 380 // .. and check that next letter is not numeric, if so insert 486 381 } else if (((argv[i][1] < '0') || (argv[i][1] > '9')) && ((argv[i][1] != '.'))) { 487 map <std::string, std::string>::iterator iter = ShortFormToActionMap.find(&(argv[i][1]));382 std::map <std::string, std::string>::iterator iter = ShortFormToActionMap.find(&(argv[i][1])); 488 383 if (iter != ShortFormToActionMap.end()) { 489 384 (cout << Verbose(1) << "Putting " << iter->second << " for " << iter->first << " into the sequence." << endl); … … 511 406 std::map <std::string, std::string> CommandLineParser::getShortFormToActionMap() 512 407 { 513 map <std::string, std::string> result;408 std::map <std::string, std::string> result; 514 409 515 410 ActionRegistry &AR = ActionRegistry::getInstance(); -
src/UIElements/Makefile.am
re9be39 r3a21a7 134 134 CommandLineUI/CommandLineDialog.cpp \ 135 135 CommandLineUI/CommandLineParser.cpp \ 136 CommandLineUI/CommandLineParser_validate.cpp \ 136 137 CommandLineUI/CommandLineStatusIndicator.cpp \ 137 138 CommandLineUI/CommandLineUIFactory.cpp \ … … 142 143 CommandLineUI/CommandLineDialog.hpp \ 143 144 CommandLineUI/CommandLineParser.hpp \ 145 CommandLineUI/CommandLineParser_validate.hpp \ 144 146 CommandLineUI/CommandLineStatusIndicator.hpp \ 145 147 CommandLineUI/CommandLineUIFactory.hpp \
Note:
See TracChangeset
for help on using the changeset viewer.