Ignore:
Timestamp:
Oct 14, 2011, 3:15:30 PM (13 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:
d3d6c6
Parents:
9a6b76e
git-author:
Frederik Heber <heber@…> (09/27/11 19:04:36)
git-committer:
Frederik Heber <heber@…> (10/14/11 15:15:30)
Message:

Huge Refactoring of FormatParserStorage and all FormatParser's.

FormatParser:

FormatParserStorage:

  • We construct all lookup tables and alikes via boost preprocessor magic from a list of all available parser (enums).
  • we use the templated getParser() and addParser() functions to serve parsers to the outside. Instances are as usual created only once.

Tests:

  • tests only had to be changed because of the "renaming" of the Parsers.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/FormatParserStorage.cpp

    r9a6b76e r765f16  
    2323#include <fstream>
    2424
    25 #include "Parser/FormatParserStorage.hpp"
    26 
     25#include <boost/preprocessor/iteration/local.hpp>
     26
     27#include "CodePatterns/Assert.hpp"
    2728#include "CodePatterns/Log.hpp"
    28 #include "CodePatterns/Verbose.hpp"
    29 
    30 #include "CodePatterns/Assert.hpp"
    3129
    3230#include "molecule.hpp"
     31#include "FormatParserStorage.hpp"
     32#include "ParserTypes.hpp"
     33
     34#include "MpqcParser.hpp"
     35#include "PcpParser.hpp"
     36#include "PdbParser.hpp"
     37#include "TremoloParser.hpp"
     38#include "XyzParser.hpp"
    3339
    3440#include "CodePatterns/Singleton_impl.hpp"
    3541
    36 template <> enum ParserTypes getPType<MpqcParser>() { return (enum ParserTypes)mpqc;  }
    37 template <> enum ParserTypes getPType<PcpParser>() { return (enum ParserTypes)pcp;  }
    38 template <> enum ParserTypes getPType<PdbParser>() { return (enum ParserTypes)pdb;  }
    39 template <> enum ParserTypes getPType<TremoloParser>() { return (enum ParserTypes)tremolo;  }
    40 template <> enum ParserTypes getPType<XyzParser>() { return (enum ParserTypes)xyz;  }
    41 
    42 /** Increment operator for the enumeration ParserTypes to allow loops.
    43  * \param &type value
    44  * \return value incremented by one
    45  */
    46 ParserTypes &operator++(ParserTypes &type)
    47 {
    48   return type = ParserTypes(type+1);
    49 }
    5042
    5143/** Constructor of class FormatParserStorage.
     
    5749  ParserPresent.resize(ParserTypes_end, false);
    5850
    59   ParserNames[mpqc] = "mpqc";
    60   ParserNames[pcp] = "pcp";
    61   ParserNames[pdb] = "pdb";
    62   ParserNames[tremolo] = "tremolo";
    63   ParserNames[xyz] = "xyz";
     51#include "ParserTypes.def"
     52
     53#define insert_print(z,n,seq,map, before, after) \
     54   map .insert( std::make_pair(  \
     55     BOOST_PP_SEQ_ELEM(n, seq) \
     56     , before < \
     57       BOOST_PP_SEQ_ELEM(n, seq) \
     58       > after \
     59     ) );
    6460 
    65   for (std::map<ParserTypes, std::string>::const_iterator it = ParserNames.begin(); it != ParserNames.end(); ++it)
    66     ParserLookupNames.insert(pair<std::string, ParserTypes>(it->second,it->first) );
    67 
    68   ParserSuffixes[mpqc] = "in";
    69   ParserSuffixes[pcp] = "conf";
    70   ParserSuffixes[pdb] = "pdb";
    71   ParserSuffixes[tremolo] = "data";
    72   ParserSuffixes[xyz] = "xyz";
    73 
    74   for (std::map<ParserTypes, std::string>::const_iterator it = ParserSuffixes.begin(); it != ParserSuffixes.end(); ++it)
    75     ParserLookupSuffixes.insert(pair<std::string, ParserTypes>(it->second,it->first) );
    76 
    77   ParserAddFunction[mpqc] = &FormatParserStorage::addParser<MpqcParser>;
    78   ParserAddFunction[pcp] = &FormatParserStorage::addParser<PcpParser>;
    79   ParserAddFunction[pdb] = &FormatParserStorage::addParser<PdbParser>;
    80   ParserAddFunction[tremolo] = &FormatParserStorage::addParser<TremoloParser>;
    81   ParserAddFunction[xyz] = &FormatParserStorage::addParser<XyzParser>;
     61#define insert_invert_print(z,n,seq,map, before, after) \
     62   map .insert( std::make_pair( before < \
     63   BOOST_PP_SEQ_ELEM(n, seq) \
     64   > after, \
     65   BOOST_PP_SEQ_ELEM(n, seq) \
     66  ) );
     67
     68  // fill ParserNames
     69#if defined ParserTypes_END // do we have parameters at all?
     70#define BOOST_PP_LOCAL_MACRO(n) insert_print(~, n, PARSERSEQUENCE, ParserNames, FormatParserTrait, ::name)
     71#define BOOST_PP_LOCAL_LIMITS  (0, ParserTypes_END-1)
     72#include BOOST_PP_LOCAL_ITERATE()
     73#endif
     74
     75  // fill ParserLookupNames
     76#if defined ParserTypes_END // do we have parameters at all?
     77#define BOOST_PP_LOCAL_MACRO(n) insert_invert_print(~, n, PARSERSEQUENCE, ParserLookupNames, FormatParserTrait, ::name)
     78#define BOOST_PP_LOCAL_LIMITS  (0, ParserTypes_END-1)
     79#include BOOST_PP_LOCAL_ITERATE()
     80#endif
     81
     82  // fill ParserSuffixes
     83#if defined ParserTypes_END // do we have parameters at all?
     84#define BOOST_PP_LOCAL_MACRO(n) insert_print(~, n, PARSERSEQUENCE, ParserSuffixes, FormatParserTrait, ::suffix)
     85#define BOOST_PP_LOCAL_LIMITS  (0, ParserTypes_END-1)
     86#include BOOST_PP_LOCAL_ITERATE()
     87#endif
     88
     89  // fill ParserLookupSuffixes
     90#if defined ParserTypes_END // do we have parameters at all?
     91#define BOOST_PP_LOCAL_MACRO(n) insert_invert_print(~, n, PARSERSEQUENCE, ParserLookupSuffixes, FormatParserTrait, ::suffix)
     92#define BOOST_PP_LOCAL_LIMITS  (0, ParserTypes_END-1)
     93#include BOOST_PP_LOCAL_ITERATE()
     94#endif
     95
     96  // fill ParserAddFunction
     97#if defined ParserTypes_END // do we have parameters at all?
     98#define BOOST_PP_LOCAL_MACRO(n) insert_print(~, n, PARSERSEQUENCE, ParserAddFunction, &FormatParserStorage::addParser, )
     99#define BOOST_PP_LOCAL_LIMITS  (0, ParserTypes_END-1)
     100#include BOOST_PP_LOCAL_ITERATE()
     101#endif
     102
     103#undef insert_print
     104#undef insert_invert_print
     105#include "ParserTypes.undef"
     106
     107  //std::cout << "ParserNames:" << std::endl << ParserNames << std::endl;
     108  //std::cout << "ParserSuffixes:" << std::endl << ParserSuffixes << std::endl;
     109  //std::cout << "ParserLookupNames:" << std::endl << ParserLookupNames << std::endl;
     110  //std::cout << "ParserLookupSuffixes:" << std::endl << ParserLookupSuffixes << std::endl;
     111  //std::cout << "ParserAddFunction:" << std::endl << ParserAddFunction << std::endl;
     112
    82113}
    83114
     
    142173  if (ptype != ParserTypes_end) {
    143174    if (ParserAddFunction.find(ptype) != ParserAddFunction.end()) {
    144       DoLog(0) && (Log() << Verbose(0) << "Adding " << ParserNames[ptype] << " type to output." << endl);
     175      LOG(0, "STATUS: Adding " << ParserNames[ptype] << " type to output.");
    145176      (getInstance().*(ParserAddFunction[ptype]))(); // we still need an object to work on ...
    146177      return true;
    147178    } else {
    148       DoeLog(1) && (eLog() << Verbose(1) << "No parser to add for this known type " << ParserNames[ptype] << ", not implemented?" << endl);
     179      ELOG(1, "No parser to add for this known type " << ParserNames[ptype] << ", not implemented?");
    149180      return false;
    150181    }
     
    156187bool FormatParserStorage::add(std::string type)
    157188{
    158   return add(getTypeFromName(type));
     189  enum ParserTypes Ptype = getTypeFromName(type);
     190  return add(Ptype);
    159191}
    160192
     
    246278 * \return reference to the output FormatParser with desired type
    247279 */
    248 FormatParser &FormatParserStorage::get(ParserTypes _type)
     280FormatParserInterface &FormatParserStorage::get(ParserTypes _type)
    249281{
    250282  if (!ParserPresent[_type]) {
Note: See TracChangeset for help on using the changeset viewer.