Changeset 5c6946


Ignore:
Timestamp:
Aug 28, 2010, 12:57:56 AM (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:
bb6193
Parents:
3ae731
git-author:
Frederik Heber <heber@…> (08/27/10 10:25:55)
git-committer:
Frederik Heber <heber@…> (08/28/10 00:57:56)
Message:

FormatParserStorage extended a bit.

  • new functions add(type) that accept either parser name or ParserTypes and adds the respective class.
  • new function getType(type) that accepts a parser name and returns the type.
Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/WorldAction/SetOutputFormatsAction.cpp

    r3ae731 r5c6946  
    4242
    4343  for (vector<std::string>::iterator iter = params.FormatList.begin(); iter != params.FormatList.end(); ++iter) {
    44     if (*iter == "mpqc") {
    45       FormatParserStorage::getInstance().addMpqc();
    46       DoLog(0) && (Log() << Verbose(0) << "Adding mpqc type to output." << endl);
    47     } else if (*iter == "pcp") {
    48       FormatParserStorage::getInstance().addPcp();
    49       DoLog(0) && (Log() << Verbose(0) << "Adding pcp type to output." << endl);
    50     } else if (*iter == "tremolo") {
    51       FormatParserStorage::getInstance().addTremolo();
    52       DoLog(0) && (Log() << Verbose(0) << "Adding tremolo type to output." << endl);
    53     } else if (*iter == "xyz") {
    54       FormatParserStorage::getInstance().addXyz();
    55       DoLog(0) && (Log() << Verbose(0) << "Adding xyz type to output." << endl);
    56     } else {
    57       DoeLog(1) && (eLog() << Verbose(1) << "Unknown format:" << *iter << endl);
     44    if (!FormatParserStorage::getInstance().add(*iter)) {
     45      DoeLog(1) && (eLog() << Verbose(1) << "Unknown parser format in WorldSetOutputFormatsAction:" << *iter << endl);
    5846    }
    5947  }
  • src/Parser/FormatParserStorage.cpp

    r3ae731 r5c6946  
    5656  ParserSuffix.resize(ParserTypes_end, "");
    5757
     58  ParserNames[mpqc] = "mpqc";
     59  ParserNames[pcp] = "pcp";
     60  ParserNames[tremolo] = "tremolo";
     61  ParserNames[xyz] = "xyz";
     62
     63  for (std::map<ParserTypes, std::string>::const_iterator it = ParserNames.begin(); it != ParserNames.end(); ++it)
     64    ParserLookupNames.insert(pair<std::string, ParserTypes>(it->second,it->first) );
     65
    5866  ParserSuffix[mpqc] = "in";
    5967  ParserSuffix[pcp] = "conf";
    6068  ParserSuffix[tremolo] = "data";
    6169  ParserSuffix[xyz] = "xyz";
     70
     71  ParserAddFunction[mpqc] = &FormatParserStorage::addMpqc;
     72  ParserAddFunction[pcp] = &FormatParserStorage::addPcp;
     73  ParserAddFunction[tremolo] = &FormatParserStorage::addTremolo;
     74  ParserAddFunction[xyz] = &FormatParserStorage::addXyz;
    6275}
    6376
     
    112125}
    113126
     127
    114128/** Adds an PcpParser to the storage.
    115129 */
     
    146160    DoeLog(1) && (eLog() << Verbose(1) << "Parser xyz is already present." << endl);
    147161}
     162
     163ParserTypes FormatParserStorage::getType(std::string type)
     164{
     165  if (ParserLookupNames.find(type) == ParserLookupNames.end()) {
     166    DoeLog(1) && (eLog() << Verbose(1) << "Unknown type " << type << "." << endl);
     167    return ParserTypes_end;
     168  } else
     169    return ParserLookupNames[type];
     170}
     171
     172bool FormatParserStorage::add(ParserTypes ptype)
     173{
     174  if (ptype != ParserTypes_end) {
     175    if (ParserAddFunction.find(ptype) != ParserAddFunction.end()) {
     176      DoLog(0) && (Log() << Verbose(0) << "Adding " << ParserNames[ptype] << " type to output." << endl);
     177      (getInstance().*(ParserAddFunction[ptype]))(); // we still need an object to work on ...
     178      return true;
     179    } else {
     180      DoeLog(1) && (eLog() << Verbose(1) << "No parser to add for this known type " << ParserNames[ptype] << ", not implemented?" << endl);
     181      return false;
     182    }
     183  } else {
     184    return false;
     185  }
     186}
     187
     188bool FormatParserStorage::add(std::string type)
     189{
     190  return add(getType(type));
     191}
     192
    148193
    149194/** Parses an istream depending on its suffix
     
    163208    getXyz().load(&input);
    164209  } else {
    165     DoeLog(1) && (eLog() << Verbose(1) << "Unknown suffix to for FormatParserStorage::get()." << endl);
     210    DoeLog(1) && (eLog() << Verbose(1) << "Unknown suffix " << suffix << " to for FormatParserStorage::get()." << endl);
    166211    return false;
    167212  }
  • src/Parser/FormatParserStorage.hpp

    r3ae731 r5c6946  
    1717
    1818#include <string>
     19#include <map>
    1920#include <vector>
    2021
     
    3536public:
    3637
    37 
    3838  void addMpqc();
    3939  void addPcp();
    4040  void addTremolo();
    4141  void addXyz();
     42  bool add(std::string type);
     43  bool add(ParserTypes type);
    4244
    4345  bool get(std::istream &input, std::string suffix);
     
    4648  TremoloParser &getTremolo();
    4749  XyzParser &getXyz();
     50
     51  ParserTypes getType(std::string type);
    4852
    4953  void SetOutputPrefixForAll(std::string &_prefix);
     
    6771  std::vector<std::string> ParserSuffix;
    6872
     73  // function pointers to each add...()
     74  std::map< ParserTypes, void (FormatParserStorage::*)() > ParserAddFunction;
     75
     76  // type name of each parser type and reverse lookup
     77  std::map<ParserTypes, std::string> ParserNames;
     78  std::map<std::string, ParserTypes> ParserLookupNames;
     79
     80
    6981  // prefix of the filenames to use on save
    7082  std::string prefix;
Note: See TracChangeset for help on using the changeset viewer.