Ignore:
Timestamp:
Oct 10, 2011, 2:27:06 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, Candidate_v1.7.0, 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:
4151b0
Parents:
e611dc
git-author:
Frederik Heber <heber@…> (09/06/11 08:45:22)
git-committer:
Frederik Heber <heber@…> (10/10/11 14:27:06)
Message:

Abstracted FormatParser_Parameters and made it "Clone"able.

  • this is preparatory for having an undoable LoadAction.
  • is so far only used by MpqcParser_Parameters.
  • FormatParser_Parameters::clone() clones the instance (uses CodePattern's Clone pattern).
  • FormatParser has pointer to FormatParser_Parameters.
  • MpqcParser now has parameters as inheritance from FormatParser, allocates in cstor, removes in dstor.
  • new function MpqcParser_Parameters::makeClone() sets instance to be a copy of the given one.
  • MpqcParser: replaced direct access to params by getParams().
  • added ParameterCloneTest to ParserMpqcUnitTest.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/MpqcParser_Parameters.cpp

    re611dc rc1db05  
    3535
    3636MpqcParser_Parameters::MpqcParser_Parameters()
     37{
     38  Init();
     39}
     40
     41void MpqcParser_Parameters::Init()
    3742{
    3843  // add all known basis
     
    106111
    107112  initParameters();
     113}
     114
     115MpqcParser_Parameters::MpqcParser_Parameters(const MpqcParser_Parameters & state)
     116{
     117  // init
     118  Init();
     119
     120  // copy values
     121  copyParameters(state);
     122}
     123
     124void MpqcParser_Parameters::copyParameters(const MpqcParser_Parameters & state)
     125{
     126  appendParameter(hessianParam, state.getBool(hessianParam));
     127  appendParameter(savestateParam, state.getBool(savestateParam));
     128  appendParameter(do_gradientParam, state.getBool(do_gradientParam));
     129  appendParameter(maxiterParam, state.getInt(maxiterParam));
     130  appendParameter(memoryParam, state.getInt(memoryParam));
     131  appendParameter(stdapproxParam, state.getString(stdapproxParam));
     132  appendParameter(nfzcParam, state.getInt(nfzcParam));
     133  appendParameter(basisParam, state.getString(basisParam));
     134  appendParameter(aux_basisParam, state.getString(aux_basisParam));
     135  appendParameter(integrationParam, state.getIntegration());
     136  appendParameter(theoryParam, state.getTheory());
     137}
     138
     139FormatParser_Parameters* MpqcParser_Parameters::clone() const
     140{
     141  //LOG(3, "Cloning parameters.");
     142  MpqcParser_Parameters *instance = new MpqcParser_Parameters(*this);
     143  return instance;
     144}
     145
     146void MpqcParser_Parameters::makeClone(const FormatParser_Parameters & _state)
     147{
     148  //LOG(3, "Cloning parameters from other instance.");
     149  copyParameters(static_cast<const MpqcParser_Parameters &>(_state));
    108150}
    109151
     
    279321}
    280322
    281 enum MpqcParser_Parameters::Parameters MpqcParser_Parameters::getParam(std::string _name)
    282 {
    283   return ParamLookup[_name];
    284 }
    285 
    286 enum MpqcParser_Parameters::IntegrationMethod MpqcParser_Parameters::getIntegration()
    287 {
     323enum MpqcParser_Parameters::Parameters MpqcParser_Parameters::getParam(std::string _name) const
     324{
     325  ParamLookupType::const_iterator iter = ParamLookup.find(_name);
     326  return iter->second;
     327}
     328
     329enum MpqcParser_Parameters::IntegrationMethod MpqcParser_Parameters::getIntegration() const
     330{
     331  parameterlist::const_iterator iter = params.find(integrationParam);
    288332  enum IntegrationMethod value;
    289333  // TODO: throw exception instead of eLog()
    290334//  try {
    291     value = boost::any_cast<enum IntegrationMethod>(params[integrationParam]);
     335    value = boost::any_cast<enum IntegrationMethod>(iter->second);
    292336//  } catch(const boost::bad_any_cast &) {
    293337//    DoeLog(0) && (eLog() << Verbose(0)
     
    298342}
    299343
    300 enum MpqcParser_Parameters::Theory MpqcParser_Parameters::getTheory()
    301 {
     344enum MpqcParser_Parameters::Theory MpqcParser_Parameters::getTheory() const
     345{
     346  parameterlist::const_iterator iter = params.find(theoryParam);
    302347  enum Theory value;
    303348  // TODO: throw exception instead of eLog()
    304349//  try {
    305     value = boost::any_cast<enum Theory>(params[theoryParam]);
     350    value = boost::any_cast<enum Theory>(iter->second);
    306351//  } catch(const boost::bad_any_cast &) {
    307352//    DoeLog(0) && (eLog() << Verbose(0)
     
    312357}
    313358
    314 std::string MpqcParser_Parameters::getString(enum Parameters _param)
     359std::string MpqcParser_Parameters::getString(enum Parameters _param) const
    315360{
    316361  std::string value;
     
    318363  enum Theory Tindex;
    319364  bool test;
     365  parameterlist::const_iterator iter = params.find(_param);
    320366  switch (_param) {
    321367    case hessianParam:
    322368    case savestateParam:
    323369    case do_gradientParam:
    324       test = boost::any_cast<bool>(params[_param]);
     370      test = boost::any_cast<bool>(iter->second);
    325371      if (test)
    326372        value = "yes";
     
    331377      // TODO: throw exception instead of eLog()
    332378//      try {
    333         Iindex = boost::any_cast<enum IntegrationMethod>(params[_param]);
     379        Iindex = boost::any_cast<enum IntegrationMethod>(iter->second);
    334380//      } catch(const boost::bad_any_cast &) {
    335381//        DoeLog(0) && (eLog() << Verbose(0)
     
    337383//            +ParamNames[_param]+" to string!" << std::endl);
    338384//      }
    339       value = IntegrationNames[Iindex];
     385      {
     386        IntegrationNamesType::const_iterator Iiter = IntegrationNames.find(Iindex);
     387        value = Iiter->second;
     388      }
    340389      break;
    341390    case theoryParam:
    342391      // TODO: throw exception instead of eLog()
    343392//      try {
    344         Tindex = boost::any_cast<enum Theory>(params[_param]);
     393        Tindex = boost::any_cast<enum Theory>(iter->second);
    345394//      } catch(const boost::bad_any_cast &) {
    346395//        DoeLog(0) && (eLog() << Verbose(0)
     
    348397//            +ParamNames[_param]+" to string!" << std::endl);
    349398//      }
    350       value = TheoryNames[(enum Theory)Tindex];
     399        {
     400          TheoryNamesType::const_iterator Titer = TheoryNames.find(Tindex);
     401          value = Titer->second;
     402        }
    351403      break;
    352404    default:
    353405      // TODO: throw exception instead of eLog()
    354406//      try {
    355         value = boost::any_cast<std::string>(params[_param]);
     407        value = boost::any_cast<std::string>(iter->second);
    356408//      } catch(const boost::bad_any_cast &) {
    357409//        DoeLog(0) && (eLog() << Verbose(0)
     
    365417}
    366418
    367 int MpqcParser_Parameters::getInt(enum Parameters _param)
     419int MpqcParser_Parameters::getInt(enum Parameters _param) const
    368420{
    369421  int value;
     422  parameterlist::const_iterator iter = params.find(_param);
    370423  switch (_param) {
    371424    default:
    372425      // TODO: throw exception instead of eLog()
    373426//      try {
    374         value = boost::any_cast<int>(params[_param]);
     427        value = boost::any_cast<int>(iter->second);
    375428//      } catch(const boost::bad_any_cast &) {
    376429//        DoeLog(0) && (eLog() << Verbose(0)
     
    383436}
    384437
    385 double MpqcParser_Parameters::getDouble(enum Parameters _param)
     438double MpqcParser_Parameters::getDouble(enum Parameters _param) const
    386439{
    387440  double value;
    388   // TODO: throw exception instead of eLog()
    389 //  try {
    390     value = boost::any_cast<double>(params[_param]);
     441  parameterlist::const_iterator iter = params.find(_param);
     442  // TODO: throw exception instead of eLog()
     443//  try {
     444    value = boost::any_cast<double>(iter->second);
    391445//  } catch(const boost::bad_any_cast &) {
    392446//    DoeLog(0) && (eLog() << Verbose(0)
     
    397451}
    398452
    399 bool MpqcParser_Parameters::getBool(enum Parameters _param)
     453bool MpqcParser_Parameters::getBool(enum Parameters _param) const
    400454{
    401455  bool value;
    402   // TODO: throw exception instead of eLog()
    403 //  try {
    404     value = boost::any_cast<bool>(params[_param]);
     456  parameterlist::const_iterator iter = params.find(_param);
     457  // TODO: throw exception instead of eLog()
     458//  try {
     459    value = boost::any_cast<bool>(iter->second);
    405460//  } catch(const boost::bad_any_cast &) {
    406461//    DoeLog(0) && (eLog() << Verbose(0)
Note: See TracChangeset for help on using the changeset viewer.