Changeset 0b0a20


Ignore:
Timestamp:
Jul 23, 2010, 5:30:57 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:
85f35e
Parents:
dde125
Message:

Inserted all possible queries into MapOfActions.

  • MapOfActions::query/setCurrentValue(): only special classes such as atom, Box, element, molecule, Vector need a specialization of the template.
  • also added missing MissingValueException files.
Location:
src
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/MapOfActions.cpp

    rdde125 r0b0a20  
    343343  TypeMap["start-step"] = &typeid(int);
    344344
     345  TypeEnumMap[&typeid(void)] = None;
     346  TypeEnumMap[&typeid(bool)] = Boolean;
    345347  TypeEnumMap[&typeid(int)] = Integer;
     348  TypeEnumMap[&typeid(std::vector<int>)] = ListOfIntegers;
    346349  TypeEnumMap[&typeid(double)] = Double;
    347   TypeEnumMap[&typeid(bool)] = Boolean;
     350  TypeEnumMap[&typeid(std::vector<double>)] = ListOfDoubles;
    348351  TypeEnumMap[&typeid(std::string)] = String;
     352  TypeEnumMap[&typeid(std::vector<std::string>)] = ListOfStrings;
     353  TypeEnumMap[&typeid(VectorValue)] = Vector;
     354  TypeEnumMap[&typeid(BoxValue)] = Box;
     355  TypeEnumMap[&typeid(molecule)] = Molecule;
     356  TypeEnumMap[&typeid(std::vector<molecule *>)] = ListOfMolecules;
    349357  TypeEnumMap[&typeid(atom)] = Atom;
     358  TypeEnumMap[&typeid(std::vector<atom *>)] = ListOfAtoms;
    350359  TypeEnumMap[&typeid(element)] = Element;
    351360  TypeEnumMap[&typeid(std::vector<element *>)] = ListOfElements;
    352   TypeEnumMap[&typeid(molecule)] = Molecule;
    353   TypeEnumMap[&typeid(VectorValue)] = Vector;
    354   TypeEnumMap[&typeid(BoxValue)] = Box;
    355 
    356361
    357362  // default values for any action that needs one (always string!)
     
    580585}
    581586
     587void MapOfActions::queryCurrentValue(const char * name, std::vector<atom *>&_T)
     588{
     589  int atomID = -1;
     590  atom *Walker = NULL;
     591  if (typeid( std::vector<atom *> ) == *TypeMap[name]) {
     592    if (CurrentValue.find(name) == CurrentValue.end())
     593      throw MissingValueException(__FILE__, __LINE__);
     594    std::istringstream stream(CurrentValue[name]);
     595    CurrentValue.erase(name);
     596    while (!stream.fail()) {
     597      stream >> atomID;
     598      Walker = World::getInstance().getAtom(AtomById(atomID));
     599      if (Walker != NULL)
     600        _T.push_back(Walker);
     601    }
     602  } else
     603    throw IllegalTypeException(__FILE__,__LINE__);
     604}
     605
    582606void MapOfActions::queryCurrentValue(const char * name, std::vector<element *>&_T)
    583607{
     
    599623}
    600624
    601 void MapOfActions::queryCurrentValue(const char * name, std::vector<std::string>&_T)
    602 {
    603   std::string temp;
    604   if (typeid( std::vector<std::string> ) == *TypeMap[name]) {
     625void MapOfActions::queryCurrentValue(const char * name, std::vector<molecule *>&_T)
     626{
     627  int molID = -1;
     628  molecule *mol = NULL;
     629  if (typeid( std::vector<molecule *> ) == *TypeMap[name]) {
    605630    if (CurrentValue.find(name) == CurrentValue.end())
    606631      throw MissingValueException(__FILE__, __LINE__);
     
    608633    CurrentValue.erase(name);
    609634    while (!stream.fail()) {
    610       stream >> temp >> ws;
    611       _T.push_back(temp);
     635      stream >> molID;
     636      mol = World::getInstance().getMolecule(MoleculeById(molID));
     637      if (mol != NULL)
     638        _T.push_back(mol);
    612639    }
    613640  } else
     
    674701}
    675702
     703void MapOfActions::setCurrentValue(const char * name, std::vector<atom *>&_T)
     704{
     705  if (typeid( std::vector<atom *> ) == *TypeMap[name]) {
     706    std::ostringstream stream;
     707    for (std::vector<atom *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
     708      stream << (*iter)->getId() << " ";
     709    }
     710    CurrentValue[name] = stream.str();
     711  } else
     712    throw IllegalTypeException(__FILE__,__LINE__);
     713}
     714
    676715void MapOfActions::setCurrentValue(const char * name, std::vector<element *>&_T)
    677716{
     
    679718    std::ostringstream stream;
    680719    for (std::vector<element *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
    681       stream << (*iter)->Z;
     720      stream << (*iter)->Z << " ";
    682721    }
    683722    CurrentValue[name] = stream.str();
     
    686725}
    687726
    688 void MapOfActions::setCurrentValue(const char * name, std::vector<std::string>&_T)
    689 {
    690   if (typeid( std::vector<std::string> ) == *TypeMap[name]) {
     727void MapOfActions::setCurrentValue(const char * name, std::vector<molecule *>&_T)
     728{
     729  if (typeid( std::vector<molecule *> ) == *TypeMap[name]) {
    691730    std::ostringstream stream;
    692     for (std::vector<std::string>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
    693       stream << (*iter);
     731    for (std::vector<molecule *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
     732      stream << (*iter)->getId() << " ";
    694733    }
    695734    CurrentValue[name] = stream.str();
     
    765804    for (set<string>::iterator OptionRunner = ListRunner->first->begin(); OptionRunner != ListRunner->first->end(); ++OptionRunner) {
    766805      if (hasValue(*OptionRunner)) {
    767         DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " with type " << TypeMap[*OptionRunner] << " to CommandLineParser." << endl);
     806        DoLog(3) && (Log() << Verbose(3) << "Adding option " << *OptionRunner << " with type " << TypeMap[*OptionRunner]->name() << " to CommandLineParser." << endl);
    768807           switch(TypeEnumMap[TypeMap[*OptionRunner]]) {
    769808          default:
     
    798837              ;
    799838            break;
    800           case ListOfInts:
     839          case ListOfIntegers:
    801840            ListRunner->second->add_options()
    802841              (getKeyAndShortForm(*OptionRunner).c_str(),
     
    830869              ;
    831870            break;
    832           case ListOfString:
     871          case ListOfStrings:
    833872            ListRunner->second->add_options()
    834873              (getKeyAndShortForm(*OptionRunner).c_str(),
     
    837876              ;
    838877            break;
    839           case Axis:
     878          case Vector:
     879            ListRunner->second->add_options()
     880              (getKeyAndShortForm(*OptionRunner).c_str(),
     881                  po::value<VectorValue>(),
     882                  getDescription(*OptionRunner).c_str())
     883              ;
     884            break;
     885          case ListOfVectors:
     886            ListRunner->second->add_options()
     887              (getKeyAndShortForm(*OptionRunner).c_str(),
     888                  po::value< vector<VectorValue> >()->multitoken(),
     889                  getDescription(*OptionRunner).c_str())
     890              ;
     891            break;
     892          case Molecule:
    840893            ListRunner->second->add_options()
    841894              (getKeyAndShortForm(*OptionRunner).c_str(),
     
    846899              ;
    847900            break;
    848           case Vector:
    849             ListRunner->second->add_options()
    850               (getKeyAndShortForm(*OptionRunner).c_str(),
    851                   po::value<VectorValue>(),
    852                   getDescription(*OptionRunner).c_str())
    853               ;
    854             break;
    855           case Molecule:
     901          case ListOfMolecules:
     902            ListRunner->second->add_options()
     903              (getKeyAndShortForm(*OptionRunner).c_str(),
     904                  po::value< vector<int> >()->multitoken(),
     905                  getDescription(*OptionRunner).c_str())
     906              ;
     907            break;
     908          case Atom:
    856909            ListRunner->second->add_options()
    857910              (getKeyAndShortForm(*OptionRunner).c_str(),
     
    862915              ;
    863916            break;
    864           case ListOfMolecules:
    865             ListRunner->second->add_options()
    866               (getKeyAndShortForm(*OptionRunner).c_str(),
    867                   po::value< vector<int> >()->multitoken(),
    868                   getDescription(*OptionRunner).c_str())
    869               ;
    870             break;
    871           case Atom:
    872             ListRunner->second->add_options()
    873               (getKeyAndShortForm(*OptionRunner).c_str(),
    874                   CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
    875                         po::value< int >()->default_value(atoi(CurrentValue[*OptionRunner].c_str())) :
    876                         po::value< int >(),
    877                   getDescription(*OptionRunner).c_str())
    878               ;
    879             break;
    880917          case ListOfAtoms:
    881918            ListRunner->second->add_options()
     
    901938        }
    902939      } else {
    903         DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to CommandLineParser." << endl);
     940        DoLog(3) && (Log() << Verbose(3) << "Adding option " << *OptionRunner << " to CommandLineParser." << endl);
    904941        ListRunner->second->add_options()
    905942          (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
     
    910947  // add positional arguments
    911948  for (set<string>::iterator OptionRunner = inputfile.begin(); OptionRunner != inputfile.end(); ++OptionRunner) {
    912     DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to positional CommandLineParser." << endl);
     949    DoLog(3) && (Log() << Verbose(3) << "Adding option " << *OptionRunner << " to positional CommandLineParser." << endl);
    913950    CommandLineParser::getInstance().inputfile.add((*OptionRunner).c_str(), -1);
    914951  }
  • src/Actions/MapOfActions.hpp

    rdde125 r0b0a20  
    135135  friend class MapOfActionsTest;
    136136public:
    137   enum OptionTypes { None, Boolean, Integer, ListOfInts, Double, ListOfDoubles, String, ListOfString, Axis, Vector, Box, Molecule, ListOfMolecules, Atom, ListOfAtoms, Element, ListOfElements };
     137  enum OptionTypes { None, Boolean, Integer, ListOfIntegers, Double, ListOfDoubles, String, ListOfStrings, Vector, ListOfVectors, Box, Molecule, ListOfMolecules, Atom, ListOfAtoms, Element, ListOfElements };
    138138
    139139  // getter for the action descriptions and short forms
     
    167167  void queryCurrentValue(const char * name, class Box &_T);
    168168  void queryCurrentValue(const char * name, class Vector &_T);
     169  void queryCurrentValue(const char * name, std::vector<atom *>&_T);
    169170  void queryCurrentValue(const char * name, std::vector<element *>&_T);
    170   void queryCurrentValue(const char * name, std::vector<std::string>&_T);
     171  void queryCurrentValue(const char * name, std::vector<molecule *>&_T);
    171172  template<typename T> void queryCurrentValue(const char * name, T &_T)
    172173  {
     
    179180      throw IllegalTypeException(__FILE__,__LINE__);
    180181  }
     182  template<typename T> void queryCurrentValue(const char * name, std::vector<T> &_T)
     183  {
     184    T temp;
     185    if (typeid( std::vector<T> ) == *TypeMap[name]) { // constructor of type_info is private, hence can only store by ref or ptr
     186      if (CurrentValue.find(name) == CurrentValue.end())
     187        throw MissingValueException(__FILE__, __LINE__);
     188      std::istringstream stream(CurrentValue[name]);
     189      CurrentValue.erase(name);
     190      while (!stream.fail()) {
     191        stream >> temp >> std::ws;
     192        _T.push_back(temp);
     193      }
     194    } else
     195      throw IllegalTypeException(__FILE__,__LINE__);
     196  }
    181197
    182198  void setCurrentValue(const char * name, class atom * &_T);
     
    185201  void setCurrentValue(const char * name, class Box &_T);
    186202  void setCurrentValue(const char * name, class Vector &_T);
     203  void setCurrentValue(const char * name, std::vector<atom *>&_T);
    187204  void setCurrentValue(const char * name, std::vector<element *>&_T);
    188   void setCurrentValue(const char * name, std::vector<std::string>&_T);
     205  void setCurrentValue(const char * name, std::vector<molecule *>&_T);
    189206  template<class T> void setCurrentValue(const char * name, T &_T)
    190207  {
     
    192209    if (typeid( T ) == *TypeMap[name]) {  // constructor of type_info is private, hence can only store by ref or ptr
    193210      stream << _T;
     211      CurrentValue[name] = stream.str();
     212    } else
     213      throw IllegalTypeException(__FILE__,__LINE__);
     214  }
     215  template<class T> void setCurrentValue(const char * name, std::vector<T> &_T)
     216  {
     217    std::ostringstream stream;
     218    if (typeid( std::vector<T> ) == *TypeMap[name]) {  // constructor of type_info is private, hence can only store by ref or ptr
     219      std::ostringstream stream;
     220      for (std::vector<std::string>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
     221        stream << (*iter) << " ";
     222      }
    194223      CurrentValue[name] = stream.str();
    195224    } else
Note: See TracChangeset for help on using the changeset viewer.