Changeset 3a21a7


Ignore:
Timestamp:
Dec 4, 2010, 11:42:39 PM (14 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:
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)
Message:

Moved validate() functions for boost::program_options into own module.

Location:
src/UIElements
Files:
2 added
2 edited

Legend:

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

    re9be39 r3a21a7  
    2121
    2222#include <boost/filesystem.hpp>
    23 #include <boost/lexical_cast.hpp>
    2423#include <boost/program_options.hpp>
    2524#include <fstream>
    2625#include <iostream>
    2726#include <map>
    28 #include <vector>
    2927
    3028#include "Actions/Action.hpp"
     
    3432#include "Actions/OptionTrait.hpp"
    3533#include "Actions/Values.hpp"
    36 #include "Helpers/Assert.hpp"
    3734#include "Helpers/Log.hpp"
    3835#include "Helpers/Verbose.hpp"
    3936#include "CommandLineParser.hpp"
     37#include "CommandLineParser_validate.hpp"
    4038
    4139#include "Patterns/Singleton_impl.hpp"
    4240
    4341class element;
    44 
    45 using namespace std;
    46 
    47 /** boost::program_options validator specialization for VectorValue.
    48  * \param &v  reference for return value
    49  * \param &values string vector of scanned options
    50  * \param *
    51  * \param
    52  *
    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 values
    60   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 values
    94   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 value
    127  * \param &values string vector of scanned options
    128  * \param *
    129  * \param
    130  *
    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 values
    139   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 
    14742
    14843/** Constructor of class CommandLineParser.
     
    461356{
    462357  po::store(po::command_line_parser(argc,argv).options(cmdline_options).run(), vm);
    463   ifstream input;
     358  std::ifstream input;
    464359  input.open("example.cfg");
    465360  if (!input.fail())
     
    473368void CommandLineParser::scanforSequenceOfArguments()
    474369{
    475   map <std::string, std::string> ShortFormToActionMap = getShortFormToActionMap();
     370  std::map <std::string, std::string> ShortFormToActionMap = getShortFormToActionMap();
    476371  // go through all arguments
    477372  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);
    479374    // check whether they
    480375    if (argv[i][0] == '-') { // .. begin with -
     
    485380        //  .. and check that next letter is not numeric, if so insert
    486381      } 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]));
    488383        if (iter != ShortFormToActionMap.end()) {
    489384          (cout << Verbose(1) << "Putting " << iter->second << " for " << iter->first << " into the sequence." << endl);
     
    511406std::map <std::string, std::string> CommandLineParser::getShortFormToActionMap()
    512407{
    513   map <std::string, std::string> result;
     408  std::map <std::string, std::string> result;
    514409
    515410  ActionRegistry &AR = ActionRegistry::getInstance();
  • src/UIElements/Makefile.am

    re9be39 r3a21a7  
    134134  CommandLineUI/CommandLineDialog.cpp \
    135135  CommandLineUI/CommandLineParser.cpp \
     136  CommandLineUI/CommandLineParser_validate.cpp \
    136137  CommandLineUI/CommandLineStatusIndicator.cpp \
    137138  CommandLineUI/CommandLineUIFactory.cpp \
     
    142143  CommandLineUI/CommandLineDialog.hpp \
    143144  CommandLineUI/CommandLineParser.hpp \
     145  CommandLineUI/CommandLineParser_validate.hpp \
    144146  CommandLineUI/CommandLineStatusIndicator.hpp \
    145147  CommandLineUI/CommandLineUIFactory.hpp \
Note: See TracChangeset for help on using the changeset viewer.