Ignore:
Timestamp:
Oct 14, 2011, 3:15:30 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:
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/TremoloParser.cpp

    r9a6b76e r765f16  
    4242using namespace std;
    4343
     44// declare specialized static variables
     45const std::string FormatParserTrait<tremolo>::name = "tremolo";
     46const std::string FormatParserTrait<tremolo>::suffix = "data";
     47const ParserTypes FormatParserTrait<tremolo>::type = tremolo;
     48
    4449/**
    4550 * Constructor.
    4651 */
    47 TremoloParser::TremoloParser() {
     52FormatParser< tremolo >::FormatParser()  :
     53  FormatParser_common(NULL)
     54{
    4855  knownKeys["x"] = TremoloKey::x;
    4956  knownKeys["u"] = TremoloKey::u;
     
    8794 * Destructor.
    8895 */
    89 TremoloParser::~TremoloParser() {
    90         std::cerr << "Clearing usedFields." << std::endl;
     96FormatParser< tremolo >::~FormatParser()
     97{
     98  std::cerr << "Clearing usedFields." << std::endl;
    9199  usedFields.clear();
    92100  additionalAtomData.clear();
     
    100108 * \param tremolo file
    101109 */
    102 void TremoloParser::load(istream* file) {
     110void FormatParser< tremolo >::load(istream* file) {
    103111  string line;
    104112  string::size_type location;
     
    141149 * \param atoms atoms to store
    142150 */
    143 void TremoloParser::save(ostream* file, const std::vector<atom *> &AtomList) {
     151void FormatParser< tremolo >::save(ostream* file, const std::vector<atom *> &AtomList) {
    144152  DoLog(0) && (Log() << Verbose(0) << "Saving changes to tremolo." << std::endl);
    145153
     
    169177 * @param id of atom
    170178 */
    171 void TremoloParser::AtomInserted(atomId_t id)
     179void FormatParser< tremolo >::AtomInserted(atomId_t id)
    172180{
    173181  std::map<int, TremoloAtomInfoContainer>::iterator iter = additionalAtomData.find(id);
    174182  ASSERT(iter == additionalAtomData.end(),
    175       "TremoloParser::AtomInserted() - additionalAtomData already present for newly added atom "
     183      "FormatParser< tremolo >::AtomInserted() - additionalAtomData already present for newly added atom "
    176184      +toString(id)+".");
    177185  // don't add entry, as this gives a default resSeq of 0 not the molecule id
     
    183191 * @param id of atom
    184192 */
    185 void TremoloParser::AtomRemoved(atomId_t id)
     193void FormatParser< tremolo >::AtomRemoved(atomId_t id)
    186194{
    187195  std::map<int, TremoloAtomInfoContainer>::iterator iter = additionalAtomData.find(id);
    188196  // as we do not insert AtomData on AtomInserted, we cannot be assured of its presence
    189197//  ASSERT(iter != additionalAtomData.end(),
    190 //      "TremoloParser::AtomRemoved() - additionalAtomData is not present for atom "
     198//      "FormatParser< tremolo >::AtomRemoved() - additionalAtomData is not present for atom "
    191199//      +toString(id)+" to remove.");
    192200  if (iter != additionalAtomData.end())
     
    201209 *        but without the prexix "ATOMDATA"
    202210 */
    203 void TremoloParser::setFieldsForSave(std::string atomDataLine) {
     211void FormatParser< tremolo >::setFieldsForSave(std::string atomDataLine) {
    204212  parseAtomDataKeysLine(atomDataLine, 0);
    205213}
     
    212220 * \param reference to the atom of which information should be written
    213221 */
    214 void TremoloParser::saveLine(ostream* file, atom* currentAtom) {
    215  /* vector<string>::iterator it;*/
    216         vector<string>::iterator it = unique(usedFields.begin(), usedFields.end()); // skips all duplicates in the vector
     222void FormatParser< tremolo >::saveLine(ostream* file, atom* currentAtom) {
     223  //vector<string>::iterator it;
     224  // TODO: Is unique for FormatParser< tremolo >::usedFields still required?
     225  vector<string>::iterator it = unique(usedFields.begin(), usedFields.end()); // skips all duplicates in the vector
    217226
    218227  TremoloKey::atomDataKey currentField;
     
    308317 * \param reference to the atom of which to take the neighbor information
    309318 */
    310 void TremoloParser::writeNeighbors(ostream* file, int numberOfNeighbors, atom* currentAtom) {
     319void FormatParser< tremolo >::writeNeighbors(ostream* file, int numberOfNeighbors, atom* currentAtom) {
    311320  const BondList& ListOfBonds = currentAtom->getListOfBonds();
    312321  // sort bonded indices
     
    331340 * \param with which offset the keys begin within the line
    332341 */
    333 void TremoloParser::parseAtomDataKeysLine(string line, int offset) {
     342void FormatParser< tremolo >::parseAtomDataKeysLine(string line, int offset) {
    334343  string keyword;
    335344  stringstream lineStream;
     
    353362 *  \a atomdata_string.
    354363 *
    355  *  We just call \sa TremoloParser::parseAtomDataKeysLine() which is left
     364 *  We just call \sa  FormatParser< tremolo >::parseAtomDataKeysLine() which is left
    356365 *  private.,
    357366 *
    358367 * @param atomdata_string line to parse with space-separated values
    359368 */
    360 void TremoloParser::setAtomData(const std::string &atomdata_string)
     369void FormatParser< tremolo >::setAtomData(const std::string &atomdata_string)
    361370{
    362371  parseAtomDataKeysLine(atomdata_string, 0);
     
    371380 * \param *newmol molecule to add atom to
    372381 */
    373 void TremoloParser::readAtomDataLine(string line, molecule *newmol = NULL) {
     382void FormatParser< tremolo >::readAtomDataLine(string line, molecule *newmol = NULL) {
    374383  vector<string>::iterator it;
    375384  stringstream lineStream;
     
    389398  tokenizer tokens(line, whitespacesep);
    390399  ASSERT(tokens.begin() != tokens.end(),
    391       "TremoloParser::readAtomDataLine - empty string, need at least ' '!");
     400      "FormatParser< tremolo >::readAtomDataLine - empty string, need at least ' '!");
    392401  tokenizer::iterator tok_iter = tokens.begin();
    393402  // then associate each token to each file
     
    401410        // for the moment, assume there are always three dimensions
    402411        for (int i=0;i<NDIM;i++) {
    403           ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for x["+toString(i)+"]!");
     412          ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for x["+toString(i)+"]!");
    404413          DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
    405414          newAtom->set(i, toDouble(*tok_iter));
     
    410419        // for the moment, assume there are always three dimensions
    411420        for (int i=0;i<NDIM;i++) {
    412           ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for u["+toString(i)+"]!");
     421          ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for u["+toString(i)+"]!");
    413422          DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
    414423          tempVector[i] = toDouble(*tok_iter);
     
    419428      case TremoloKey::type :
    420429      {
    421         ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
     430        ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!");
    422431        DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
    423432        std::string element(knownTypes[(*tok_iter)]);
     
    431440      }
    432441      case TremoloKey::Id :
    433         ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
     442        ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!");
    434443        DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
    435444        atomIdMap[toInt(*tok_iter)] = newAtom->getId();
     
    438447      case TremoloKey::neighbors :
    439448        for (int i=0;i<atoi(it->substr(it->find("=") + 1, 1).c_str());i++) {
    440           ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
     449          ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!");
    441450          DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
    442451          lineStream << *tok_iter << "\t";
     
    447456        break;
    448457      default :
    449         ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
     458        ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!");
    450459        DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
    451460        atomInfo->set(currentField, *tok_iter);
     
    467476 * \param atomid world id of the atom the information belongs to
    468477 */
    469 void TremoloParser::readNeighbors(stringstream* line, int numberOfNeighbors, int atomId) {
     478void FormatParser< tremolo >::readNeighbors(stringstream* line, int numberOfNeighbors, int atomId) {
    470479  int neighborId = 0;
    471480  for (int i = 0; i < numberOfNeighbors; i++) {
     
    489498 * \return true if the field name is used
    490499 */
    491 bool TremoloParser::isUsedField(string fieldName) {
     500bool FormatParser< tremolo >::isUsedField(string fieldName) {
    492501  bool fieldNameExists = false;
    493502  for (vector<string>::iterator usedField = usedFields.begin(); usedField != usedFields.end(); usedField++) {
     
    505514 * Id found in the parsed file.
    506515 */
    507 void TremoloParser::processNeighborInformation() {
     516void FormatParser< tremolo >::processNeighborInformation() {
    508517  if (!isUsedField("neighbors")) {
    509518    return;
     
    538547 * \return input string with modified atom IDs
    539548 */
    540 string TremoloParser::adaptIdDependentDataString(string data) {
     549std::string FormatParser< tremolo >::adaptIdDependentDataString(string data) {
    541550  // there might be no IDs
    542551  if (data == "-") {
     
    563572 * as they might differ from the originally read IDs.
    564573 */
    565 void TremoloParser::adaptImprData() {
     574void FormatParser< tremolo >::adaptImprData() {
    566575  if (!isUsedField("imprData")) {
    567576    return;
     
    579588 * as they might differ from the originally read IDs.
    580589 */
    581 void TremoloParser::adaptTorsion() {
     590void FormatParser< tremolo >::adaptTorsion() {
    582591  if (!isUsedField("torsion")) {
    583592    return;
     
    594603 *
    595604 */
    596 void TremoloParser::createKnownTypesByIdentity()
     605void FormatParser< tremolo >::createKnownTypesByIdentity()
    597606{
    598607  // remove old mapping
     
    611620 * @param file input stream of .potentials file
    612621 */
    613 void TremoloParser::parseKnownTypes(std::istream &file)
     622void FormatParser< tremolo >::parseKnownTypes(std::istream &file)
    614623{
    615624  const periodentafel *periode = World::getInstance().getPeriode();
     
    632641      tokenizer tokens(line, tokensep);
    633642      ASSERT(tokens.begin() != tokens.end(),
    634           "TremoloParser::parseKnownTypes() - line with 'particle:' but no particles separated by comma.");
     643          "FormatParser< tremolo >::parseKnownTypes() - line with 'particle:' but no particles separated by comma.");
    635644      // look for particle_type
    636645      std::string particle_type("NULL");
     
    643652          tokenizer token((*tok_iter), equalitysep);
    644653          ASSERT(token.begin() != token.end(),
    645                     "TremoloParser::parseKnownTypes() - could not split particle_type by equality sign");
     654                    "FormatParser< tremolo >::parseKnownTypes() - could not split particle_type by equality sign");
    646655          tokenizer::iterator particle_iter = token.begin();
    647656          particle_iter++;
     
    652661          tokenizer token((*tok_iter), equalitysep);
    653662          ASSERT(token.begin() != token.end(),
    654                     "TremoloParser::parseKnownTypes() - could not split particle_type by equality sign");
     663                    "FormatParser< tremolo >::parseKnownTypes() - could not split particle_type by equality sign");
    655664          tokenizer::iterator element_iter = token.begin();
    656665          element_iter++;
Note: See TracChangeset for help on using the changeset viewer.