Changeset ab9a27


Ignore:
Timestamp:
Jul 22, 2010, 5:53:44 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:
0c9cc3
Parents:
ba7418
Message:

MapOfActions::TypeMap now contains type_info.

We are going to use the information contained in MapOfActions to split Dialog (information gathering) from the performCall (execution) of the Action.
Therefore, Dialogs will store information as string in MapOfActions' maps and the Actions will retrieve the needed information therefrom.

  • TypeMap now contains pointers to type_info
  • new TypeEnumMap mapping *type_info to enum Options
  • renamed map DefaultValue -> CurrentValue
  • new functions MapOfActions::getCurrentValue(), ...::setCurrentValue() as getter and setter of current value
  • new exception IllegalTypeException derived from CustomException, thrown when getCurrentValue is asked for value from an action/option-name with different type than stored in TypeMap.
Location:
src
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/MapOfActions.cpp

    rba7418 rab9a27  
    2020#include <iostream>
    2121
     22#include "atom.hpp"
    2223#include "CommandLineParser.hpp"
     24#include "element.hpp"
    2325#include "log.hpp"
     26#include "molecule.hpp"
    2427#include "verbose.hpp"
    2528
     
    266269
    267270  // value types for the actions
    268   TypeMap["add-atom"] = Element;
    269   TypeMap["bond-file"] = String;
    270   TypeMap["bond-table"] = String;
    271   TypeMap["boundary"] = Vector;
    272   TypeMap["center-in-box"] = Box;
    273   TypeMap["change-box"] = Box;
    274   TypeMap["change-element"] = Element;
    275   TypeMap["change-molname"] = String;
    276   TypeMap["convex-envelope"] = Molecule;
    277   TypeMap["default-molname"] = String;
    278   TypeMap["depth-first-search"] = Double;
    279   TypeMap["element-db"] = String;
    280   TypeMap["fastparsing"] = Boolean;
    281   TypeMap["fill-molecule"] = String;
    282   TypeMap["fragment-mol"] = String;
    283   TypeMap["input"] = String;
    284   TypeMap["linear-interpolate"] = String;
    285   TypeMap["molecular-volume"] = Molecule;
    286   TypeMap["nonconvex-envelope"] = Molecule;
    287   TypeMap["output"] = None;
    288   TypeMap["parse-xyz"] = String;
    289   TypeMap["pair-correlation"] = String;
    290   TypeMap["principal-axis-system"] = Molecule;
    291   TypeMap["remove-atom"] = Atom;
    292   TypeMap["remove-sphere"] = Double;
    293   TypeMap["repeat-box"] = Vector;
    294   TypeMap["rotate-to-pas"] = Molecule;
    295   TypeMap["save-adjacency"] = String;
    296   TypeMap["save-bonds"] = String;
    297   TypeMap["save-temperature"] = String;
    298   TypeMap["scale-box"] = Vector;
    299   TypeMap["set-basis"] = String;
    300   TypeMap["set-output"] = ListOfString;
    301   TypeMap["subgraph-dissect"] = None;
    302   TypeMap["suspend-in-water"] = Double;
    303   TypeMap["translate-mol"] = Vector;
    304   TypeMap["verlet-integrate"] = String;
    305   TypeMap["verbose"] = Integer;
     271  TypeMap["add-atom"] = &typeid(element);
     272  TypeMap["bond-file"] = &typeid(std::string);
     273  TypeMap["bond-table"] = &typeid(std::string);
     274  TypeMap["boundary"] = &typeid(VectorValue);
     275  TypeMap["center-in-box"] = &typeid(BoxValue);
     276  TypeMap["change-box"] = &typeid(BoxValue);
     277  TypeMap["change-element"] = &typeid(element);
     278  TypeMap["change-molname"] = &typeid(std::string);
     279  TypeMap["convex-envelope"] = &typeid(molecule);
     280  TypeMap["default-molname"] = &typeid(std::string);
     281  TypeMap["depth-first-search"] = &typeid(double);
     282  TypeMap["element-db"] = &typeid(std::string);
     283  TypeMap["fastparsing"] = &typeid(bool);
     284  TypeMap["fill-molecule"] = &typeid(std::string);
     285  TypeMap["fragment-mol"] = &typeid(std::string);
     286  TypeMap["input"] = &typeid(std::string);
     287  TypeMap["linear-interpolate"] = &typeid(std::string);
     288  TypeMap["molecular-volume"] = &typeid(molecule);
     289  TypeMap["nonconvex-envelope"] = &typeid(molecule);
     290  TypeMap["output"] = &typeid(void);
     291  TypeMap["parse-xyz"] = &typeid(std::string);
     292  TypeMap["pair-correlation"] = &typeid(std::string);
     293  TypeMap["principal-axis-system"] = &typeid(molecule);
     294  TypeMap["remove-atom"] = &typeid(atom);
     295  TypeMap["remove-sphere"] = &typeid(double);
     296  TypeMap["repeat-box"] = &typeid(VectorValue);
     297  TypeMap["rotate-to-pas"] = &typeid(molecule);
     298  TypeMap["save-adjacency"] = &typeid(std::string);
     299  TypeMap["save-bonds"] = &typeid(std::string);
     300  TypeMap["save-temperature"] = &typeid(std::string);
     301  TypeMap["scale-box"] = &typeid(VectorValue);
     302  TypeMap["set-basis"] = &typeid(std::string);
     303  TypeMap["set-output"] = &typeid(std::vector<std::string>);
     304  TypeMap["subgraph-dissect"] = &typeid(void);
     305  TypeMap["suspend-in-water"] = &typeid(double);
     306  TypeMap["translate-mol"] = &typeid(VectorValue);
     307  TypeMap["verlet-integrate"] = &typeid(std::string);
     308  TypeMap["verbose"] = &typeid(int);
    306309
    307310  // value types for the values
    308   TypeMap["atom-by-id"] = Atom;
    309   TypeMap["bin-output-file"] = String;
    310   TypeMap["bin-end"] = Double;
    311   TypeMap["bin-start"] = Double;
    312   TypeMap["bin-width"] = Double;
    313   TypeMap["convex-file"] = String;
    314   TypeMap["distance"] = Double;
    315   TypeMap["distances"] = Vector;
    316   TypeMap["DoRotate"] = Boolean;
    317   TypeMap["element"] = Element;
    318   TypeMap["elements"] = ListOfElements;
    319   TypeMap["end-step"] = Integer;
    320   TypeMap["id-mapping"] = Boolean;
    321   TypeMap["length"] = Double;
    322   TypeMap["lengths"] = Vector;
    323   TypeMap["MaxDistance"] = Double;
    324   TypeMap["molecule-by-id"] = Molecule;
    325   TypeMap["molecule-by-name"] = String;
    326   TypeMap["nonconvex-file"] = String;
    327   TypeMap["order"] = Integer;
    328   TypeMap["output-file"] = String;
    329   TypeMap["periodic"] = Boolean;
    330   TypeMap["position"] = Vector;
    331   TypeMap["sphere-radius"] = Double;
    332   TypeMap["start-step"] = Integer;
     311  TypeMap["atom-by-id"] = &typeid(atom);
     312  TypeMap["bin-output-file"] = &typeid(std::string);
     313  TypeMap["bin-end"] = &typeid(double);
     314  TypeMap["bin-start"] = &typeid(double);
     315  TypeMap["bin-width"] = &typeid(double);
     316  TypeMap["convex-file"] = &typeid(std::string);
     317  TypeMap["distance"] = &typeid(double);
     318  TypeMap["distances"] = &typeid(VectorValue);
     319  TypeMap["DoRotate"] = &typeid(bool);
     320  TypeMap["element"] = &typeid(element);
     321  TypeMap["elements"] = &typeid(std::vector<element *>);
     322  TypeMap["end-step"] = &typeid(int);
     323  TypeMap["id-mapping"] = &typeid(bool);
     324  TypeMap["length"] = &typeid(double);
     325  TypeMap["lengths"] = &typeid(VectorValue);
     326  TypeMap["MaxDistance"] = &typeid(double);
     327  TypeMap["molecule-by-id"] = &typeid(molecule);
     328  TypeMap["molecule-by-name"] = &typeid(std::string);
     329  TypeMap["nonconvex-file"] = &typeid(std::string);
     330  TypeMap["order"] = &typeid(int);
     331  TypeMap["output-file"] = &typeid(std::string);
     332  TypeMap["periodic"] = &typeid(bool);
     333  TypeMap["position"] = &typeid(VectorValue);
     334  TypeMap["sphere-radius"] = &typeid(double);
     335  TypeMap["start-step"] = &typeid(int);
     336
     337  TypeEnumMap[&typeid(int)] = Integer;
     338  TypeEnumMap[&typeid(double)] = Double;
     339  TypeEnumMap[&typeid(bool)] = Boolean;
     340  TypeEnumMap[&typeid(std::string)] = String;
     341  TypeEnumMap[&typeid(atom)] = Atom;
     342  TypeEnumMap[&typeid(element)] = Element;
     343  TypeEnumMap[&typeid(std::vector<element *>)] = ListOfElements;
     344  TypeEnumMap[&typeid(molecule)] = Molecule;
     345  TypeEnumMap[&typeid(VectorValue)] = Vector;
     346  TypeEnumMap[&typeid(BoxValue)] = Box;
     347
    333348
    334349  // default values for any action that needs one (always string!)
    335   DefaultValue["bin-width"] = "0.5";
    336   DefaultValue["fastparsing"] = "0";
    337   DefaultValue["atom-by-id"] = "-1";
    338   DefaultValue["molecule-by-id"] = "-1";
    339   DefaultValue["periodic"] = "0";
     350  CurrentValue["bin-width"] = "0.5";
     351  CurrentValue["fastparsing"] = "0";
     352  CurrentValue["atom-by-id"] = "-1";
     353  CurrentValue["molecule-by-id"] = "-1";
     354  CurrentValue["periodic"] = "0";
    340355
    341356  // put action into each menu category
     
    537552}
    538553
    539 
    540554/** Adds all options to the CommandLineParser.
    541555 *
     
    548562      if (hasValue(*OptionRunner)) {
    549563        DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " with type " << TypeMap[*OptionRunner] << " to CommandLineParser." << endl);
    550            switch((enum OptionTypes) TypeMap[*OptionRunner]) {
     564           switch(TypeEnumMap[TypeMap[*OptionRunner]]) {
    551565          default:
    552566          case None:
     
    558572            ListRunner->second->add_options()
    559573              (getKeyAndShortForm(*OptionRunner).c_str(),
    560                   DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
    561                         po::value< bool >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
     574                  CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
     575                        po::value< bool >()->default_value(atoi(CurrentValue[*OptionRunner].c_str())) :
    562576                        po::value< bool >(),
    563577                  getDescription(*OptionRunner).c_str())
     
    574588            ListRunner->second->add_options()
    575589              (getKeyAndShortForm(*OptionRunner).c_str(),
    576                   DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
    577                         po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
     590                  CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
     591                        po::value< int >()->default_value(atoi(CurrentValue[*OptionRunner].c_str())) :
    578592                        po::value< int >(),
    579593                  getDescription(*OptionRunner).c_str())
     
    590604            ListRunner->second->add_options()
    591605              (getKeyAndShortForm(*OptionRunner).c_str(),
    592                   DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
    593                         po::value< double >()->default_value(atof(DefaultValue[*OptionRunner].c_str())) :
     606                  CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
     607                        po::value< double >()->default_value(atof(CurrentValue[*OptionRunner].c_str())) :
    594608                        po::value< double >(),
    595609                  getDescription(*OptionRunner).c_str())
     
    606620            ListRunner->second->add_options()
    607621              (getKeyAndShortForm(*OptionRunner).c_str(),
    608                   DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
    609                         po::value< std::string >()->default_value(DefaultValue[*OptionRunner]) :
     622                  CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
     623                        po::value< std::string >()->default_value(CurrentValue[*OptionRunner]) :
    610624                        po::value< std::string >(),
    611625                  getDescription(*OptionRunner).c_str())
     
    622636            ListRunner->second->add_options()
    623637              (getKeyAndShortForm(*OptionRunner).c_str(),
    624                   DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
    625                         po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
     638                  CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
     639                        po::value< int >()->default_value(atoi(CurrentValue[*OptionRunner].c_str())) :
    626640                        po::value< int >(),
    627641                  getDescription(*OptionRunner).c_str())
     
    638652            ListRunner->second->add_options()
    639653              (getKeyAndShortForm(*OptionRunner).c_str(),
    640                   DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
    641                         po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
     654                  CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
     655                        po::value< int >()->default_value(atoi(CurrentValue[*OptionRunner].c_str())) :
    642656                        po::value< int >(),
    643657                  getDescription(*OptionRunner).c_str())
     
    654668            ListRunner->second->add_options()
    655669              (getKeyAndShortForm(*OptionRunner).c_str(),
    656                   DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
    657                         po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
     670                  CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
     671                        po::value< int >()->default_value(atoi(CurrentValue[*OptionRunner].c_str())) :
    658672                        po::value< int >(),
    659673                  getDescription(*OptionRunner).c_str())
     
    751765 * \return type of the action
    752766 */
    753 enum MapOfActions::OptionTypes MapOfActions::getValueType(string actionname)
    754 {
    755   return TypeMap[actionname];
     767std::string MapOfActions::getValueType(string actionname)
     768{
     769  return TypeMap[actionname]->name();
    756770}
    757771
  • src/Actions/MapOfActions.hpp

    rba7418 rab9a27  
    1414#include <map>
    1515#include <set>
     16#include <typeinfo>
    1617
    1718class MapOfActionsTest;
    1819
     20#include "Exceptions/IllegalTypeException.hpp"
    1921#include "Patterns/Singleton.hpp"
    2022
    2123namespace po = boost::program_options;
     24
     25using boost::lexical_cast;
    2226
    2327/** Central class for adding functionality to the code.
     
    136140  bool hasValue(std::string actionname);
    137141  bool isShortFormPresent(std::string shortform);
    138   enum OptionTypes getValueType(std::string actionname);
     142  std::string getValueType(std::string actionname);
    139143
    140144  std::set<std::string> generic;
     
    150154  void populateActions();
    151155
     156  template<typename T> void queryCurrentValue(const char * name, T &_T)
     157  {
     158    if (typeid( T ) == *TypeMap[name])  // constructor of type_info is private, hence can only store by ref or ptr
     159      _T = lexical_cast<T>(CurrentValue[name].c_str());
     160    else
     161      throw IllegalTypeException(__FILE__,__LINE__);
     162  }
     163
     164  template<class T> void setCurrentValue(const char * name, T &_T)
     165  {
     166    if (typeid( T ) == *TypeMap[name])  // constructor of type_info is private, hence can only store by ref or ptr
     167      CurrentValue[name] = std::string(_T);
     168    else
     169      throw IllegalTypeException(__FILE__,__LINE__);
     170  }
     171
     172
    152173private:
    153174  // private constructor and destructor
     
    159180
    160181  // map of the action names and their description
    161   std::map<std::string, std::string> DefaultValue;
     182  std::map<std::string, std::string> CurrentValue;
    162183  std::map<std::string, std::string> DescriptionMap;
    163184  std::map<std::string, std::string> ShortFormMap;
    164   std::map<std::string, enum OptionTypes > TypeMap;
     185  std::map<std::string, const std::type_info * > TypeMap;
     186  std::map<const std::type_info *, enum OptionTypes > TypeEnumMap;
    165187};
    166188
  • src/Makefile.am

    rba7418 rab9a27  
    7878
    7979EXCEPTIONSOURCE = Exceptions/CustomException.cpp \
     80                                  Exceptions/IllegalTypeException.cpp \
    8081                                  Exceptions/LinearDependenceException.cpp \
    8182                                  Exceptions/MathException.cpp \
     
    8586                                 
    8687EXCEPTIONHEADER = Exceptions/CustomException.hpp \
     88                                  Exceptions/IllegalTypeException.hpp \
    8789                                  Exceptions/LinearDependenceException.hpp \
    8890                                  Exceptions/MathException.hpp \
Note: See TracChangeset for help on using the changeset viewer.