From 70d3a283b68a0b3b1928e9d8ff728f20988ff894 Mon Sep 17 00:00:00 2001 From: Christian Vazquez Date: Sun, 29 May 2011 10:56:33 +0000 Subject: Mis à jour le parser. Renommé et déplacé le fichier ParserTest.cc Renommé et déplacé le fichier accelerator.xml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/Parser.cc | 58 ++++++++++----- src/test/ParserTest.cc | 37 ++++++++++ src/test/accelerator.xml | 180 +++++++++++++++++++++++++++++++++++++++++++++ src/test/simulation.xml | 180 --------------------------------------------- src/test/simulationTest.cc | 32 -------- 5 files changed, 257 insertions(+), 230 deletions(-) create mode 100644 src/test/ParserTest.cc create mode 100644 src/test/accelerator.xml delete mode 100644 src/test/simulation.xml delete mode 100644 src/test/simulationTest.cc diff --git a/src/main/Parser.cc b/src/main/Parser.cc index fa14fb7..f6f60a8 100644 --- a/src/main/Parser.cc +++ b/src/main/Parser.cc @@ -5,6 +5,7 @@ * Author: christian */ #include +#include #include #include "Parser.h" #include "exceptions.h" @@ -606,19 +607,22 @@ StraightElement* Parser::buildStraightElement(ifstream& file){ //=======================================================lecture atomique=============================================================== /** Cf. header. */ -//TODO lire un double double Parser::readOneDouble(ifstream& file){ + double tmp; + char ex('x'); + string str; file>>ws; - file>>tmp; - return tmp; -} -/** Cf. header. */ -void Parser::readComma(ifstream& file){ - char trash; - file>>ws; - file.get(trash); + do{ + file.get(ex); + str=str+ex; + + }while(ex != '<' && ','); + + istringstream is(str); + is>>tmp; + return tmp; } //===========================================================lecture moléculaire======================================================== @@ -626,29 +630,46 @@ void Parser::readComma(ifstream& file){ Vector3D Parser::readVector3D(ifstream& file){ double x = readOneDouble(file); - readComma(file); double y = readOneDouble(file); - readComma(file); double z = readOneDouble(file); - file>>ws; return Vector3D(x,y,z); } /** Cf. header. */ tag Parser::readOneTag(ifstream& file){ - tag tmp; - file>>ws; - getline(file, tmp); + + tag tmp("<"); + char ex('x'); + + /* Lecture caractère par caractère du flot, et remplissage au fur et à mesure de la string, + * jusqu'à la fin de la balise. */ + do{ + file>>ws; + file.get(ex); + tmp=tmp+ex; + + }while(ex != '>'); + return tmp; } /** Cf. header. */ void Parser::closingTag(ifstream& file, std::string ta){ - tag tmp; + + tag tmp("<"); + char ex('x'); size_t found; - file>>ws; - getline(file,tmp); + + /* Lecture caractère par caractère du flot, et remplissage au fur et à mesure de la string, + * jusqu'à la fin de la balise. */ + do{ + file>>ws; + file.get(ex); + tmp=tmp+ex; + + }while(ex != '>'); + //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) @@ -657,6 +678,7 @@ void Parser::closingTag(ifstream& file, std::string ta){ //===========================================================lecture commentaire======================================================== /**Cf. header. */ void Parser::jumpComment(ifstream& file){ + tag tmp; size_t found; diff --git a/src/test/ParserTest.cc b/src/test/ParserTest.cc new file mode 100644 index 0000000..42a0c3e --- /dev/null +++ b/src/test/ParserTest.cc @@ -0,0 +1,37 @@ +/* + * simulationTest.cc + * + * Created on: 28 mai 2011 + * Author: christian + */ +#include +#include "Parser.h" +#include "Accelerator.h" +#include "exceptions.h" + +using namespace std; +using namespace vhc; + +/* Ne marche pas. L'ouverture du fichier est impossible. + * Pourtant j'ai essayé en exercice le même bout de code + * [ que dans la méthode extract() ] pour ouvrir un fichier, et ça marchait.... + * Je suspecte un problème avec la makefile.*/ + +int main(){ + try{ + Parser pars("./accelerator.xml"); + + Accelerator* a = pars.extract(); + + cout<< *a <clear(); + + delete a; + } + catch(Exception const& ex){ + cout< + + + + 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 deleted file mode 100644 index 61e4173..0000000 --- a/src/test/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/simulationTest.cc b/src/test/simulationTest.cc deleted file mode 100644 index 485e3d3..0000000 --- a/src/test/simulationTest.cc +++ /dev/null @@ -1,32 +0,0 @@ -/* - * simulationTest.cc - * - * Created on: 28 mai 2011 - * Author: christian - */ -#include -#include "Parser.h" -#include "Accelerator.h" -#include "exceptions.h" - -using namespace std; -using namespace vhc; - -int main(){ - try{ - Parser pars("./simulation.xml"); - - Accelerator* a = pars.extract(); - - cout<< *a <clear(); - - delete a; - } - catch(Exception const& ex){ - cout<