Ignore:
Timestamp:
Feb 2, 2015, 7:20:43 PM (10 years ago)
Author:
Frederik Heber <heber@…>
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:
55feff5
Parents:
27e464
git-author:
Frederik Heber <heber@…> (10/17/14 16:50:10)
git-committer:
Frederik Heber <heber@…> (02/02/15 19:20:43)
Message:

CommandLineParser adds Action's default values as implicit.

  • this allows to have action's token as option with both empty (then default is used) and some given argument.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/CommandLineUI/CommandLineParser.cpp

    r27e464 r7912e9  
    147147//        std::cout << std::endl;
    148148
    149         AddOptionToParser(currentOption, (CmdParserLookup["options"]));
     149        AddOptionToParser(currentOption, (CmdParserLookup["options"]),
     150            (optioniter->first == *iter) ?
     151                true : false);
    150152
    151153        AlreadyAddedOptionNames.insert(optioniter->first);
     
    174176      ASSERT(CmdParserLookup.find(CurrentTrait.getMenuName()) != CmdParserLookup.end(),
    175177          "CommandLineParser: boost::program_options::options_description for this Action not present.");
    176       AddOptionToParser(dynamic_cast<const OptionTrait * const>(&CurrentTrait),(CmdParserLookup[CurrentTrait.getMenuName()]));
     178      AddOptionToParser(
     179          dynamic_cast<const OptionTrait * const>(&CurrentTrait),
     180          (CmdParserLookup[CurrentTrait.getMenuName()]),
     181          false);
    177182    }
    178183  }
     
    191196 * \param *currentOption pointer to Action/Option to add
    192197 * \param *OptionList program_options list to add to
    193  */
    194 void CommandLineParser::AddOptionToParser(const OptionTrait * const currentOption, po::options_description* OptionList)
     198 * \param _DefaultAsImplicit whether to add a default value as default_value or
     199 *        as implicit_value (default = option token present or not, implicit =
     200          option token present but not necessarily followed by argument)
     201 */
     202void CommandLineParser::AddOptionToParser(
     203    const OptionTrait * const currentOption,
     204    po::options_description* OptionList,
     205    const bool _DefaultAsImplicit)
    195206{
    196207  // check whether dynamic_cast in Init() suceeded
     
    212223        (currentOption->getKeyAndShortForm().c_str(),
    213224            currentOption->hasDefaultValue() ?
    214                   po::value < bool >()->default_value(boost::lexical_cast<int>(currentOption->getDefaultValue().c_str())) :
     225                  (_DefaultAsImplicit ?
     226                      po::value < bool >()->implicit_value(boost::lexical_cast<int>(currentOption->getDefaultValue().c_str())) :
     227                      po::value < bool >()->default_value(boost::lexical_cast<int>(currentOption->getDefaultValue().c_str()))) :
    215228                  po::value < bool >(),
    216229                  currentOption->getDescription().c_str())
     
    239252        (currentOption->getKeyAndShortForm().c_str(),
    240253            currentOption->hasDefaultValue() ?
    241                   po::value < int >()->default_value(boost::lexical_cast<int>(currentOption->getDefaultValue().c_str())) :
     254                  (_DefaultAsImplicit ?
     255                      po::value < int >()->implicit_value(boost::lexical_cast<int>(currentOption->getDefaultValue().c_str())) :
     256                      po::value < int >()->default_value(boost::lexical_cast<int>(currentOption->getDefaultValue().c_str()))) :
    242257                  po::value < int >(),
    243258                  currentOption->getDescription().c_str())
     
    257272        (currentOption->getKeyAndShortForm().c_str(),
    258273            currentOption->hasDefaultValue() ?
    259                   po::value < unsigned int >()->default_value(boost::lexical_cast<unsigned int>(currentOption->getDefaultValue().c_str())) :
     274                  (_DefaultAsImplicit ?
     275                      po::value < unsigned int >()->implicit_value(boost::lexical_cast<unsigned int>(currentOption->getDefaultValue().c_str())) :
     276                      po::value < unsigned int >()->default_value(boost::lexical_cast<unsigned int>(currentOption->getDefaultValue().c_str()))) :
    260277                  po::value < unsigned int >(),
    261278                  currentOption->getDescription().c_str())
     
    275292        (currentOption->getKeyAndShortForm().c_str(),
    276293            currentOption->hasDefaultValue() ?
    277                   po::value < double >()->default_value(boost::lexical_cast<double>(currentOption->getDefaultValue().c_str())) :
     294                  (_DefaultAsImplicit ?
     295                      po::value < double >()->implicit_value(boost::lexical_cast<double>(currentOption->getDefaultValue().c_str())) :
     296                      po::value < double >()->default_value(boost::lexical_cast<double>(currentOption->getDefaultValue().c_str()))) :
    278297                  po::value < double >(),
    279298                  currentOption->getDescription().c_str())
     
    293312        (currentOption->getKeyAndShortForm().c_str(),
    294313            currentOption->hasDefaultValue() ?
    295                   po::value < std::string >()->default_value(currentOption->getDefaultValue()) :
     314                  (_DefaultAsImplicit ?
     315                      po::value < std::string >()->implicit_value(currentOption->getDefaultValue()) :
     316                      po::value < std::string >()->default_value(currentOption->getDefaultValue())) :
    296317                  po::value < std::string >(),
    297318                  currentOption->getDescription().c_str())
     
    347368        (currentOption->getKeyAndShortForm().c_str(),
    348369            currentOption->hasDefaultValue() ?
    349                   po::value < int >()->default_value(boost::lexical_cast<int>(currentOption->getDefaultValue().c_str())) :
     370                  (_DefaultAsImplicit ?
     371                      po::value < int >()->implicit_value(boost::lexical_cast<int>(currentOption->getDefaultValue().c_str())) :
     372                      po::value < int >()->default_value(boost::lexical_cast<int>(currentOption->getDefaultValue().c_str()))) :
    350373                  po::value < int >(),
    351374                  currentOption->getDescription().c_str())
     
    383406        (currentOption->getKeyAndShortForm().c_str(),
    384407            currentOption->hasDefaultValue() ?
    385                   po::value < std::string >()->default_value(boost::lexical_cast< std::string >(currentOption->getDefaultValue().c_str())) :
     408                  (_DefaultAsImplicit ?
     409                      po::value < std::string >()->implicit_value(boost::lexical_cast< std::string >(currentOption->getDefaultValue().c_str())) :
     410                      po::value < std::string >()->default_value(boost::lexical_cast< std::string >(currentOption->getDefaultValue().c_str()))) :
    386411                  po::value < std::string >(),
    387412                  currentOption->getDescription().c_str())
     
    438463    po::store(po::command_line_parser(argc,argv).options(cmdline_options).run(), vm);
    439464  } catch (std::exception &e) {
    440     std::cerr << "Something went wrong with parsing the command-line arguments." << std::endl;
     465    std::cerr << "Something went wrong with parsing the command-line arguments: "
     466        << e.what() << std::endl;
    441467    World::getInstance().setExitFlag(134);
    442468#ifdef HAVE_ACTION_THREAD
Note: See TracChangeset for help on using the changeset viewer.