From 947022127d0a53a6a436205cbafe4e7207938de4 Mon Sep 17 00:00:00 2001 From: Christian Vazquez Date: Sat, 28 May 2011 17:26:04 +0000 Subject: Corrigé quelques erreurs du parser. déplacé 'simulation.xml' dans dossier 'test'. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Créé le fichier 'simulationTest.cc' qui ne marche pas du tout. --- src/main/Makefile | 2 +- src/main/Parser.cc | 401 +++++++++++++++++++-------------------------- src/main/Parser.h | 2 +- src/main/simulation.xml | 180 -------------------- src/test/simulation.xml | 180 ++++++++++++++++++++ src/test/simulationTest.cc | 2 +- 6 files changed, 348 insertions(+), 419 deletions(-) delete mode 100644 src/main/simulation.xml create mode 100644 src/test/simulation.xml diff --git a/src/main/Makefile b/src/main/Makefile index 4c0ac06..0ba6a5e 100644 --- a/src/main/Makefile +++ b/src/main/Makefile @@ -16,7 +16,7 @@ LOCALDIR = main LOCALOBJS = Vector3D.o Particle.o Printable.o Element.o CurvedElement.o StraightElement.o \ CompositeElement.o Dipole.o Quadrupole.o FODO.o ElementVisitor.o Cloneable.o \ Accelerator.o exceptions.o Beam.o SingleBeam.o CircularBeam.o \ - random.o Bunch.o events.o Interactor.o BruteForceInteractor.o + random.o Bunch.o events.o Interactor.o BruteForceInteractor.o Parser.o OBJS=$(addprefix $(BINDIR)/$(LOCALDIR)/,$(LOCALOBJS)) .PHONY = all checkdirs lib diff --git a/src/main/Parser.cc b/src/main/Parser.cc index 0331c4c..fa14fb7 100644 --- a/src/main/Parser.cc +++ b/src/main/Parser.cc @@ -4,9 +4,10 @@ * Created on: 11 mai 2011 * Author: christian */ -#include +#include #include #include "Parser.h" +#include "exceptions.h" using namespace std; @@ -15,81 +16,81 @@ namespace vhc { //===========================================balises ouvrantes========================================================================== //balises ouvrantes d'un système -static tag Parser::system = ""; -static tag Parser::accelerator =""; -static tag Parser::comment = ""; +tag Parser::systemCl = "<\System>"; +tag Parser::acceleratorCl ="<\Accelerator>"; +tag Parser::commentCl = "-->"; //balises fermantes d'une particule -static tag Parser::particleCl ="<\Particle>"; -static tag Parser::positionCl = "<\Position>"; -static tag Parser::massCl = "<\Mass>"; -static tag Parser::chargeCl = "<\Charge>"; -static tag Parser::energyCl = "<\Energy>"; -static tag Parser::directionCl = "<\Direction>"; +tag Parser::particleCl ="<\Particle>"; +tag Parser::positionCl = "<\Position>"; +tag Parser::massCl = "<\Mass>"; +tag Parser::chargeCl = "<\Charge>"; +tag Parser::energyCl = "<\Energy>"; +tag Parser::directionCl = "<\Direction>"; //balises fermantes d'un Element -static tag Parser::entryPosCl = "<\EntryPosition>"; -static tag Parser::exitPosCl = "<\ExitPosition>"; -static tag Parser::sectionRadiusCl = "<\SectionRadius>"; +tag Parser::entryPosCl = "<\EntryPosition>"; +tag Parser::exitPosCl = "<\ExitPosition>"; +tag Parser::sectionRadiusCl = "<\SectionRadius>"; //balises fermantes d'un Dipole -static tag Parser::dipoleCl ="<\Dipole>"; -static tag Parser::curvatureCl = "<\Curvature>"; -static tag Parser::magneticFieldCl = "<\MagneticField"; +tag Parser::dipoleCl ="<\Dipole>"; +tag Parser::curvatureCl = "<\Curvature>"; +tag Parser::magneticFieldCl = "<\MagneticField"; //balise fermantes commune aux quadrupoles et aux fodo -static tag Parser::focCoeffCl = "<\FocalizingCoefficient>"; +tag Parser::focCoeffCl = "<\FocalizingCoefficient>"; //balises fermantes d'une FODO -static tag Parser::fodoCl ="<\FODO>"; -static tag Parser::straightLengthCl = "<\StraightLenght>"; +tag Parser::fodoCl ="<\FODO>"; +tag Parser::straightLengthCl = "<\StraightLenght>"; //balises fermantes d'un Quadrupole -static tag Parser::quadrupoleCl ="<\Quadrupole>"; +tag Parser::quadrupoleCl ="<\Quadrupole>"; //balises fermantes d'un StraightElement -static tag Parser::straightElementCl ="<\StraightElement>"; +tag Parser::straightElementCl ="<\StraightElement>"; //===========================================================création et renvoi d'un accélérateur======================================= -Parser::extract() { +Accelerator* Parser::extract() { Accelerator* acc = new Accelerator; @@ -100,10 +101,10 @@ Parser::extract() { entry.open(nameOfFile.c_str()); //teste si l'association a bien pu se faire - if(not entry.fail()){ + if(! entry.fail()){ //Tant qu'on n'est pas arrivé à la fin du fichier, on continue à le lire - while(not file.eof()){ + while(! entry.eof()){ //tout se fait depuis ici readFile(entry, *acc); @@ -121,39 +122,33 @@ Parser::extract() { } //===========================================================lecture du fichier .xml==================================================== -Parser::readFile(ifstream& file, Accelerator& acc){ +void Parser::readFile(ifstream& file, Accelerator& acc){ try { - + tag tmp1; // on lit la balise qu'on doit traiter - tag tmp1 = readOneTag(file); + tmp1=readOneTag(file); /*on teste si tmp1 correspond à une des balises suivantes : * - soit system * - soit un commentaire * - sinon il y a un problème car on ne s'attend pas à autre chose à ce niveau-là */ - switch(tmp1){ - - case system : + if(tmp1 == system){ readSystem(file, acc); closingTag(file, systemCl); - break; - case comment : + }else if(tmp1 == comment){ jumpComment(file); - break; - + } /* si la variable tmp1 ne contient pas les balises voulues, c'est qu'une valeur * (celle contenue par la variable tmp1 donc) * n'a pas été récupérée comme il faut. */ - default: - + else{ throw ReadException("Values found outside of following tags : "+system+ "\n Value is : "+tmp1); - break; } } @@ -163,7 +158,7 @@ Parser::readFile(ifstream& file, Accelerator& acc){ } //==============================================================lecture de la balise system============================================= -Parser::readSystem(ifstream& file, Accelerator& acc){ +void Parser::readSystem(ifstream& file, Accelerator& acc){ try { @@ -175,29 +170,23 @@ Parser::readSystem(ifstream& file, Accelerator& acc){ * - soit un commentaire * - sinon il y a un problème car on ne s'attend pas à autre chose à ce niveau-là */ - switch(tmp2){ - - case accelerator : + if(tmp2==accelerator){ buildAccelerator(file, acc); - break; - case comment : + }else if(tmp2==comment){ jumpComment(file); - break; - + } /* si la variable tmp2 ne contient pas les balises voulues, c'est qu'une valeur * (celle contenue par la variable tmp2 donc) * n'a pas été récupérée comme il faut. */ - default: - + else{ throw ReadException("Values found outside of following tags : "+accelerator+ "\n Value is : "+tmp2); - break; } - } + }//try catch(Exception const& ex){ cout<>ws; double tmp; + file>>ws; file>>tmp; return tmp; } @@ -691,7 +618,7 @@ double Parser::readOneDouble(ifstream& file){ void Parser::readComma(ifstream& file){ char trash; file>>ws; - file>>trash; + file.get(trash); } //===========================================================lecture moléculaire======================================================== @@ -712,34 +639,36 @@ Vector3D Parser::readVector3D(ifstream& file){ tag Parser::readOneTag(ifstream& file){ tag tmp; file>>ws; - file>>tag; + getline(file, tmp); return tmp; } /** Cf. header. */ void Parser::closingTag(ifstream& file, std::string ta){ tag tmp; + size_t found; file>>ws; - file>>tmp; + getline(file,tmp); //si on a pas de balise fermante (ici il devrait il y en avoir normalement une) alors on lance une exception found=tmp.find(ta); - if(found() == string::npos) - throw ReadExceptionMessage("No closing tag "+ta+" found."); + if(found == string::npos) + throw ReadException("No closing tag "+ta+" found."); } //===========================================================lecture commentaire======================================================== /**Cf. header. */ void Parser::jumpComment(ifstream& file){ tag tmp; + size_t found; do{ file>>ws; - file>>tmp; + getline(file,tmp); found=tmp.find("-->"); } - while(found() == string::npos); + while(found == string::npos); if(file.eof()) - throw ReadExceptionMessage("No closing tag for comment found."); + throw ReadException("No closing tag for comment found."); } diff --git a/src/main/Parser.h b/src/main/Parser.h index 12ff5a5..ce9e31e 100644 --- a/src/main/Parser.h +++ b/src/main/Parser.h @@ -149,7 +149,7 @@ private: /** Ajoute les différents éléments et particules du fichier dans l'Accelerator passé en argument. * @param file fichier à lire * @param acc référence sur un Accelerator déjà construit */ - void buildAccelerator(ifstream& file, Accelerator const& acc); + void buildAccelerator(ifstream& file, Accelerator& acc); /** Construction d'une nouvelle Particle. * @param file fichier à lire diff --git a/src/main/simulation.xml b/src/main/simulation.xml deleted file mode 100644 index 61e4173..0000000 --- a/src/main/simulation.xml +++ /dev/null @@ -1,180 +0,0 @@ - - - - - 3.01,0,0 - <\Position> - - 1 - <\Mass> - - - 1 - <\Charge> - - - 0,-1,0 - <\Direction> - - 2 - <\Energy> - - <\Particle> - - - 2.99,0,0 - <\Position> - - 1 - <\Mass> - - - 1 - <\Charge> - - - 0,-1,0 - <\Direction> - - 2 - <\Energy> - - <\Particle> - - - 3,2,0 - <\EntryPosition> - - 3,-2,0 - <\ExitPosition> - - 0.2 - <\SectionRadius> - - 1. - <\StraightLenght> - - 1.2 - <\FocalizingCoefficient> - <\FODO> - - - 3,-2,0 - <\EntryPosition> - - 2,-3,0 - <\ExitPosition> - - 0.1 - <\SectionRadius> - - 1. - <\Curvature> - - 0,0,5.89158 - <\MagneticField> - <\Dipole> - - - 2,-3,0 - <\EntryPosition> - - -2,-3,0 - <\ExitPosition> - - 0.2 - <\SectionRadius> - - 1. - <\StraightLenght> - - 1.2 - <\FocalizingCoefficient> - <\FODO> - - - -2,-3,0 - <\EntryPosition> - - -3,-2,0 - <\ExitPosition> - - 0.1 - <\SectionRadius> - - 1. - <\Curvature> - - 0,0,5.89158 - <\MagneticField> - <\Dipole> - - - -3,-2,0 - <\EntryPosition> - - -3,2,0 - <\ExitPosition> - - 0.2 - <\SectionRadius> - - 1. - <\StraightLenght> - - 1.2 - <\FocalizingCoefficient> - <\FODO> - - - -3,2,0 - <\EntryPosition> - - -2,3,0 - <\ExitPosition> - - 0.1 - <\SectionRadius> - - 1. - <\Curvature> - - 0,0,5.89158 - <\MagneticField> - <\Dipole> - - - -2,3,0 - <\EntryPosition> - - 2,3,0 - <\ExitPosition> - - 0.2 - <\SectionRadius> - - 1. - <\StraightLenght> - - 1.2 - <\FocalizingCoefficient> - <\FODO> - - - 2,3,0 - <\EntryPosition> - - 3,2,0 - <\ExitPosition> - - 0.1 - <\SectionRadius> - - 1. - <\Curvature> - - 0,0,5.89158 - <\MagneticField> - <\Dipole> - <\Accelerator> -<\System> \ No newline at end of file diff --git a/src/test/simulation.xml b/src/test/simulation.xml new file mode 100644 index 0000000..61e4173 --- /dev/null +++ b/src/test/simulation.xml @@ -0,0 +1,180 @@ + + + + + 3.01,0,0 + <\Position> + + 1 + <\Mass> + + + 1 + <\Charge> + + + 0,-1,0 + <\Direction> + + 2 + <\Energy> + + <\Particle> + + + 2.99,0,0 + <\Position> + + 1 + <\Mass> + + + 1 + <\Charge> + + + 0,-1,0 + <\Direction> + + 2 + <\Energy> + + <\Particle> + + + 3,2,0 + <\EntryPosition> + + 3,-2,0 + <\ExitPosition> + + 0.2 + <\SectionRadius> + + 1. + <\StraightLenght> + + 1.2 + <\FocalizingCoefficient> + <\FODO> + + + 3,-2,0 + <\EntryPosition> + + 2,-3,0 + <\ExitPosition> + + 0.1 + <\SectionRadius> + + 1. + <\Curvature> + + 0,0,5.89158 + <\MagneticField> + <\Dipole> + + + 2,-3,0 + <\EntryPosition> + + -2,-3,0 + <\ExitPosition> + + 0.2 + <\SectionRadius> + + 1. + <\StraightLenght> + + 1.2 + <\FocalizingCoefficient> + <\FODO> + + + -2,-3,0 + <\EntryPosition> + + -3,-2,0 + <\ExitPosition> + + 0.1 + <\SectionRadius> + + 1. + <\Curvature> + + 0,0,5.89158 + <\MagneticField> + <\Dipole> + + + -3,-2,0 + <\EntryPosition> + + -3,2,0 + <\ExitPosition> + + 0.2 + <\SectionRadius> + + 1. + <\StraightLenght> + + 1.2 + <\FocalizingCoefficient> + <\FODO> + + + -3,2,0 + <\EntryPosition> + + -2,3,0 + <\ExitPosition> + + 0.1 + <\SectionRadius> + + 1. + <\Curvature> + + 0,0,5.89158 + <\MagneticField> + <\Dipole> + + + -2,3,0 + <\EntryPosition> + + 2,3,0 + <\ExitPosition> + + 0.2 + <\SectionRadius> + + 1. + <\StraightLenght> + + 1.2 + <\FocalizingCoefficient> + <\FODO> + + + 2,3,0 + <\EntryPosition> + + 3,2,0 + <\ExitPosition> + + 0.1 + <\SectionRadius> + + 1. + <\Curvature> + + 0,0,5.89158 + <\MagneticField> + <\Dipole> + <\Accelerator> +<\System> \ No newline at end of file diff --git a/src/test/simulationTest.cc b/src/test/simulationTest.cc index b9ac1a4..485e3d3 100644 --- a/src/test/simulationTest.cc +++ b/src/test/simulationTest.cc @@ -14,7 +14,7 @@ using namespace vhc; int main(){ try{ - Parser pars("simulation.xml"); + Parser pars("./simulation.xml"); Accelerator* a = pars.extract(); -- cgit v1.2.3