Ignore:
Timestamp:
Jun 11, 2015, 11:21:41 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:
043598
Parents:
dd6c07
git-author:
Frederik Heber <heber@…> (05/17/15 04:22:43)
git-committer:
Frederik Heber <heber@…> (06/11/15 23:21:41)
Message:

Added ParameterPair (i.e. "key = value;") to allow other string output.

  • this will solve the problem of vectors of key-value-pairs not properly converted into a single string because of missing semicolon.
  • FIX: toCLIString used functions toPythonString if possible.
Location:
src/UIElements/CommandLineUI
Files:
2 added
8 edited

Legend:

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

    rdd6c07 r33e801  
    136136}
    137137
     138void CommandLineDialog::queryKeyValuePair(Parameter<KeyValuePair> &param, const std::string title, const std::string description)
     139{
     140  registerQuery(new KeyValuePairCommandLineQuery(param, title,description));
     141}
     142
     143void CommandLineDialog::queryKeyValuePairs(Parameter< std::vector<KeyValuePair> > &param, const std::string title, const std::string description)
     144{
     145  registerQuery(new KeyValuePairsCommandLineQuery(param, title,description));
     146}
     147
    138148/************************** Query Infrastructure ************************/
    139149/*       ---> shifted to folder Query                                   */
  • src/UIElements/CommandLineUI/CommandLineDialog.hpp

    rdd6c07 r33e801  
    5454  virtual void queryFile(Parameter<boost::filesystem::path> &, const std::string ="", const std::string = "");
    5555  virtual void queryFiles(Parameter<std::vector< boost::filesystem::path> > &, const std::string ="", const std::string = "");
     56  virtual void queryKeyValuePair(Parameter<KeyValuePair> &, const std::string ="", const std::string = "");
     57  virtual void queryKeyValuePairs(Parameter< std::vector<KeyValuePair> > &, const std::string ="", const std::string = "");
     58
    5659  // specialized stuff for command line queries
    5760  // all placed into Query/CommandLineQuery.hpp
    5861  // !please adhere to alphabetical ordering!
     62
    5963  class AtomCommandLineQuery;
    6064  class AtomsCommandLineQuery;
     
    6973  class IntCommandLineQuery;
    7074  class IntsCommandLineQuery;
     75  class KeyValuePairCommandLineQuery;
     76  class KeyValuePairsCommandLineQuery;
    7177  class MoleculeCommandLineQuery;
    7278  class MoleculesCommandLineQuery;
  • src/UIElements/CommandLineUI/CommandLineParser.cpp

    rdd6c07 r33e801  
    5252#include "CommandLineParser.hpp"
    5353#include "CommandLineParser_validate.hpp"
     54#include "Parameters/Specifics/KeyValuePair.hpp"
    5455#include "World.hpp"
    5556
     
    408409//                  po::value < RealSpaceMatrixValue >()->default_value(boost::lexical_cast<BoxValue>(currentOption->getDefaultValue().c_str())) :
    409410                  po::value < RealSpaceMatrixValue >(),
     411                  currentOption->getDescription().c_str())
     412        ;
     413      break;
     414    case TypeEnumContainer::KeyValueType:
     415      OptionList->add_options()
     416        (currentOption->getKeyAndShortForm().c_str(),
     417            currentOption->hasDefaultValue() ?
     418                  (_DefaultAsImplicit ?
     419                      po::value < KeyValuePair >()->implicit_value(boost::lexical_cast< KeyValuePair >(currentOption->getDefaultValue().c_str())) :
     420                      po::value < KeyValuePair >()->default_value(boost::lexical_cast< KeyValuePair >(currentOption->getDefaultValue().c_str()))) :
     421                  po::value < KeyValuePair >(),
     422                  currentOption->getDescription().c_str())
     423        ;
     424      break;
     425    case TypeEnumContainer::ListOfKeyValuesType:
     426      OptionList->add_options()
     427        (currentOption->getKeyAndShortForm().c_str(),
     428//            currentOption->hasDefaultValue() ?
     429//                  po::value < std::vector<KeyValuePair> >()->default_value(boost::lexical_cast< std::vector<KeyValuePair> >(currentOption->getDefaultValue().c_str())) :
     430                  po::value < std::vector<KeyValuePair> >()->multitoken(),
    410431                  currentOption->getDescription().c_str())
    411432        ;
  • src/UIElements/CommandLineUI/CommandLineParser_validate.cpp

    rdd6c07 r33e801  
    4242#include "Actions/Values.hpp"
    4343#include "CommandLineParser_validate.hpp"
     44#include "Parameters/Specifics/KeyValuePair.hpp"
    4445
    4546/** boost::program_options validator specialization for VectorValue.
     
    157158void validate(boost::any& v, const std::vector<std::string>& values, boost::filesystem::path *, int)
    158159{
    159   boost::filesystem::path filename;
    160 
    161   std::cerr << "boost::filesystem::path validator used." << std::endl;
     160//  std::cerr << "boost::filesystem::path validator used." << std::endl;
     161
     162  // Make sure no previous assignment to 'a' was made.
     163  boost::program_options::validators::check_first_occurrence(v);
     164  // Extract the first string from 'values'. If there is more than
     165  // one string, it's an error, and exception will be thrown.
     166  const std::string& s = boost::program_options::validators::get_single_string(values);
     167
     168  v = boost::any(boost::filesystem::path(s));
     169}
     170
     171/** boost::program_options validator specialization for boost::filesystem::path.
     172 * \param &v  reference for return value
     173 * \param &values string vector of scanned options
     174 * \param *
     175 * \param
     176 *
     177 */
     178void validate(boost::any& v, const std::vector<std::string>& values, KeyValuePair *, int)
     179{
     180//  std::cerr << "KeyValuePair validator used." << std::endl;
     181
     182  // Make sure no previous assignment to 'a' was made.
     183  boost::program_options::validators::check_first_occurrence(v);
     184  // Extract the first string from 'values'. If there is more than
     185  // one string, it's an error, and exception will be thrown.
     186  const std::string& s = boost::program_options::validators::get_single_string(values);
     187
     188  if (s.find("=") == std::string::npos) {
     189#if BOOST_VERSION < 104200
     190    throw boost::program_options::validation_error("Invalid KeyValue given");
     191#else
     192throw boost::program_options::validation_error(
     193    boost::program_options::validation_error::invalid_option_value,
     194    std::string("value"),
     195    std::string("vector<KeyValuePair>")
     196    );
     197#endif
     198  }
     199  v = boost::any(KeyValuePair(s));
     200}
     201
     202/** boost::program_options validator specialization for boost::filesystem::path.
     203 * \param &v  reference for return value
     204 * \param &values string vector of scanned options
     205 * \param *
     206 * \param
     207 *
     208 */
     209void validate(boost::any& v, const std::vector<std::string>& values, std::vector<KeyValuePair> *, int)
     210{
     211//  std::cerr << "vector<KeyValuePair> validator used." << std::endl;
    162212
    163213  // split comma-separated values
    164   if (values.size() != 1) {
    165     std::cerr <<  "Not one file but " << values.size() << " given " << std::endl;
     214  if (values.size() > 1) {
    166215#if BOOST_VERSION < 104200
    167216    throw boost::program_options::validation_error("Unequal to one file given");
     
    171220          boost::program_options::validation_error::at_least_one_value_required,
    172221          std::string("value"),
    173           std::string("boost::filesystem::path")
    174       );
    175     } else {
    176       throw boost::program_options::validation_error(
    177           boost::program_options::validation_error::multiple_values_not_allowed,
    178           std::string("value"),
    179           std::string("boost::filesystem::path")
     222          std::string("vector<KeyValuePair>")
    180223      );
    181224    }
    182225#endif
    183   }
    184   filename = values.at(0);
    185   v = boost::any(boost::filesystem::path(filename));
    186 }
    187 
     226    for (std::vector<std::string>::const_iterator iter = values.begin();
     227        iter != values.end();++iter)
     228      if ((*iter).find("=") == std::string::npos) {
     229#if BOOST_VERSION < 104200
     230    throw boost::program_options::validation_error("Invalid KeyValue given");
     231#else
     232    throw boost::program_options::validation_error(
     233        boost::program_options::validation_error::invalid_option_value,
     234        std::string("value"),
     235        std::string("vector<KeyValuePair>")
     236    );
     237#endif
     238      }
     239  }
     240  std::vector<KeyValuePair> temp;
     241  for (std::vector<std::string>::const_iterator iter = values.begin();
     242      iter != values.end();++iter)
     243    temp.push_back(KeyValuePair(*iter));
     244  v = boost::any(temp);
     245}
  • src/UIElements/CommandLineUI/CommandLineParser_validate.hpp

    rdd6c07 r33e801  
    2222#include <boost/lexical_cast.hpp>
    2323
     24struct KeyValuePair;
    2425class RealSpaceMatrixValue;
    2526class VectorValue;
    2627
     28void validate(boost::any& v, const std::vector<std::string>& values, KeyValuePair *, int);
     29void validate(boost::any& v, const std::vector<std::string>& values, std::vector<KeyValuePair> *, int);
    2730void validate(boost::any& v, const std::vector<std::string>& values, VectorValue *, int);
    2831void validate(boost::any& v, const std::vector<std::string>& values, RealSpaceMatrixValue *, int);
  • src/UIElements/CommandLineUI/Query/CommandLineQuery.hpp

    rdd6c07 r33e801  
    164164};
    165165
     166class CommandLineDialog::KeyValuePairCommandLineQuery : public Dialog::TQuery<KeyValuePair> {
     167public:
     168  KeyValuePairCommandLineQuery(Parameter<KeyValuePair> &_param, const std::string &_title, const std::string &_description = "");
     169  virtual ~KeyValuePairCommandLineQuery();
     170  virtual bool handle();
     171};
     172
     173class CommandLineDialog::KeyValuePairsCommandLineQuery : public Dialog::TQuery<std::vector<KeyValuePair> > {
     174public:
     175  KeyValuePairsCommandLineQuery(Parameter<std::vector<KeyValuePair> > &_param, const std::string &_title, const std::string &_description = "");
     176  virtual ~KeyValuePairsCommandLineQuery();
     177  virtual bool handle();
     178};
     179
    166180#endif /* COMMANDLINEQUERY_HPP_ */
  • src/UIElements/CommandLineUI/TypeEnumContainer.cpp

    rdd6c07 r33e801  
    5151#include "Element/element.hpp"
    5252#include "molecule.hpp"
     53#include "Parameters/Specifics/KeyValuePair.hpp"
    5354#include "RandomNumbers/RandomNumberDistribution_Parameters.hpp"
    5455
     
    8182  TypeEnumMap[&typeid(const element *)] = ElementType;
    8283  TypeEnumMap[&typeid(std::vector<const element *>)] = ListOfElementsType;
     84  TypeEnumMap[&typeid(KeyValuePair)] = KeyValueType;
     85  TypeEnumMap[&typeid(std::vector<KeyValuePair>)] = ListOfKeyValuesType;
    8386
    8487  // for debugging: list all stored types
  • src/UIElements/CommandLineUI/TypeEnumContainer.hpp

    rdd6c07 r33e801  
    4646        ElementType,
    4747        ListOfElementsType,
    48         RealSpaceMatrixType
     48        RealSpaceMatrixType,
     49        KeyValueType,
     50        ListOfKeyValuesType
    4951  };
    5052
Note: See TracChangeset for help on using the changeset viewer.