Changeset 765f16 for src


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.
Location:
src
Files:
8 added
33 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/Actions/MoleculeAction/FillVoidWithMoleculeAction.cpp

    r9a6b76e r765f16  
    2828#include "Descriptors/MoleculeOrderDescriptor.hpp"
    2929#include "molecule.hpp"
     30#include "Parser/FormatParserInterface.hpp"
    3031#include "Parser/FormatParserStorage.hpp"
    3132#include "World.hpp"
     
    6768  input.open(params.fillername.string().c_str());
    6869  ParserTypes type = FormatParserStorage::getInstance().getTypeFromSuffix(FilenameSuffix);
    69   FormatParser &parser = FormatParserStorage::getInstance().get(type);
     70  FormatParserInterface &parser = FormatParserStorage::getInstance().get(type);
    7071  parser.load(&input);
    7172
  • src/Actions/MoleculeAction/FillWithMoleculeAction.cpp

    r9a6b76e r765f16  
    2828#include "Descriptors/MoleculeOrderDescriptor.hpp"
    2929#include "molecule.hpp"
     30#include "Parser/FormatParserInterface.hpp"
    3031#include "Parser/FormatParserStorage.hpp"
    3132#include "World.hpp"
     
    6162  input.open(params.fillername.string().c_str());
    6263  ParserTypes type = FormatParserStorage::getInstance().getTypeFromSuffix(FilenameSuffix);
    63   FormatParser &parser = FormatParserStorage::getInstance().get(type);
     64  FormatParserInterface &parser = FormatParserStorage::getInstance().get(type);
    6465  parser.load(&input);
    6566
  • src/Actions/MoleculeAction/LoadAction.cpp

    r9a6b76e r765f16  
    2323#include "CodePatterns/Verbose.hpp"
    2424#include "Descriptors/MoleculeIdDescriptor.hpp"
     25#include "Parser/FormatParserInterface.hpp"
    2526#include "Parser/FormatParserStorage.hpp"
    2627#include "Parser/FormatParser_Parameters.hpp"
  • src/Actions/ParserAction/ParseTremoloPotentialsAction.cpp

    r9a6b76e r765f16  
    4343
    4444  boost::filesystem::ifstream test;
    45   TremoloParser &tremolo = FormatParserStorage::getInstance().getParser<TremoloParser>();
     45  FormatParser<tremolo> &parser = FormatParserStorage::getInstance().getParser<tremolo>();
    4646  // parsing file if present
    4747  if (!boost::filesystem::exists(params.filename)) {
    4848    DoLog(1) && (Log() << Verbose(1) << "Specified potentials file " << params.filename << " not found." << endl);
    4949    // DONT FAIL: it's just empty we re-create default id-mapping
    50     tremolo.createKnownTypesByIdentity();
     50    parser.createKnownTypesByIdentity();
    5151
    5252  } else {
     
    5555    // parse the file
    5656    test.open(params.filename);
    57     TremoloParser &tremolo = FormatParserStorage::getInstance().getParser<TremoloParser>();
    58     tremolo.parseKnownTypes(test);
     57    parser.parseKnownTypes(test);
    5958    test.close();
    6059  }
  • src/Actions/ParserAction/SetMpqcParametersAction.cpp

    r9a6b76e r765f16  
    3838/** =========== define the function ====================== */
    3939Action::state_ptr ParserSetMpqcParametersAction::performCall() {
    40   MpqcParser_Parameters &mpqc = FormatParserStorage::getInstance().getParser<MpqcParser>().getParams();
     40  MpqcParser_Parameters &parser = FormatParserStorage::getInstance().getParser<mpqc>().getParams();
    4141
    4242  std::stringstream oldparamstream;
    43   oldparamstream << mpqc;
     43  oldparamstream << parser;
    4444  // obtain information
    4545  getParametersfromValueStorage();
    4646  std::stringstream newparamstream(params.newparams);
    47   newparamstream >> mpqc;
     47  newparamstream >> parser;
    4848
    4949  return Action::state_ptr(new ParserSetMpqcParametersState(oldparamstream.str(), params));
     
    5353  ParserSetMpqcParametersState *state = assert_cast<ParserSetMpqcParametersState*>(_state.get());
    5454
    55   MpqcParser_Parameters &mpqc = FormatParserStorage::getInstance().getParser<MpqcParser>().getParams();
     55  MpqcParser_Parameters &parser = FormatParserStorage::getInstance().getParser<mpqc>().getParams();
    5656  std::stringstream oldparamstream(state->oldparams);
    57   oldparamstream >> mpqc;
     57  oldparamstream >> parser;
    5858
    5959  return Action::state_ptr(_state);
     
    6363  ParserSetMpqcParametersState *state = assert_cast<ParserSetMpqcParametersState*>(_state.get());
    6464
    65   MpqcParser_Parameters &mpqc = FormatParserStorage::getInstance().getParser<MpqcParser>().getParams();
     65  MpqcParser_Parameters &parser = FormatParserStorage::getInstance().getParser<mpqc>().getParams();
    6666  std::stringstream newparamstream(state->params.newparams);
    67   newparamstream >> mpqc;
     67  newparamstream >> parser;
    6868
    6969  return Action::state_ptr(_state);
  • src/Actions/ParserAction/SetTremoloAtomdataAction.cpp

    r9a6b76e r765f16  
    4242  getParametersfromValueStorage();
    4343
    44   TremoloParser &tremolo = FormatParserStorage::getInstance().getParser<TremoloParser>();
     44  FormatParser<tremolo> &parser = FormatParserStorage::getInstance().getParser<tremolo>();
    4545
    4646  DoLog(1) && (Log() << Verbose(1) << "Setting Tremolo's ATOMDATA to: '" << params.atomdata_string << "'" << std::endl);
    4747
    48   tremolo.setAtomData(params.atomdata_string);
     48  parser.setAtomData(params.atomdata_string);
    4949
    5050  return Action::success;
  • src/Parser/FormatParser.hpp

    r9a6b76e r765f16  
    1414#endif
    1515
     16#include <iosfwd>
     17#include <string>
     18#include <vector>
    1619
    17 #include "CodePatterns/Observer.hpp"
    18 #include "ChangeTracker.hpp"
    19 #include "FormatParser_Parameters.hpp"
    20 #include "parser.hpp"
     20#include "CodePatterns/Assert.hpp"
    2121
    22 namespace MoleCuilder {
    23   class MoleculeLoadAction;
    24 }
     22#include "FormatParserTrait.hpp"
     23#include "FormatParserInterface.hpp"
     24#include "FormatParser_common.hpp"
     25#include "ParserTypes.hpp"
    2526
    2627class atom;
    2728
    2829/**
     30 * @file
     31 * <H1> FormatParser Howto </H1>
     32 *
     33 * <H2> Introduction </H2>
     34 *
     35 * FormatParsers parse external streams (files) and bring their information
     36 * into the World. That is they implement load and save functions that work
     37 * on a specific vector atoms.
     38 *
     39 * <H2> Building your own Parsers </H2>
     40 *
     41 * Building Parsers is easy. All you have to do is the following:
     42 * -# add a new parser type to the file ParserTypes.def.
     43 * -# add a new template specialization of FormatParser in a new header and
     44 *    module that implement the virtual load and save functions.
     45 * -# Add the header file of your new parser to FormatParserStorage.cpp.
     46 *
     47 * <H3> Specific notes on the macros </H3>
     48 *
     49 * To clarify a bit the internals of all the different FormatParser... files, here
     50 * are some notes:
     51 * -# We make use of boost::preprocessor to generate lists from the sequence
     52 *    given in ParserTypes.def (and undefined in ParserTypes.undef). These might
     53 *    be forward declarations of even implementations. This is to assure that
     54 *    none are forgotten when a new FormatParser is added.
     55 * -# Thanks to the above construct FormatParserStorage also immediately knows
     56 *    about any new parsers and can get and add such instances.
     57 */
     58
     59/**
    2960 * General parser which observes the change tracker.
    3061 */
    31 class FormatParser : public Observer {
    32   friend class MoleCuilder::MoleculeLoadAction;
    33 public:
    34   FormatParser();
    35   virtual ~FormatParser();
    36   virtual void save(std::ostream* file, const std::vector<atom *> &atoms)=0;
    37   virtual void load(std::istream* file)=0;
    38   void setOstream(std::ostream* file);
     62template <enum ParserTypes Ptype>
     63class FormatParser : virtual public FormatParserInterface, public FormatParser_common {
     64  FormatParser() :
     65    FormatParser_common(NULL)
     66  {
     67    ASSERT(0, "FormatParser<>::FormatParser() - unspecialized function cannot be called.");
     68  }
     69  virtual ~FormatParser()
     70  {
     71    ASSERT(0, "FormatParser<>::~FormatParser() - unspecialized function cannot be called.");
     72  }
    3973
    40 protected:
    41   void update(Observable *publisher);
    42   void recieveNotification(Observable *publisher, Notification_ptr notification);
    43   void subjectKilled(Observable *publisher);
    44 
    45   // these functions are called when atoms are inserted or removed
    46   virtual void AtomInserted(atomId_t) {};
    47   virtual void AtomRemoved(atomId_t) {};
    48 
    49   FormatParser_Parameters *parameters;
    50 private:
    51 
    52   std::ostream* saveStream;
     74  void load(std::istream *file)
     75  {
     76    ASSERT(0, "FormatParser<>::load() - unspecialized function cannot be called.");
     77  }
     78  void save(std::ostream *file, const std::vector<atom *> &atoms)
     79  {
     80    ASSERT(0, "FormatParser<>::save() - unspecialized function cannot be called.");
     81  }
    5382};
    5483
     84#include "FormatParser_specializations_header.hpp"
     85
    5586#endif /* FORMATPARSER_HPP_ */
  • 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]) {
  • src/Parser/FormatParserStorage.hpp

    r9a6b76e r765f16  
    1616#include "CodePatterns/Singleton.hpp"
    1717
     18#include <iosfwd>
     19#include <map>
    1820#include <string>
    19 #include <map>
    2021#include <vector>
    2122
    22 #include "Parser/ParserTypes.hpp"
    23 #include "Parser/FormatParser.hpp"
    24 #include "Parser/MpqcParser.hpp"
    25 #include "Parser/PcpParser.hpp"
    26 #include "Parser/PdbParser.hpp"
    27 #include "Parser/TremoloParser.hpp"
    28 #include "Parser/XyzParser.hpp"
     23#include "CodePatterns/Assert.hpp"
     24#include "CodePatterns/Log.hpp"
     25#include "FormatParser.hpp"
     26#include "ParserTypes.hpp"
    2927
    3028class atom;
    31 
    32 template <class T> enum ParserTypes getPType();
    33 template <> enum ParserTypes getPType<MpqcParser>();
    34 template <> enum ParserTypes getPType<PcpParser>();
    35 template <> enum ParserTypes getPType<PdbParser>();
    36 template <> enum ParserTypes getPType<TremoloParser>();
    37 template <> enum ParserTypes getPType<XyzParser>();
    38 
     29class FormatParserInterface;
    3930
    4031class FormatParserStorage : public Singleton<FormatParserStorage> {
     
    5142  bool saveWorld(std::ostream &output, std::string suffix);
    5243 
    53   FormatParser &get(enum ParserTypes _type);
     44  FormatParserInterface &get(ParserTypes _type);
    5445
    5546  ParserTypes getTypeFromName(std::string type);
     
    6556 
    6657  // list of allocated parsers
    67   std::vector<FormatParser *> ParserList;
     58  std::vector<FormatParserInterface *> ParserList;
    6859
    6960  // list of allocated strams
     
    8475  std::map<std::string, ParserTypes> ParserLookupNames;
    8576
    86 
    8777  // prefix of the filenames to use on save
    8878  std::string prefix;
    8979
    9080public:
    91 
    92   template<class ParserT> void addParser()
     81  template<ParserTypes Ptype> void addParser()
    9382  {
    94     enum ParserTypes Ptype = getPType<ParserT>();
    9583    if (!ParserPresent[Ptype]) {
    96       ParserList[Ptype] = new ParserT();
     84      ParserList[Ptype] = new FormatParser<Ptype>();
    9785      ParserPresent[Ptype] = true;
    9886    } else {
     
    10896  }
    10997
    110   template<class ParserT> ParserT &getParser()
     98  template<ParserTypes Ptype> FormatParser<Ptype> &getParser()
    11199  {
    112     enum ParserTypes Ptype = getPType<ParserT>();
    113100    if(!ParserPresent[Ptype])
    114       addParser<ParserT>();
    115     return dynamic_cast<ParserT &>(*ParserList[Ptype]);
     101      addParser< Ptype >();
     102    return dynamic_cast<FormatParser<Ptype> &>(*ParserList[Ptype]);
    116103  }
    117 
    118104};
    119105
  • src/Parser/FormatParser_common.cpp

    r9a6b76e r765f16  
    77
    88/*
    9  * FormatParser.cpp
     9 * FormatParser_common_common.cpp
    1010 *
    1111 *  Created on: Mar 1, 2010
     
    2020#include "CodePatterns/MemDebug.hpp"
    2121
    22 #include "FormatParser.hpp"
    2322#include <iostream>
     23
     24#include "CodePatterns/Observer.hpp"
     25#include "World.hpp"
     26#include "ChangeTracker.hpp"
     27#include "FormatParser_common.hpp"
    2428
    2529using namespace std;
     
    2832 * Constructor.
    2933 */
    30 FormatParser::FormatParser() :
    31   Observer("FormatParser"),
    32   parameters(NULL),
    33   saveStream(NULL)
     34FormatParser_common::FormatParser_common(FormatParser_Parameters *_parameters) :
     35  Observer("FormatParser_common")
    3436{
     37  parameters = _parameters;
    3538  ChangeTracker::getInstance().signOn(this);
    3639  World::getInstance().signOn(this, World::getInstance().getChannel(World::AtomInserted));
     
    4144 * Destructor.
    4245 */
    43 FormatParser::~FormatParser() {
     46FormatParser_common::~FormatParser_common()
     47{
    4448  ChangeTracker::getInstance().signOff(this);
    4549  World::getInstance().signOff(this, World::getInstance().getChannel(World::AtomInserted));
    4650  World::getInstance().signOff(this, World::getInstance().getChannel(World::AtomRemoved));
     51  if (parameters != NULL)
     52    delete parameters;
    4753}
    4854
     
    5157 * change tracker here).
    5258 */
    53 void FormatParser::update(Observable *publisher) {
     59void FormatParser_common::update(Observable *publisher) {
    5460  if (!saveStream) {
    5561    cerr << "Please invoke setOstream() so the parser knows where to save the World's data." << endl;
     
    6470 * With this, each format parser is informed about specific changes in the World.
    6571 */
    66 void FormatParser::recieveNotification(Observable *publisher, Notification_ptr notification) {
     72void FormatParser_common::recieveNotification(Observable *publisher, Notification_ptr notification) {
    6773  switch (notification->getChannelNo()) {
    6874    case World::AtomInserted:
     
    7480    default:
    7581      ASSERT(0,
    76           "FormatParser::recieveNotification() - unknown notification "
     82          "FormatParser_common::recieveNotification() - unknown notification "
    7783          +toString(notification->getChannelNo())+" received.");
    7884      break;
     
    8389 * The observable can tell when it dies.
    8490 */
    85 void FormatParser::subjectKilled(Observable *publisher) {}
    86 
     91void FormatParser_common::subjectKilled(Observable *publisher) {}
    8792
    8893/**
     
    9297 * \param ostream where to save the World's state
    9398 */
    94 void FormatParser::setOstream(ostream* output) {
     99void FormatParser_common::setOstream(ostream* output) {
    95100  saveStream = output;
    96101}
  • src/Parser/Makefile.am

    r9a6b76e r765f16  
    55PARSERSOURCE = \
    66  Parser/ChangeTracker.cpp \
    7   Parser/FormatParser.cpp \
     7  Parser/FormatParser_common.cpp \
    88  Parser/FormatParserStorage.cpp \
    99  Parser/MpqcParser.cpp \
    1010  Parser/MpqcParser_Parameters.cpp \
    1111  Parser/MpqcParser_Parameters_initBasis.cpp \
     12  Parser/ParserTypes.cpp \
    1213  Parser/PcpParser.cpp \
    1314  Parser/PdbAtomInfoContainer.cpp \
     
    2021  Parser/ChangeTracker.hpp \
    2122  Parser/FormatParser.hpp \
     23  Parser/FormatParser_specializations_header.hpp \
     24  Parser/FormatParser_common.hpp \
     25  Parser/FormatParserInterface.hpp \
     26  Parser/FormatParserTrait.hpp \
     27  Parser/FormatParserTrait_specializations_header.hpp \
    2228  Parser/FormatParser_Parameters.hpp \
    2329  Parser/FormatParserStorage.hpp \
    2430  Parser/MpqcParser.hpp \
    2531  Parser/MpqcParser_Parameters.hpp \
     32  Parser/ParserTypes.hpp \
     33  Parser/ParserTypes.def \
     34  Parser/ParserTypes.undef \
    2635  Parser/PcpParser.hpp \
    2736  Parser/PdbAtomInfoContainer.hpp \
  • src/Parser/MpqcParser.cpp

    r9a6b76e r765f16  
    3838#include "World.hpp"
    3939
     40// declare specialized static variables
     41const std::string FormatParserTrait<mpqc>::name = "mpqc";
     42const std::string FormatParserTrait<mpqc>::suffix = "in";
     43const ParserTypes FormatParserTrait<mpqc>::type = mpqc;
    4044
    4145/** Constructor of MpqcParser.
    4246 *
    4347 */
    44 MpqcParser::MpqcParser()
    45 {
    46   parameters = new MpqcParser_Parameters();
    47 }
     48FormatParser< mpqc >::FormatParser() :
     49  FormatParser_common(new MpqcParser_Parameters())
     50{}
    4851
    4952/** Destructor of MpqcParser.
    5053 *
    5154 */
    52 MpqcParser::~MpqcParser()
    53 {
    54   delete parameters;
    55 }
     55FormatParser< mpqc >::~FormatParser()
     56{}
    5657
    5758/** Load an MPQC config file into the World.
    5859 * \param *file input stream
    5960 */
    60 void MpqcParser::load(istream *file)
     61void FormatParser< mpqc >::load(istream *file)
    6162{
    6263  bool MpqcSection = false;
     
    9697        tokenizer::iterator tok_iter = tokens.begin();
    9798        ASSERT(tok_iter != tokens.end(),
    98             "MpqcParser::load() - missing token for MoleculeSection in line "+linestring+"!");
     99            "FormatParser< mpqc >::load() - missing token for MoleculeSection in line "+linestring+"!");
    99100        std::stringstream whitespacefilter(*tok_iter++);
    100101        std::string element;
    101102        whitespacefilter >> ws >> element;
    102103        ASSERT(tok_iter != tokens.end(),
    103             "MpqcParser::load() - missing token for MoleculeSection in line "+linestring+"!");
     104            "FormatParser< mpqc >::load() - missing token for MoleculeSection in line "+linestring+"!");
    104105        std::string vector = *tok_iter;
    105106        tokenizer vectorcomponents(vector, whitesep);
     
    125126        ++tok_iter;
    126127        ASSERT(tok_iter != tokens.end(),
    127             "MpqcParser::load() - missing token in brackets<> for mole< in line "+linestring+"!");
     128            "FormatParser< mpqc >::load() - missing token in brackets<> for mole< in line "+linestring+"!");
    128129        std::string value(*tok_iter);
    129130        std::stringstream linestream("theory = "+value);
     
    134135        ++tok_iter;
    135136        ASSERT(tok_iter != tokens.end(),
    136             "MpqcParser::load() - missing token in brackets<> for integrals< in line "+linestring+"!");
     137            "FormatParser< mpqc >::load() - missing token in brackets<> for integrals< in line "+linestring+"!");
    137138        std::string value(*tok_iter);
    138139        std::stringstream linestream("integration = "+value);
     
    143144        tokenizer::iterator tok_iter = tokens.begin();
    144145        ASSERT(tok_iter != tokens.end(),
    145             "MpqcParser::load() - missing token before '=' for MpqcSection in line "+linestring+"!");
     146            "FormatParser< mpqc >::load() - missing token before '=' for MpqcSection in line "+linestring+"!");
    146147        std::stringstream whitespacefilter(*tok_iter);
    147148        std::string key;
     
    159160      tokenizer::iterator tok_iter = tokens.begin();
    160161      ASSERT(tok_iter != tokens.end(),
    161           "MpqcParser::load() - missing token for BasisSection in line "+linestring+"!");
     162          "FormatParser< mpqc >::load() - missing token for BasisSection in line "+linestring+"!");
    162163      std::string key(*tok_iter++);
    163164      ASSERT(tok_iter != tokens.end(),
    164           "MpqcParser::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");
     165          "FormatParser< mpqc >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");
    165166      std::string value(*tok_iter);
    166167      tok_iter++;
    167168      // TODO: use exception instead of ASSERT
    168169      ASSERT(tok_iter == tokens.end(),
    169           "MpqcParser::load() - more than (key = value) on line "+linestring+".");
     170          "FormatParser< mpqc >::load() - more than (key = value) on line "+linestring+".");
    170171      if (key == "name") {
    171172        std::stringstream linestream("basis = "+value);
     
    177178      tokenizer::iterator tok_iter = tokens.begin();
    178179      ASSERT(tok_iter != tokens.end(),
    179           "MpqcParser::load() - missing token for AuxBasisSection in line "+linestring+"!");
     180          "FormatParser< mpqc >::load() - missing token for AuxBasisSection in line "+linestring+"!");
    180181      std::string key(*tok_iter++);
    181182      ASSERT(tok_iter != tokens.end(),
    182           "MpqcParser::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");
     183          "FormatParser< mpqc >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");
    183184      std::string value(*tok_iter);
    184185      tok_iter++;
    185186      // TODO: use exception instead of ASSERT
    186187      ASSERT(tok_iter == tokens.end(),
    187           "MpqcParser::load() - more than (key = value) on line "+linestring+".");
     188          "FormatParser< mpqc >::load() - more than (key = value) on line "+linestring+".");
    188189      if (key == "name") {
    189190        std::stringstream linestream("aux_basis = "+value);
     
    216217 * \param atoms atoms to store
    217218 */
    218 void MpqcParser::save(ostream *file, const std::vector<atom *> &atoms)
     219void FormatParser< mpqc >::save(ostream *file, const std::vector<atom *> &atoms)
    219220{
    220221  Vector center;
  • src/Parser/MpqcParser.hpp

    r9a6b76e r765f16  
    1616
    1717#include "FormatParser.hpp"
     18#include "FormatParserTrait.hpp"
     19#include "FormatParserInterface.hpp"
     20#include "FormatParser_common.hpp"
     21#include "ParserTypes.hpp"
     22
    1823#include "MpqcParser_Parameters.hpp"
    1924
    2025#include <iosfwd>
    2126
     27// declaration of specialized FormatParserTrait
     28template<>
     29struct FormatParserTrait<mpqc>
     30{
     31  //!> Name of the parser
     32  static const std::string name;
     33  //!> suffix of the files the parser understands to read and write
     34  static const std::string suffix;
     35  //!> ParserTypes enumeration for the parser
     36  static const enum ParserTypes type;
     37};
     38
    2239/**
    2340 * Loads a MPQC config file into the World and saves the World as a tremolo file.
    2441 */
    25 class MpqcParser : public FormatParser
     42template <>
     43class FormatParser< mpqc >  : virtual public FormatParserInterface, public FormatParser_common
    2644{
    2745  friend class ParserMpqcUnitTest;
    2846public:
     47  FormatParser();
     48  virtual ~FormatParser();
    2949
    30   MpqcParser();
    31   virtual ~MpqcParser();
    32   void load(std::istream* file);
    33   void save(std::ostream* file, const std::vector<atom *> &atoms);
     50  void load(std::istream *file);
     51  void save(std::ostream *file, const std::vector<atom *> &atoms);
    3452
    3553  /** Getter for parameter set.
  • src/Parser/ParserTypes.hpp

    r9a6b76e r765f16  
    1414#endif
    1515
    16 // enum has to be outside of class for operator++ to be possible
    17 enum ParserTypes { mpqc, pcp, pdb, tremolo, xyz, ParserTypes_end, ParserTypes_begin = mpqc };
     16#include <boost/preprocessor/seq/elem.hpp>
     17#include <boost/preprocessor/seq/seq.hpp>
     18#include <boost/preprocessor/seq/size.hpp>
     19#include <boost/preprocessor/iteration/local.hpp>
     20
     21
     22#include "ParserTypes.def"
     23
     24//!> function to print each member of the sequence in the enumeration
     25#define sequence_print(z,n,seq) \
     26  BOOST_PP_SEQ_ELEM(n, seq) ,
     27
     28//!> Enumeration of all known parsers
     29enum ParserTypes {
     30// some proprocessor magic to generate the body from the above sequence
     31#if defined ParserTypes_END // do we have parameters at all?
     32#define BOOST_PP_LOCAL_MACRO(n) sequence_print(~, n, PARSERSEQUENCE)
     33#define BOOST_PP_LOCAL_LIMITS  (0, ParserTypes_END-1)
     34#include BOOST_PP_LOCAL_ITERATE()
     35#undef BOOST_PP_LOCAL_MACRO
     36#undef BOOST_PP_LOCAL_LIMITS
     37#endif
     38  ParserTypes_end = ParserTypes_END,
     39  ParserTypes_begin = BOOST_PP_SEQ_HEAD(PARSERSEQUENCE)
     40};
     41
     42#undef sequence_print
     43
     44//!> Number of known ParserTypes
     45const size_t ParserTypesMax = ParserTypes_END;
     46
     47#include "ParserTypes.undef"
     48
     49//!> Typedef for enumeration to ease its use
    1850typedef enum ParserTypes ParserTypes;
     51
     52/** Increment operator for the enumeration ParserTypes to allow loops.
     53 * \param &type value
     54 * \return value incremented by one
     55 */
     56ParserTypes &operator++(ParserTypes &type);
    1957
    2058#endif /* PARSERTYPES_HPP_ */
  • src/Parser/PcpParser.cpp

    r9a6b76e r765f16  
    4040
    4141
    42 PcpParser::StructParallelization::StructParallelization() :
     42// declare specialized static variables
     43const std::string FormatParserTrait<pcp>::name = "pcp";
     44const std::string FormatParserTrait<pcp>::suffix = "conf";
     45const ParserTypes FormatParserTrait<pcp>::type = pcp;
     46
     47FormatParser< pcp >::StructParallelization::StructParallelization() :
    4348  ProcPEGamma(8),
    4449  ProcPEPsi(1)
    4550{}
    4651
    47 PcpParser::StructParallelization::~StructParallelization()
    48 {}
    49 
    50 PcpParser::StructPaths::StructPaths() :
     52FormatParser< pcp >::StructParallelization::~StructParallelization()
     53{}
     54
     55FormatParser< pcp >::StructPaths::StructPaths() :
    5156  databasepath(NULL),
    5257  configname(NULL),
     
    5661{}
    5762
    58 PcpParser::StructPaths::~StructPaths()
    59 {}
    60 
    61 PcpParser::StructSwitches::StructSwitches() :
     63FormatParser< pcp >::StructPaths::~StructPaths()
     64{}
     65
     66FormatParser< pcp >::StructSwitches::StructSwitches() :
    6267  DoConstrainedMD(0),
    6368  DoOutVis(0),
     
    7176{}
    7277
    73 PcpParser::StructSwitches::~StructSwitches()
    74 {}
    75 
    76 PcpParser::StructLocalizedOrbitals::StructLocalizedOrbitals() :
     78FormatParser< pcp >::StructSwitches::~StructSwitches()
     79{}
     80
     81FormatParser< pcp >::StructLocalizedOrbitals::StructLocalizedOrbitals() :
    7782  CommonWannier(0),
    7883  SawtoothStart(0.01),
     
    8489{}
    8590
    86 PcpParser::StructLocalizedOrbitals::~StructLocalizedOrbitals()
    87 {}
    88 
    89 PcpParser::StructStepCounts::StructStepCounts() :
     91FormatParser< pcp >::StructLocalizedOrbitals::~StructLocalizedOrbitals()
     92{}
     93
     94FormatParser< pcp >::StructStepCounts::StructStepCounts() :
    9095  MaxMinStopStep(1),
    9196  InitMaxMinStopStep(1),
     
    104109{}
    105110
    106 PcpParser::StructStepCounts::~StructStepCounts()
    107 {}
    108 
    109 PcpParser::StructPlaneWaveSpecifics::StructPlaneWaveSpecifics() :
     111FormatParser< pcp >::StructStepCounts::~StructStepCounts()
     112{}
     113
     114FormatParser< pcp >::StructPlaneWaveSpecifics::StructPlaneWaveSpecifics() :
    110115  PsiType(0),
    111116  MaxPsiDouble(0),
     
    123128{}
    124129
    125 PcpParser::StructPlaneWaveSpecifics::~StructPlaneWaveSpecifics()
     130FormatParser< pcp >::StructPlaneWaveSpecifics::~StructPlaneWaveSpecifics()
    126131{}
    127132
     
    129134 *
    130135 */
    131 PcpParser::PcpParser() :
     136FormatParser< pcp >::FormatParser() :
     137  FormatParser_common(NULL),
    132138  FastParsing(false),
    133139  Deltat(0.01),
     
    141147 *
    142148 */
    143 PcpParser::~PcpParser()
    144 {}
    145 
    146 void PcpParser::load(std::istream* file)
     149FormatParser< pcp >::~FormatParser()
     150{}
     151
     152void FormatParser< pcp >::load(std::istream* file)
    147153{
    148154  if (file->fail()) {
     
    380386 * \param atoms atoms to store
    381387 */
    382 void PcpParser::save(std::ostream* file, const std::vector<atom *> &atoms)
     388void FormatParser< pcp >::save(std::ostream* file, const std::vector<atom *> &atoms)
    383389{
    384390  DoLog(0) && (Log() << Verbose(0) << "Saving changes to pcp." << std::endl);
     
    414420    *file << "DoFullCurrent\t" << Switches.DoFullCurrent << "\t# Do full perturbation" << endl;
    415421    *file << "DoConstrainedMD\t" << Switches.DoConstrainedMD << "\t# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD" << endl;
    416     ASSERT(Thermostats != NULL, "PcpParser::save() - Thermostats not initialized!");
     422    ASSERT(Thermostats != NULL, "FormatParser< pcp >::save() - Thermostats not initialized!");
    417423    *file << "Thermostat\t" << Thermostats->activeThermostat->name() << "\t";
    418424    *file << Thermostats->activeThermostat->writeParams();
     
    487493 * \param &allatoms all atoms to store away
    488494 */
    489 void PcpParser::CalculateOrbitals(const std::vector<atom *> &allatoms)
     495void FormatParser< pcp >::CalculateOrbitals(const std::vector<atom *> &allatoms)
    490496{
    491497  PlaneWaveSpecifics.MaxPsiDouble = PlaneWaveSpecifics.PsiMaxNoDown = PlaneWaveSpecifics.PsiMaxNoUp = PlaneWaveSpecifics.PsiType = 0;
     
    520526 * \param &ZtoIndexMap map of which atoms belong to which ion number
    521527 */
    522 void PcpParser::OutputElements(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap)
     528void FormatParser< pcp >::OutputElements(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap)
    523529{
    524530  map<int, int> PresentElements;
     
    550556 * \param &ZtoIndexMap map of which atoms belong to which ion number
    551557 */
    552 void PcpParser::OutputAtoms(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap)
     558void FormatParser< pcp >::OutputAtoms(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap)
    553559{
    554560  *file << "#Ion_TypeNr._Nr.R[0]    R[1]    R[2]    MoveType (0 MoveIon, 1 FixedIon)" << endl;
     
    598604 * \param *fb file buffer containing the config file
    599605 */
    600 void PcpParser::ParseThermostats(class ConfigFileBuffer * const fb)
     606void FormatParser< pcp >::ParseThermostats(class ConfigFileBuffer * const fb)
    601607{
    602608  char * const thermo = new char[12];
     
    615621};
    616622
    617 bool PcpParser::operator==(const PcpParser& b) const
     623bool FormatParser< pcp >::operator==(const FormatParser< pcp >& b) const
    618624{
    619625  ASSERT(Parallelization.ProcPEGamma == b.Parallelization.ProcPEGamma, "PcpParser ==: ProcPEGamma not");
  • src/Parser/PcpParser.hpp

    r9a6b76e r765f16  
    1414#endif
    1515
     16#include <iosfwd>
     17#include <map>
     18#include <string>
     19#include <vector>
    1620
    17 #include <iosfwd>
    18 #include "Parser/FormatParser.hpp"
     21#include "FormatParser.hpp"
     22#include "FormatParserTrait.hpp"
     23#include "FormatParserInterface.hpp"
     24#include "FormatParser_common.hpp"
     25#include "ParserTypes.hpp"
     26
     27class atom;
     28
     29// declaration of specialized FormatParserTrait
     30template<>
     31struct FormatParserTrait<pcp>
     32{
     33  //!> Name of the parser
     34  static const std::string name;
     35  //!> suffix of the files the parser understands to read and write
     36  static const std::string suffix;
     37  //!> ParserTypes enumeration for the parser
     38  static const enum ParserTypes type;
     39};
    1940
    2041/**
    2142 * Parser for PCP config files.
    2243 */
    23 class PcpParser : public FormatParser {
     44template <>
     45class FormatParser< pcp >  : virtual public FormatParserInterface, public FormatParser_common
     46{
    2447public:
    25   PcpParser();
    26   virtual ~PcpParser();
     48  FormatParser();
     49  virtual ~FormatParser();
    2750  void load(std::istream* file);
    2851  void save(std::ostream* file, const std::vector<atom *> &atoms);
    2952
    30   bool operator==(const PcpParser& b) const;
     53  bool operator==(const FormatParser< pcp >& b) const;
    3154
    3255private:
    3356
    3457  void ParseThermostats(class ConfigFileBuffer * const fb);
    35   void OutputAtoms(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap);
    36   void OutputElements(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap);
     58  void OutputAtoms(std::ostream *file, const std::vector<atom *> &allatoms, std::map<int, int> &ZtoIndexMap);
     59  void OutputElements(std::ostream *file, const std::vector<atom *> &allatoms, std::map<int, int> &ZtoIndexMap);
    3760  void CalculateOrbitals(const std::vector<atom *> &allatoms);
    3861
     
    154177  int StructOpt;
    155178  int MaxTypes;
    156   string basis;
     179  std::string basis;
    157180};
    158181
  • src/Parser/PdbAtomInfoContainer.hpp

    r9a6b76e r765f16  
    1414#endif
    1515
     16#include <string>
     17#include <typeinfo>
    1618
     19#include "LinearAlgebra/Vector.hpp"
    1720#include "PdbKey.hpp"
    1821
    19 class PdbParser;
    20 class Vector;
     22#include "ParserTypes.hpp"
    2123
    22 #include <string>
    23 #include <typeinfo>
     24//template <class T> class FormatParser;
     25//template<> class FormatParser< pdb >;
    2426
    2527/**
     
    2729 */
    2830class PdbAtomInfoContainer {
    29   friend class PdbParser;
     31  //!> Grant all FormatParser specializations access, otherwise we have to fully define FormatParser<pdb>
     32  template<enum ParserTypes> friend class FormatParser;
    3033public:
    3134  PdbAtomInfoContainer();
  • src/Parser/PdbParser.cpp

    r9a6b76e r765f16  
    4444using namespace std;
    4545
     46// declare specialized static variables
     47const std::string FormatParserTrait<pdb>::name = "pdb";
     48const std::string FormatParserTrait<pdb>::suffix = "pdb";
     49const ParserTypes FormatParserTrait<pdb>::type = pdb;
     50
    4651/**
    4752 * Constructor.
    4853 */
    49 PdbParser::PdbParser() {
     54FormatParser< pdb >::FormatParser() :
     55  FormatParser_common(NULL)
     56{
    5057  knownTokens["ATOM"] = PdbKey::Atom;
    5158  knownTokens["HETATM"] = PdbKey::Atom;
     
    6572 * Destructor.
    6673 */
    67 PdbParser::~PdbParser() {
     74FormatParser< pdb >::~FormatParser()
     75{
    6876  PdbAtomInfoContainer::clearknownDataKeys();
    6977  additionalAtomData.clear();
     
    7785 * @return token type
    7886 */
    79 enum PdbKey::KnownTokens PdbParser::getToken(string &line)
     87enum PdbKey::KnownTokens FormatParser< pdb >::getToken(string &line)
    8088{
    8189  // look for first space
     
    105113 * \param PDB file
    106114 */
    107 void PdbParser::load(istream* file) {
     115void FormatParser< pdb >::load(istream* file) {
    108116  string line;
    109117  size_t linecount  = 0;
     
    148156            // TODO: put a throw here
    149157            DoeLog(2) && (eLog() << Verbose(2) << "Unknown token: '" << line << "' for time step " << step << "." << std::endl);
    150             //ASSERT(0, "PdbParser::load() - Unknown token in line "+toString(linecount)+": "+line+".");
     158            //ASSERT(0, "FormatParser< pdb >::load() - Unknown token in line "+toString(linecount)+": "+line+".");
    151159            break;
    152160        }
     
    170178 * \param atoms atoms to store
    171179 */
    172 void PdbParser::save(ostream* file, const std::vector<atom *> &AtomList)
     180void FormatParser< pdb >::save(ostream* file, const std::vector<atom *> &AtomList)
    173181{
    174182  DoLog(0) && (Log() << Verbose(0) << "Saving changes to pdb." << std::endl);
     
    240248        } else {
    241249          ASSERT(MolIdMap.find(mol->getId()) != MolIdMap.end(),
    242               "PdbParser::save() - Mol id "+toString(mol->getId())+" not present despite we set it?!");
     250              "FormatParser< pdb >::save() - Mol id "+toString(mol->getId())+" not present despite we set it?!");
    243251          MolNo = MolIdMap[mol->getId()];
    244252          atomInfo.set(PdbKey::resSeq, toString(MolIdMap[mol->getId()]));
     
    289297 * @param id of atom
    290298 */
    291 void PdbParser::AtomInserted(atomId_t id)
    292 {
    293   //LOG(3, "PdbParser::AtomInserted() - notified of atom " << id << "'s insertion.");
     299void FormatParser< pdb >::AtomInserted(atomId_t id)
     300{
     301  //LOG(3, "FormatParser< pdb >::AtomInserted() - notified of atom " << id << "'s insertion.");
    294302  ASSERT(!isPresentadditionalAtomData(id),
    295       "PdbParser::AtomInserted() - additionalAtomData already present for newly added atom "
     303      "FormatParser< pdb >::AtomInserted() - additionalAtomData already present for newly added atom "
    296304      +toString(id)+".");
    297305  // don't insert here as this is our check whether we are in the first time step
     
    304312 * @param id of atom
    305313 */
    306 void PdbParser::AtomRemoved(atomId_t id)
    307 {
    308   //LOG(3, "PdbParser::AtomRemoved() - notified of atom " << id << "'s removal.");
     314void FormatParser< pdb >::AtomRemoved(atomId_t id)
     315{
     316  //LOG(3, "FormatParser< pdb >::AtomRemoved() - notified of atom " << id << "'s removal.");
    309317  std::map<size_t, PdbAtomInfoContainer>::iterator iter = additionalAtomData.find(id);
    310318  // as we do not insert AtomData on AtomInserted, we cannot be assured of its presence
    311319//  ASSERT(iter != additionalAtomData.end(),
    312 //      "PdbParser::AtomRemoved() - additionalAtomData is not present for atom "
     320//      "FormatParser< pdb >::AtomRemoved() - additionalAtomData is not present for atom "
    313321//      +toString(id)+" to remove.");
    314322  if (iter != additionalAtomData.end()) {
     
    325333 * @return true - entry present, false - only for atom's father or no entry
    326334 */
    327 bool PdbParser::isPresentadditionalAtomData(unsigned int _id)
     335bool FormatParser< pdb >::isPresentadditionalAtomData(unsigned int _id)
    328336{
    329337  return (additionalAtomData.find(_id) != additionalAtomData.end());
     
    336344 * @return
    337345 */
    338 PdbAtomInfoContainer& PdbParser::getadditionalAtomData(atom *_atom)
     346PdbAtomInfoContainer& FormatParser< pdb >::getadditionalAtomData(atom *_atom)
    339347{
    340348  if (additionalAtomData.find(_atom->getId()) != additionalAtomData.end()) {
     
    362370 * \param ResidueNo number of residue
    363371 */
    364 void PdbParser::saveLine(
     372void FormatParser< pdb >::saveLine(
    365373    ostream* file,
    366374    const PdbAtomInfoContainer &atomInfo)
     
    423431 * \param *currentAtom to the atom of which to take the neighbor information
    424432 */
    425 void PdbParser::writeNeighbors(ostream* file, int MaxnumberOfNeighbors, atom* currentAtom) {
     433void FormatParser< pdb >::writeNeighbors(ostream* file, int MaxnumberOfNeighbors, atom* currentAtom) {
    426434  int MaxNo = MaxnumberOfNeighbors;
    427435  int charsleft = 80;
     
    452460}
    453461
    454 /** Retrieves a value from PdbParser::atomIdMap.
     462/** Retrieves a value from  FormatParser< pdb >::atomIdMap.
    455463 * \param atomid key
    456464 * \return value
    457465 */
    458 size_t PdbParser::getSerial(const size_t atomid) const
    459 {
    460   ASSERT(atomIdMap.find(atomid) != atomIdMap.end(),
    461       "PdbParser::getSerial() - atomid "+toString(atomid)+" not present in Map.");
     466size_t FormatParser< pdb >::getSerial(const size_t atomid) const
     467{
     468  ASSERT(atomIdMap.find(atomid) != atomIdMap.end(), 
     469      "FormatParser< pdb >::getAtomId: atomid "+toString(atomid)+" not present in Map.");
    462470  return (atomIdMap.find(atomid)->second);
    463471}
    464472
    465 /** Sets an entry in PdbParser::atomIdMap.
     473/** Sets an entry in  FormatParser< pdb >::atomIdMap.
    466474 * \param localatomid key
    467475 * \param atomid value
    468476 * \return true - key not present, false - value present
    469477 */
    470 void PdbParser::setSerial(const size_t localatomid, const size_t atomid)
     478void FormatParser< pdb >::setSerial(const size_t localatomid, const size_t atomid)
    471479{
    472480  pair<std::map<size_t,size_t>::iterator, bool > inserter;
    473 //  DoLog(1) && (Log() << Verbose(1) << "PdbParser::setAtomId() - Inserting ("
     481//  DoLog(1) && (Log() << Verbose(1) << "FormatParser< pdb >::setAtomId() - Inserting ("
    474482//      << localatomid << " -> " << atomid << ")." << std::endl);
    475483  inserter = atomIdMap.insert( make_pair(localatomid, atomid) );
    476   ASSERT(inserter.second, "PdbParser::setAtomId: atomId already present in Map.");
     484  ASSERT(inserter.second, "FormatParser< pdb >::setAtomId: atomId already present in Map.");
    477485}
    478486
     
    482490 * @return
    483491 */
    484 atom* PdbParser::getAtomToParse(std::string id_string) const
     492atom* FormatParser< pdb >::getAtomToParse(std::string id_string) const
    485493{
    486494  // get the local ID
     
    517525 * @param line line containing key ATOM
    518526 */
    519 void PdbParser::readPdbAtomInfoContainer(PdbAtomInfoContainer &atomInfo, std::string &line) const
     527void FormatParser< pdb >::readPdbAtomInfoContainer(PdbAtomInfoContainer &atomInfo, std::string &line) const
    520528{
    521529  const size_t length = line.length();
    522530  if (length < 80)
    523     ELOG(2, "PdbParser::readPdbAtomInfoContainer() - pdb is mal-formed, containing less than 80 chars!");
     531    ELOG(2, "FormatParser< pdb >::readPdbAtomInfoContainer() - pdb is mal-formed, containing less than 80 chars!");
    524532  if (length >= 6) {
    525533    LOG(4,"INFO: Parsing token from "+line.substr(0,6)+".");
     
    530538    atomInfo.set(PdbKey::serial, line.substr(6,5));
    531539    ASSERT(atomInfo.get<int>(PdbKey::serial) != 0,
    532         "PdbParser::readPdbAtomInfoContainer() - serial 0 is invalid (filler id for conect entries).");
     540        "FormatParser< pdb >::readPdbAtomInfoContainer() - serial 0 is invalid (filler id for conect entries).");
    533541  }
    534542
     
    591599 * \param newmol molecule to add parsed atoms to
    592600 */
    593 void PdbParser::readAtomDataLine(const unsigned int _step, std::string &line, molecule *newmol = NULL) {
     601void FormatParser< pdb >::readAtomDataLine(const unsigned int _step, std::string &line, molecule *newmol = NULL) {
    594602  vector<string>::iterator it;
    595603
     
    598606  bool FirstTimestep = isPresentadditionalAtomData(newAtom->getId()) ? false : true;
    599607  ASSERT((FirstTimestep && (_step == 0)) || (!FirstTimestep && (_step !=0)),
    600       "PdbParser::readAtomDataLine() - additionalAtomData present though atom is newly parsed.");
     608      "FormatParser< pdb >::readAtomDataLine() - additionalAtomData present though atom is newly parsed.");
    601609  if (FirstTimestep) {
    602610    LOG(3,"INFO: Parsing new atom.");
     
    646654      SerialSet.insert(toSize_t(atomInfo.get<std::string>(PdbKey::serial)));
    647655    ASSERT(Inserter.second,
    648         "PdbParser::readAtomDataLine() - ATOM contains entry with serial "
     656        "FormatParser< pdb >::readAtomDataLine() - ATOM contains entry with serial "
    649657        +atomInfo.get<std::string>(PdbKey::serial)+" already present!");
    650658    setSerial(toSize_t(atomInfo.get<std::string>(PdbKey::serial)), newAtom->getId());
     
    667675        ->FindElement(value);
    668676    ASSERT(elem != NULL,
    669         "PdbParser::readAtomDataLine() - element "+atomInfo.get<std::string>(PdbKey::element)+" is unknown!");
     677        "FormatParser< pdb >::readAtomDataLine() - element "+atomInfo.get<std::string>(PdbKey::element)+" is unknown!");
    670678    newAtom->setType(elem);
    671679
     
    679687    // then check additional info for consistency
    680688    ASSERT(atomInfo.get<std::string>(PdbKey::token) == consistencyInfo.get<std::string>(PdbKey::token),
    681         "PdbParser::readAtomDataLine() - difference in token on multiple time step for atom with id "
     689        "FormatParser< pdb >::readAtomDataLine() - difference in token on multiple time step for atom with id "
    682690        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    683691    ASSERT(atomInfo.get<std::string>(PdbKey::name) == consistencyInfo.get<std::string>(PdbKey::name),
    684         "PdbParser::readAtomDataLine() - difference in name on multiple time step for atom with id "
     692        "FormatParser< pdb >::readAtomDataLine() - difference in name on multiple time step for atom with id "
    685693        +atomInfo.get<std::string>(PdbKey::serial)+":"
    686694        +atomInfo.get<std::string>(PdbKey::name)+"!="
    687695        +consistencyInfo.get<std::string>(PdbKey::name)+".");
    688696    ASSERT(atomInfo.get<std::string>(PdbKey::altLoc) == consistencyInfo.get<std::string>(PdbKey::altLoc),
    689         "PdbParser::readAtomDataLine() - difference in altLoc on multiple time step for atom with id "
     697        "FormatParser< pdb >::readAtomDataLine() - difference in altLoc on multiple time step for atom with id "
    690698        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    691699    ASSERT(atomInfo.get<std::string>(PdbKey::resName) == consistencyInfo.get<std::string>(PdbKey::resName),
    692         "PdbParser::readAtomDataLine() - difference in resName on multiple time step for atom with id "
     700        "FormatParser< pdb >::readAtomDataLine() - difference in resName on multiple time step for atom with id "
    693701        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    694702    ASSERT(atomInfo.get<std::string>(PdbKey::chainID) == consistencyInfo.get<std::string>(PdbKey::chainID),
    695         "PdbParser::readAtomDataLine() - difference in chainID on multiple time step for atom with id "
     703        "FormatParser< pdb >::readAtomDataLine() - difference in chainID on multiple time step for atom with id "
    696704        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    697705    ASSERT(atomInfo.get<std::string>(PdbKey::resSeq) == consistencyInfo.get<std::string>(PdbKey::resSeq),
    698         "PdbParser::readAtomDataLine() - difference in resSeq on multiple time step for atom with id "
     706        "FormatParser< pdb >::readAtomDataLine() - difference in resSeq on multiple time step for atom with id "
    699707        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    700708    ASSERT(atomInfo.get<std::string>(PdbKey::iCode) == consistencyInfo.get<std::string>(PdbKey::iCode),
    701         "PdbParser::readAtomDataLine() - difference in iCode on multiple time step for atom with id "
     709        "FormatParser< pdb >::readAtomDataLine() - difference in iCode on multiple time step for atom with id "
    702710        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    703711    ASSERT(atomInfo.get<std::string>(PdbKey::occupancy) == consistencyInfo.get<std::string>(PdbKey::occupancy),
    704         "PdbParser::readAtomDataLine() - difference in occupancy on multiple time step for atom with id "
     712        "FormatParser< pdb >::readAtomDataLine() - difference in occupancy on multiple time step for atom with id "
    705713        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    706714    ASSERT(atomInfo.get<std::string>(PdbKey::tempFactor) == consistencyInfo.get<std::string>(PdbKey::tempFactor),
    707         "PdbParser::readAtomDataLine() - difference in tempFactor on multiple time step for atom with id "
     715        "FormatParser< pdb >::readAtomDataLine() - difference in tempFactor on multiple time step for atom with id "
    708716        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    709717    ASSERT(atomInfo.get<std::string>(PdbKey::charge) == consistencyInfo.get<std::string>(PdbKey::charge),
    710         "PdbParser::readAtomDataLine() - difference in charge on multiple time step for atom with id "
     718        "FormatParser< pdb >::readAtomDataLine() - difference in charge on multiple time step for atom with id "
    711719        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    712720    ASSERT(atomInfo.get<std::string>(PdbKey::element) == consistencyInfo.get<std::string>(PdbKey::element),
    713         "PdbParser::readAtomDataLine() - difference in element on multiple time step for atom with id "
     721        "FormatParser< pdb >::readAtomDataLine() - difference in element on multiple time step for atom with id "
    714722        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    715723    // and parse in trajectory
     
    734742 *
    735743 */
    736 void PdbParser::printAtomInfo(const atom * const newAtom) const
     744void FormatParser< pdb >::printAtomInfo(const atom * const newAtom) const
    737745{
    738746  const PdbAtomInfoContainer &atomInfo = additionalAtomData.at(newAtom->getId()); // operator[] const does not exist
     
    762770 * \param line to parse as an atom
    763771 */
    764 void PdbParser::readNeighbors(const unsigned int _step, std::string &line)
     772void FormatParser< pdb >::readNeighbors(const unsigned int _step, std::string &line)
    765773{
    766774  const size_t length = line.length();
     
    772780  string output;
    773781  ASSERT(length >=16,
    774       "PdbParser::readNeighbors() - CONECT entry has not enough entries: "+line+"!");
    775   output = "Split line:|";
    776   output += line.substr(6,5) + "|";
     782      "FormatParser< pdb >::readNeighbors() - CONECT entry has not enough entries: "+line+"!");
     783//  output = "Split line:|";
     784//  output += line.substr(6,5) + "|";
    777785  const size_t id = toSize_t(line.substr(6,5));
    778786  for (size_t index = 11; index <= 26; index+=5) {
     
    785793        ListOfNeighbors.push_back(otherid);
    786794      else
    787         ELOG(2, "PdbParser::readNeighbors() - discarding conect entry with id 0.");
     795        ELOG(2, "FormatParser< pdb >::readNeighbors() - discarding conect entry with id 0.");
    788796    } else  {
    789797      break;
     
    813821 * \return input string with modified atom IDs
    814822 */
    815 //string PdbParser::adaptIdDependentDataString(string data) {
     823//string  FormatParser< pdb >::adaptIdDependentDataString(string data) {
    816824//  // there might be no IDs
    817825//  if (data == "-") {
     
    836844
    837845
    838 bool PdbParser::operator==(const PdbParser& b) const
     846bool FormatParser< pdb >::operator==(const FormatParser< pdb >& b) const
    839847{
    840848  bool status = true;
  • src/Parser/PdbParser.hpp

    r9a6b76e r765f16  
    1414#endif
    1515
     16#include <string>
    1617
    17 #include <string>
    1818#include "FormatParser.hpp"
     19#include "FormatParserTrait.hpp"
     20#include "FormatParserInterface.hpp"
     21#include "FormatParser_common.hpp"
     22#include "ParserTypes.hpp"
     23
    1924#include "PdbAtomInfoContainer.hpp"
    2025#include "PdbKey.hpp"
     26
     27class molecule;
     28
     29// declaration of specialized FormatParserTrait
     30template<>
     31struct FormatParserTrait<pdb>
     32{
     33  //!> Name of the parser
     34  static const std::string name;
     35  //!> suffix of the files the parser understands to read and write
     36  static const std::string suffix;
     37  //!> ParserTypes enumeration for the parser
     38  static const enum ParserTypes type;
     39};
    2140
    2241/**
    2342 * Loads a PDB format 3.2 file into the World and saves the World as a PDB file.
    2443 */
    25 class PdbParser : public FormatParser
     44template <>
     45class FormatParser< pdb >  : virtual public FormatParserInterface, public FormatParser_common
    2646{
    2747public:
    28   PdbParser();
    29   virtual ~PdbParser();
     48  FormatParser();
     49  virtual ~FormatParser();
    3050  void load(std::istream* file);
    3151  void save(std::ostream* file, const std::vector<atom *> &atoms);
    3252
    33   bool operator==(const PdbParser& b) const;
     53  bool operator==(const FormatParser< pdb>& b) const;
    3454  void printAtomInfo(const atom *newAtom) const;
    3555
     
    91111   */
    92112  std::set<size_t> SerialSet;
    93 
    94113};
    95114
  • 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++;
  • src/Parser/TremoloParser.hpp

    r9a6b76e r765f16  
    1414#endif
    1515
     16#include <string>
    1617
    17 #include <string>
    18 #include "Parser/FormatParser.hpp"
     18#include "FormatParser.hpp"
     19#include "FormatParserTrait.hpp"
     20#include "FormatParserInterface.hpp"
     21#include "FormatParser_common.hpp"
     22#include "ParserTypes.hpp"
    1923
    2024#include "TremoloKey.hpp"
     
    2327class molecule;
    2428
     29// declaration of specialized FormatParserTrait
     30template<>
     31struct FormatParserTrait<tremolo>
     32{
     33  //!> Name of the parser
     34  static const std::string name;
     35  //!> suffix of the files the parser understands to read and write
     36  static const std::string suffix;
     37  //!> ParserTypes enumeration for the parser
     38  static const enum ParserTypes type;
     39};
     40
    2541/**
    2642 * Loads a tremolo file into the World and saves the World as a tremolo file.
    2743 */
    28 class TremoloParser : public FormatParser
     44template <>
     45class FormatParser< tremolo >  : virtual public FormatParserInterface, public FormatParser_common
    2946{
    3047public:
    31   TremoloParser();
    32   virtual ~TremoloParser();
     48  FormatParser();
     49  virtual ~FormatParser();
    3350  void load(std::istream* file);
    3451  void save(std::ostream* file, const std::vector<atom *> &atoms);
     
    4461
    4562private:
    46   void readAtomDataLine(string line);
    47   void readAtomDataLine(string line, molecule *newmol);
    48   void parseAtomDataKeysLine(string line, int offset);
     63  void readAtomDataLine(std::string line);
     64  void readAtomDataLine(std::string line, molecule *newmol);
     65  void parseAtomDataKeysLine(std::string line, int offset);
    4966  void readNeighbors(std::stringstream* line, int numberOfNeighbors, int atomId);
    5067  void processNeighborInformation();
  • src/Parser/XyzParser.cpp

    r9a6b76e r765f16  
    3333using namespace std;
    3434
     35// declare specialized static variables
     36const std::string FormatParserTrait<xyz>::name = "xyz";
     37const std::string FormatParserTrait<xyz>::suffix = "xyz";
     38const ParserTypes FormatParserTrait<xyz>::type = xyz;
     39
    3540/**
    3641 * Constructor.
    3742 */
    38 XyzParser::XyzParser() :
     43FormatParser< xyz >::FormatParser() :
     44  FormatParser_common(NULL),
    3945  comment("")
    4046{}
     
    4349 * Destructor.
    4450 */
    45 XyzParser::~XyzParser() {
    46 }
     51FormatParser< xyz >::~FormatParser()
     52{}
    4753
    4854/**
     
    5157 * \param XYZ file
    5258 */
    53 void XyzParser::load(istream* file)
     59void FormatParser< xyz >::load(istream* file)
    5460{
    5561  atom* newAtom = NULL;
     
    99105        LOG(5, "INFO: Using present atom " << *newAtom << " from " << i << " th component of AddedAtoms.");
    100106        ASSERT(newAtom->getType() == World::getInstance().getPeriode()->FindElement(type),
    101             "XyzParser::load() - atom has different type "+newAtom->getType()->getSymbol()+" than parsed now "+type+", mixed up order?");
     107            "FormatParser< xyz >::load() - atom has different type "+newAtom->getType()->getSymbol()+" than parsed now "+type+", mixed up order?");
    102108      }
    103109      newAtom->setPositionAtStep(step, tempVector);
     
    129135 * \param atoms atoms to store
    130136 */
    131 void XyzParser::save(ostream* file, const std::vector<atom *> &atoms) {
     137void FormatParser< xyz >::save(ostream* file, const std::vector<atom *> &atoms) {
    132138  DoLog(0) && (Log() << Verbose(0) << "Saving changes to xyz." << std::endl);
    133139
     
    145151  }
    146152  ASSERT((min_trajectories == max_trajectories) || (min_trajectories == 1),
    147       "XyzParser::save() - not all atoms have same number of trajectories.");
     153      "FormatParser< xyz >::save() - not all atoms have same number of trajectories.");
    148154  LOG(2, "INFO: There are " << max_trajectories << " to save.");
    149155
  • src/Parser/XyzParser.hpp

    r9a6b76e r765f16  
    1414#endif
    1515
     16#include <string>
    1617
    17 #include <string>
    18 #include "Parser/FormatParser.hpp"
     18
     19#include "FormatParser.hpp"
     20#include "FormatParserTrait.hpp"
     21#include "FormatParserInterface.hpp"
     22#include "FormatParser_common.hpp"
     23#include "ParserTypes.hpp"
     24
     25// declaration of specialized FormatParserTrait
     26template<>
     27struct FormatParserTrait<xyz>
     28{
     29  //!> Name of the parser
     30  static const std::string name;
     31  //!> suffix of the files the parser understands to read and write
     32  static const std::string suffix;
     33  //!> ParserTypes enumeration for the parser
     34  static const enum ParserTypes type;
     35};
    1936
    2037/**
    2138 * Parser for XYZ files.
    2239 */
    23 class XyzParser : public FormatParser {
     40template <>
     41class FormatParser< xyz >  : virtual public FormatParserInterface, public FormatParser_common
     42{
    2443public:
    25   XyzParser();
    26   virtual ~XyzParser();
     44  FormatParser();
     45  virtual ~FormatParser();
    2746  void load(std::istream* file);
    2847  void save(std::ostream* file, const std::vector<atom *> &atoms);
  • src/Parser/unittests/ParserMpqcUnitTest.cpp

    r9a6b76e r765f16  
    3232#include "Descriptors/AtomTypeDescriptor.hpp"
    3333#include "CodePatterns/Assert.hpp"
     34#include "Parser/ChangeTracker.hpp"
     35#include "Parser/MpqcParser.hpp"
    3436
    3537#ifdef HAVE_TESTRUNNER
     
    157159
    158160void ParserMpqcUnitTest::setUp() {
    159   mpqc = new MpqcParser();
     161  parser = new FormatParser<mpqc>();
    160162
    161163  World::getInstance();
     
    169171
    170172void ParserMpqcUnitTest::tearDown() {
    171   delete mpqc;
     173  delete parser;
    172174  ChangeTracker::purgeInstance();
    173175  World::purgeInstance();
     
    178180void ParserMpqcUnitTest::ParameterTypeTest() {
    179181  // check types in boost::any map
    180   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::hessianParam].type() == typeid(bool));
    181   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::hessianParam].type() != typeid(int));
    182   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::savestateParam].type() == typeid(bool));
    183   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::do_gradientParam].type() == typeid(bool));
    184   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::maxiterParam].type() == typeid(int));
    185   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::memoryParam].type() == typeid(int));
    186   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::stdapproxParam].type() == typeid(std::string));
    187   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::nfzcParam].type() == typeid(int));
    188   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::basisParam].type() == typeid(std::string));
    189   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::aux_basisParam].type() == typeid(std::string));
    190   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::integrationParam].type() == typeid(MpqcParser_Parameters::IntegralCints));
    191   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::theoryParam].type() == typeid(MpqcParser_Parameters::MBPT2));
     182  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::hessianParam].type() == typeid(bool));
     183  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::hessianParam].type() != typeid(int));
     184  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::savestateParam].type() == typeid(bool));
     185  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::do_gradientParam].type() == typeid(bool));
     186  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::maxiterParam].type() == typeid(int));
     187  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::memoryParam].type() == typeid(int));
     188  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::stdapproxParam].type() == typeid(std::string));
     189  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::nfzcParam].type() == typeid(int));
     190  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::basisParam].type() == typeid(std::string));
     191  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::aux_basisParam].type() == typeid(std::string));
     192  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::integrationParam].type() == typeid(MpqcParser_Parameters::IntegralCints));
     193  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::theoryParam].type() == typeid(MpqcParser_Parameters::MBPT2));
    192194}
    193195
    194196void ParserMpqcUnitTest::ParameterDefaultTest() {
    195197  // check default values
    196   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "no");
    197   CPPUNIT_ASSERT(!mpqc->getParams().getBool(MpqcParser_Parameters::hessianParam));
    198   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::savestateParam) == "no");
    199   CPPUNIT_ASSERT(!mpqc->getParams().getBool(MpqcParser_Parameters::savestateParam));
    200   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::do_gradientParam) == "yes");
    201   CPPUNIT_ASSERT(mpqc->getParams().getBool(MpqcParser_Parameters::do_gradientParam));
    202   CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 1000);
    203   CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::memoryParam) == 16000000);
    204   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::stdapproxParam) == "A'");
    205   CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::nfzcParam) == 1);
    206   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::basisParam) == "3-21G");
    207   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::aux_basisParam) == "aug-cc-pVDZ");
    208   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::integrationParam) == "IntegralCints");
    209   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
    210   CPPUNIT_ASSERT(mpqc->getParams().getTheory() == MpqcParser_Parameters::MBPT2);
    211   CPPUNIT_ASSERT(mpqc->getParams().getIntegration() == MpqcParser_Parameters::IntegralCints);
     198  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "no");
     199  CPPUNIT_ASSERT(!parser->getParams().getBool(MpqcParser_Parameters::hessianParam));
     200  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::savestateParam) == "no");
     201  CPPUNIT_ASSERT(!parser->getParams().getBool(MpqcParser_Parameters::savestateParam));
     202  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::do_gradientParam) == "yes");
     203  CPPUNIT_ASSERT(parser->getParams().getBool(MpqcParser_Parameters::do_gradientParam));
     204  CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 1000);
     205  CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::memoryParam) == 16000000);
     206  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::stdapproxParam) == "A'");
     207  CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::nfzcParam) == 1);
     208  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::basisParam) == "3-21G");
     209  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::aux_basisParam) == "aug-cc-pVDZ");
     210  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::integrationParam) == "IntegralCints");
     211  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
     212  CPPUNIT_ASSERT(parser->getParams().getTheory() == MpqcParser_Parameters::MBPT2);
     213  CPPUNIT_ASSERT(parser->getParams().getIntegration() == MpqcParser_Parameters::IntegralCints);
    212214
    213215  // check that values are not removed
    214   CPPUNIT_ASSERT(!mpqc->getParams().params[MpqcParser_Parameters::theoryParam].empty());
     216  CPPUNIT_ASSERT(!parser->getParams().params[MpqcParser_Parameters::theoryParam].empty());
    215217
    216218  // check throw, for the moment aren't, are caught in getInt()
    217   CPPUNIT_ASSERT_THROW(mpqc->getParams().getInt(MpqcParser_Parameters::integrationParam), boost::bad_any_cast);
    218   CPPUNIT_ASSERT_THROW(mpqc->getParams().getInt(MpqcParser_Parameters::theoryParam), boost::bad_any_cast);
     219  CPPUNIT_ASSERT_THROW(parser->getParams().getInt(MpqcParser_Parameters::integrationParam), boost::bad_any_cast);
     220  CPPUNIT_ASSERT_THROW(parser->getParams().getInt(MpqcParser_Parameters::theoryParam), boost::bad_any_cast);
    219221
    220222}
    221223
    222224void ParserMpqcUnitTest::ParameterCloneTest() {
    223   FormatParser_Parameters *clone = mpqc->getParams().clone();
    224   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
     225  FormatParser_Parameters *clone = parser->getParams().clone();
     226  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
    225227  std::stringstream setvalue("theory = CLHF");
    226   setvalue >> mpqc->getParams();
    227   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
    228   mpqc->getParams().makeClone(*clone);
    229   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
     228  setvalue >> parser->getParams();
     229  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
     230  parser->getParams().makeClone(*clone);
     231  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
    230232}
    231233
     
    234236  {
    235237    std::stringstream setvalue("theory = CLHF");
    236     setvalue >> mpqc->getParams();
     238    setvalue >> parser->getParams();
    237239//    std::cout << "integration method is "
    238 //        << mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;
    239     CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
     240//        << parser->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;
     241    CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
    240242  }
    241243  // test a bool
    242244  {
    243245    std::stringstream setvalue("Hessian = yes");
    244     setvalue >> mpqc->getParams();
     246    setvalue >> parser->getParams();
    245247//    std::cout << "Hessian is "
    246 //        << mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
    247     CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
     248//        << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
     249    CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
    248250  }
    249251  // test int
    250252  {
    251253    std::stringstream setvalue("maxiter = 500");
    252     setvalue >> mpqc->getParams();
     254    setvalue >> parser->getParams();
    253255//    std::cout << "maxiter is "
    254 //        << mpqc->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;
    255     CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 500);
     256//        << parser->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;
     257    CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 500);
    256258  }
    257259  // test whether unknown key fails
     
    261263#ifndef NDEBUG
    262264    ASSERT_DO(Assert::Throw);
    263     CPPUNIT_ASSERT_THROW(setvalue >> mpqc->getParams(), Assert::AssertionFailure);
     265    CPPUNIT_ASSERT_THROW(setvalue >> parser->getParams(), Assert::AssertionFailure);
    264266#else
    265     setvalue >> mpqc->getParams();
     267    setvalue >> parser->getParams();
    266268#endif
    267269//    std::cout << "Hessian is still "
    268 //        << mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
    269     CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
     270//        << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
     271    CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
    270272  }
    271273}
     
    273275void ParserMpqcUnitTest::readMpqcTest() {
    274276  stringstream input(waterMpqc_CLHF);
    275   mpqc->getParams().setTheory(MpqcParser_Parameters::CLHF);
    276   mpqc->load(&input);
     277  parser->getParams().setTheory(MpqcParser_Parameters::CLHF);
     278  parser->load(&input);
    277279
    278280  CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
     
    301303    // compare both configs for CLHF
    302304    stringstream output;
    303     mpqc->getParams().setTheory(MpqcParser_Parameters::CLHF);
    304     mpqc->save(&output, atoms);
     305    parser->getParams().setTheory(MpqcParser_Parameters::CLHF);
     306    parser->save(&output, atoms);
    305307    stringstream input(waterMpqc_CLHF);
    306308    for (; std::getline(input, first) && std::getline(output, second); ) {
     
    312314    // compare both configs for CLKS
    313315    stringstream output;
    314     mpqc->getParams().setTheory(MpqcParser_Parameters::CLKS);
    315     mpqc->save(&output, atoms);
     316    parser->getParams().setTheory(MpqcParser_Parameters::CLKS);
     317    parser->save(&output, atoms);
    316318    stringstream input(waterMpqc_CLKS);
    317319    for (; std::getline(input, first) && std::getline(output, second); ) {
     
    323325    // compare both configs for MBPT2
    324326    stringstream output;
    325     mpqc->getParams().setTheory(MpqcParser_Parameters::MBPT2);
    326     mpqc->save(&output, atoms);
     327    parser->getParams().setTheory(MpqcParser_Parameters::MBPT2);
     328    parser->save(&output, atoms);
    327329    stringstream input(waterMpqc_MBPT2);
    328330    for (; std::getline(input, first) && std::getline(output, second); ) {
     
    334336    // compare both configs for MBPT2_R12
    335337    stringstream output;
    336     mpqc->getParams().setTheory(MpqcParser_Parameters::MBPT2_R12);
    337     mpqc->save(&output, atoms);
     338    parser->getParams().setTheory(MpqcParser_Parameters::MBPT2_R12);
     339    parser->save(&output, atoms);
    338340    stringstream input(waterMpqc_MBPT2_R12);
    339341    for (; std::getline(input, first) && std::getline(output, second); ) {
  • src/Parser/unittests/ParserMpqcUnitTest.hpp

    r9a6b76e r765f16  
    4141
    4242private:
    43   MpqcParser *mpqc;
     43  FormatParser<mpqc> *parser;
    4444};
    4545
  • src/Parser/unittests/ParserPcpUnitTest.cpp

    r9a6b76e r765f16  
    2424#include <cppunit/ui/text/TestRunner.h>
    2525
    26 #include "Parser/PcpParser.hpp"
    2726#include "World.hpp"
    2827#include "atom.hpp"
     
    3130#include "CodePatterns/Log.hpp"
    3231#include "Descriptors/AtomTypeDescriptor.hpp"
     32#include "Parser/ChangeTracker.hpp"
     33#include "Parser/PcpParser.hpp"
    3334
    3435#ifdef HAVE_TESTRUNNER
     
    119120  World::getInstance();
    120121
     122  parser = new FormatParser<pcp>();
     123
    121124  setVerbosity(2);
    122125
     
    126129}
    127130
    128 void ParserPcpUnitTest::tearDown() {
     131void ParserPcpUnitTest::tearDown()
     132{
     133  delete parser;
    129134  ChangeTracker::purgeInstance();
    130135  World::purgeInstance();
     
    135140void ParserPcpUnitTest::readwritePcpTest() {
    136141  stringstream input(waterPcp);
    137   PcpParser* testParser = new PcpParser();
    138   testParser->load(&input);
     142  parser->load(&input);
    139143  input.clear();
    140144
     
    142146
    143147  // check that equality function is ok
    144   CPPUNIT_ASSERT(*testParser == *testParser);
     148  CPPUNIT_ASSERT(*parser == *parser);
    145149
    146150  stringstream output;
    147151  std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    148   testParser->save(&output, atoms);
     152  parser->save(&output, atoms);
    149153
    150154  input << output.str();
    151   PcpParser* testParser2 = new PcpParser();
    152   testParser2->load(&input);
     155  FormatParser<pcp>* parser2 = new FormatParser<pcp>();
     156  parser2->load(&input);
    153157
    154158  CPPUNIT_ASSERT_EQUAL(6, World::getInstance().numAtoms());
    155159
    156   CPPUNIT_ASSERT(*testParser == *testParser2);
     160  CPPUNIT_ASSERT(*parser == *parser2);
     161
     162  delete parser2;
    157163}
  • src/Parser/unittests/ParserPcpUnitTest.hpp

    r9a6b76e r765f16  
    1313#endif
    1414
     15#include "Parser/PcpParser.hpp"
    1516
    1617#include <cppunit/extensions/HelperMacros.h>
     
    2829
    2930  void readwritePcpTest();
     31
     32private:
     33  FormatParser<pcp> *parser;
    3034};
    3135
  • src/Parser/unittests/ParserPdbUnitTest.cpp

    r9a6b76e r765f16  
    2424#include <cppunit/ui/text/TestRunner.h>
    2525
    26 #include "Parser/PdbParser.hpp"
    2726#include "World.hpp"
    2827#include "atom.hpp"
     
    3130#include "CodePatterns/Log.hpp"
    3231#include "Descriptors/AtomTypeDescriptor.hpp"
     32#include "Parser/ChangeTracker.hpp"
     33#include "Parser/PdbParser.hpp"
    3334
    3435#ifdef HAVE_TESTRUNNER
     
    6364  World::getInstance();
    6465
     66  parser = new FormatParser<pdb>();
     67
    6568  setVerbosity(2);
    6669
     
    7073}
    7174
    72 void ParserPdbUnitTest::tearDown() {
     75void ParserPdbUnitTest::tearDown()
     76{
     77  delete parser;
    7378  ChangeTracker::purgeInstance();
    7479  World::purgeInstance();
     
    8085  stringstream input;
    8186  input << waterPdb;
    82   PdbParser* testParser = new PdbParser();
    83   testParser->load(&input);
     87  parser->load(&input);
    8488  input.clear();
    8589
     
    8892  stringstream output;
    8993  std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    90   testParser->save(&output, atoms);
     94  parser->save(&output, atoms);
    9195
    9296//  std::cout << "Save PDB is:" << std::endl;
     
    9498
    9599  input << output.str();
    96   PdbParser* testParser2 = new PdbParser();
    97   testParser2->load(&input);
     100  FormatParser<pdb>* parser2 = new FormatParser<pdb>();
     101  parser2->load(&input);
    98102
    99103  CPPUNIT_ASSERT_EQUAL(12, World::getInstance().numAtoms());
     104
     105  delete parser2;
    100106}
  • src/Parser/unittests/ParserPdbUnitTest.hpp

    r9a6b76e r765f16  
    1313#endif
    1414
     15#include "Parser/PdbParser.hpp"
    1516
    1617#include <cppunit/extensions/HelperMacros.h>
     
    2829
    2930  void readwritePdbTest();
     31
     32private:
     33  FormatParser<pdb> *parser;
    3034};
    3135
  • src/Parser/unittests/ParserTremoloUnitTest.cpp

    r9a6b76e r765f16  
    2727#include "Descriptors/AtomTypeDescriptor.hpp"
    2828#include "element.hpp"
    29 #include "Parser/MpqcParser.hpp"
    30 #include "Parser/PdbParser.hpp"
    31 #include "Parser/PcpParser.hpp"
    3229#include "Parser/TremoloParser.hpp"
    33 #include "Parser/XyzParser.hpp"
     30#include "Parser/ChangeTracker.hpp"
    3431#include "periodentafel.hpp"
    3532#include "World.hpp"
     
    8582  World::getInstance();
    8683
     84  parser = new FormatParser<tremolo>();
     85
    8786  // we need hydrogens and oxygens in the following tests
    8887  CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
     
    9089}
    9190
    92 void ParserTremoloUnitTest::tearDown() {
     91void ParserTremoloUnitTest::tearDown()
     92{
     93  delete parser;
    9394  ChangeTracker::purgeInstance();
    9495  World::purgeInstance();
     
    99100void ParserTremoloUnitTest::readTremoloPreliminaryCommentsTest() {
    100101  cout << "Testing the tremolo parser." << endl;
    101   TremoloParser* testParser = new TremoloParser();
    102102  stringstream input, output;
    103103
     
    105105  {
    106106    input << Tremolo_Atomdata1;
    107     testParser->load(&input);
    108     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    109     testParser->save(&output, atoms);
     107    parser->load(&input);
     108    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
     109    parser->save(&output, atoms);
    110110//    std::cout << output.str() << std::endl;
    111111//    std::cout << Tremolo_Atomdata1 << std::endl;
     
    118118  {
    119119    input << Tremolo_Atomdata2;
    120     testParser->load(&input);
    121     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    122     testParser->save(&output, atoms);
     120    parser->load(&input);
     121    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
     122    parser->save(&output, atoms);
    123123    std::cout << output.str() << std::endl;
    124124    CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
     
    129129  // Invalid key in Atomdata line
    130130  input << Tremolo_invalidkey;
    131   testParser->load(&input);
     131  parser->load(&input);
    132132  //TODO: prove invalidity
    133133  input.clear();
     
    135135
    136136void ParserTremoloUnitTest::readTremoloCoordinatesTest() {
    137   TremoloParser* testParser = new TremoloParser();
    138137  stringstream input;
    139138
    140139  // One simple data line
    141140  input << Tremolo_Atomdata2;
    142   testParser->load(&input);
     141  parser->load(&input);
    143142  CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0);
    144143  input.clear();
     
    146145
    147146void ParserTremoloUnitTest::readTremoloVelocityTest() {
    148   TremoloParser* testParser = new TremoloParser();
    149147  stringstream input;
    150148
    151149  // One simple data line
    152150  input << Tremolo_velocity;
    153   testParser->load(&input);
     151  parser->load(&input);
    154152  CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->getAtomicVelocity()[0] == 3.0);
    155153  input.clear();
     
    157155
    158156void ParserTremoloUnitTest::readTremoloNeighborInformationTest() {
    159   TremoloParser* testParser = new TremoloParser();
    160157  stringstream input;
    161158
    162159  // Neighbor data
    163160  input << Tremolo_neighbours;
    164   testParser->load(&input);
     161  parser->load(&input);
    165162
    166163  CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
     
    171168
    172169void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() {
    173   TremoloParser* testParser = new TremoloParser();
    174170  stringstream input, output;
    175171
     
    177173  {
    178174    input << Tremolo_improper;
    179     testParser->load(&input);
    180     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    181     testParser->save(&output, atoms);
     175    parser->load(&input);
     176    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
     177    parser->save(&output, atoms);
    182178    CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
    183179    std::cout << output.str() << std::endl;
     
    189185
    190186void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() {
    191   TremoloParser* testParser = new TremoloParser();
    192187  stringstream input, output;
    193188
     
    195190  {
    196191    input << Tremolo_torsion;
    197     testParser->load(&input);
    198     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    199     testParser->save(&output, atoms);
     192    parser->load(&input);
     193    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
     194    parser->save(&output, atoms);
    200195    CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
    201196    std::cout << output.str() << std::endl;
     
    207202
    208203void ParserTremoloUnitTest::writeTremoloTest() {
    209   TremoloParser* testParser = new TremoloParser();
    210204  stringstream output;
    211205
     
    214208    atom* newAtom = World::getInstance().createAtom();
    215209    newAtom->setType(1);
    216     testParser->setFieldsForSave("x=3 u=3 F stress Id neighbors=5 imprData GroupMeasureTypeNo type extType name resName chainID resSeq occupancy tempFactor segID Charge charge GrpTypeNo torsion");
    217     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    218     testParser->save(&output, atoms);
     210    parser->setFieldsForSave("x=3 u=3 F stress Id neighbors=5 imprData GroupMeasureTypeNo type extType name resName chainID resSeq occupancy tempFactor segID Charge charge GrpTypeNo torsion");
     211    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
     212    parser->save(&output, atoms);
    219213    CPPUNIT_ASSERT(output.str() == Tremolo_full);
    220214  }
     
    222216  cout << "testing the tremolo parser is done" << endl;
    223217}
     218
  • src/Parser/unittests/ParserTremoloUnitTest.hpp

    r9a6b76e r765f16  
    1313#endif
    1414
     15#include "Parser/TremoloParser.hpp"
    1516
    1617#include <cppunit/extensions/HelperMacros.h>
     
    4041  void readAndWriteTremoloTorsionInformationTest();
    4142  void writeTremoloTest();
     43
     44private:
     45  FormatParser<tremolo> *parser;
    4246};
    4347
  • src/Parser/unittests/ParserXyzUnitTest.cpp

    r9a6b76e r765f16  
    2424#include <cppunit/ui/text/TestRunner.h>
    2525
    26 #include "Parser/XyzParser.hpp"
    2726#include "World.hpp"
    2827#include "atom.hpp"
     
    3130#include "CodePatterns/Log.hpp"
    3231#include "Descriptors/AtomTypeDescriptor.hpp"
     32#include "Parser/ChangeTracker.hpp"
     33#include "Parser/XyzParser.hpp"
    3334
    3435#ifdef HAVE_TESTRUNNER
     
    6263  World::getInstance();
    6364
     65  parser = new FormatParser<xyz>();
     66
    6467  setVerbosity(2);
    6568
     
    6972}
    7073
    71 void ParserXyzUnitTest::tearDown() {
     74void ParserXyzUnitTest::tearDown()
     75{
     76  delete parser;
    7277  ChangeTracker::purgeInstance();
    7378  World::purgeInstance();
     
    7883void ParserXyzUnitTest::rewriteAnXyzTest() {
    7984  cout << "Testing the XYZ parser." << endl;
    80   XyzParser* testParser = new XyzParser();
    8185  stringstream input;
    8286  input << waterXyz;
    83   testParser->load(&input);
     87  parser->load(&input);
    8488  input.clear();
    8589
     
    9094    stringstream output;
    9195    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    92     testParser->save(&output, atoms);
     96    parser->save(&output, atoms);
    9397    input << output.str();
    94     testParser->load(&input);
     98    parser->load(&input);
    9599  }
    96100
     
    115119void ParserXyzUnitTest::readMultiXyzTest() {
    116120  cout << "Testing the multi time step XYZ parser." << endl;
    117   XyzParser* testParser = new XyzParser();
    118121  stringstream input;
    119122  input << waterMultiXyz;
    120   testParser->load(&input);
     123  parser->load(&input);
    121124  input.clear();
    122125
     
    130133
    131134void ParserXyzUnitTest::writeMultiXyzTest() {
    132   XyzParser* testParser = new XyzParser();
    133135  stringstream input;
    134136  input << waterMultiXyz;
    135   testParser->load(&input);
     137  parser->load(&input);
    136138  input.clear();
    137139
     
    143145    stringstream output;
    144146    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    145     testParser->save(&output, atoms);
     147    parser->save(&output, atoms);
    146148    input << output.str();
    147     testParser->load(&input);
     149    parser->load(&input);
    148150  }
    149151
  • src/Parser/unittests/ParserXyzUnitTest.hpp

    r9a6b76e r765f16  
    1313#endif
    1414
     15#include "Parser/XyzParser.hpp"
    1516
    1617#include <cppunit/extensions/HelperMacros.h>
     
    3233  void readMultiXyzTest();
    3334  void writeMultiXyzTest();
     35
     36private:
     37  FormatParser<xyz> *parser;
    3438};
    3539
  • src/moleculelist.cpp

    r9a6b76e r765f16  
    626626//      atoms.resize((*ListRunner)->getAtomCount());
    627627//      std::copy((*ListRunner)->begin(), (*ListRunner)->end(), atoms.begin());
    628       FormatParserStorage::getInstance().getParser<MpqcParser>().save(&outfile, atoms);
     628      FormatParserStorage::getInstance().get(mpqc).save(&outfile, atoms);
    629629//      if ((intermediateResult = World::getInstance().getConfig()->SaveMPQC(FragmentName.c_str(), (*ListRunner))))
    630630        output << " done.";
Note: See TracChangeset for help on using the changeset viewer.