Commit 999768a3 authored by Johnny Jazeix's avatar Johnny Jazeix
Browse files

No commit message

No commit message
parent 9af21b33
......@@ -3,36 +3,35 @@
// string buffer;
int Line::starttoken(unsigned int cursor,std::string&line){
while(line[cursor]==' ')
cursor ++;
return cursor;
}
int Line::stopnexttoken(unsigned int cursor,std::string&line){
if (line[cursor]!='"'){
while(line[cursor]!='"' || line[cursor]!='\n' || line[cursor]!='\0')
cursor ++;
return cursor;
}
else{
while(line[cursor]!=' ' || line[cursor]!='\n' || line[cursor]!='\0')
while(line[cursor]==' ')
cursor ++;
return cursor;
}
}
bool Line::store(std::ifstream &file){
if (file.eof())
return false;
char buffer[BUFFSIZE];
file.getline(buffer, BUFFSIZE);
std::string line = buffer;
store(line);
return true;
int Line::stopnexttoken(unsigned int cursor,std::string&line){
if (line[cursor]!='"'){
while(line[cursor]!='"' || line[cursor]!='\n' || line[cursor]!='\0')
cursor ++;
return cursor;
}
else{
while(line[cursor]!=' ' || line[cursor]!='\n' || line[cursor]!='\0')
cursor ++;
return cursor;
}
}
bool Line::store(std::ifstream &file){
if(!file.eof()){
char buffer[BUFFSIZE];
file.getline(buffer, BUFFSIZE);
std::string line = buffer;
store(line);
return true;
}
else // It is the end of the file
return false;
}
void Line::store(std::string &s){
......@@ -41,15 +40,14 @@ void Line::store(std::string &s){
int start;
int stop;
while(cursor<s.length())
{
start = starttoken(cursor,s);
cursor = start;
stop = stopnexttoken(cursor,s);
stop = cursor;
tokens.push_back(s.substr(start,stop));
}
while(cursor<s.length()){
start = starttoken(cursor, s);
cursor = start;
stop = stopnexttoken(cursor, s);
stop = cursor;
_tokens.push_back(s.substr(start,stop));
}
}
......@@ -64,10 +62,8 @@ Line::Line(Line &){}
Line::~Line(){}
bool Line::starts_with(std::string & s)
{
return tokens[0].compare(s)==0;
bool Line::starts_with(const std::string & s) const{
return _tokens[0].compare(s)==0;
}
......@@ -75,33 +71,32 @@ Line::~Line(){}
bool Line::operator== (std::string &s)
{
bool Line::operator== (std::string &s){
Line l;
l.store(s);
return (*this == l);
}
bool Line::operator== (Line &l)
{
if ((*this).length()==l.length())
{
for (int i = 0 ; i < length() ; i ++)
if (item(i)==l.item(i))
return false;
return true;
}
bool Line::operator== (Line &l){
int size_of_this_line = length();
if (size_of_this_line == l.length()){
for (int i = 0 ; i < size_of_this_line ; i ++)
if (item(i) == l.item(i))
return false;
return true;
}
else
return false;
}
std::string& Line::item (int i ){return tokens[i];}
std::string &Line::item (int i){
return _tokens[i];
}
int Line::length(){
return tokens.size();
return _tokens.size();
}
#ifndef LINE_HPP
#define LINE_HPP
#include <fstream>
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#define BUFFSIZE 256
/*! \class Line Line.hpp "../parser/src/Line.hpp"
......@@ -13,12 +15,10 @@
class Line{
private:
std::vector<std::string> tokens;
int Line::starttoken(unsigned int cursor,std::string&);
int Line::stopnexttoken(unsigned int cursor,std::string&);
std::vector<std::string> _tokens;
int Line::starttoken(unsigned int cursor, std::string &);
int Line::stopnexttoken(unsigned int cursor, std::string &);
/*!
......@@ -50,27 +50,29 @@ public:
* \param : the string we want to know if the line starts with it
* \return : true if the line starts with the param, false else
*/
bool starts_with(std::string &);
bool starts_with(const std::string &) const;
/*!
* \brief store() read the next line and divide into tokens
*
*/
bool store(std::ifstream &);
void store(std::string &);
bool store(std::ifstream &);
void store(std::string &);
/*!
* \brief line compare
*
*/
bool operator== (std::string &);
bool operator== (std::string &); // on peut pas utiliser une référence sinon ca bugue : ParserDefinitionDecoder.cpp:26: erreur: no match for «operator==» in «line == "%EndEventDef"»
bool Line::operator== (Line &l);
/*!
* \brief the ith token in the line
*
*/
std::string& item (int i );
std::string& item (int i);
......
......@@ -14,7 +14,7 @@ public:
* \param : the name of the file to parse
* \param : the structure of data to fill
*/
virtual void parse(string filename) = 0;
virtual void parse(std::string filename, Trace &trace) = 0;
};
......
#include "ParserDefinitionDecoder.hpp"
using namespace std;
int ParserDefinitionDecoder::definitions_number(){
return _definitions.size();
return _definitions.size();
}
void ParserDefinitionDecoder::store_definition(Line &line, ifstream &file){
//read the definition header
line.store(file);
string& definition_name = line.item(2);
//read the definition header
line.store(file);
string& definition_name = line.item(2);
//string& definition_identity = line.item(3);
const char *definition_identity_string= line.item(3).data();
int definition_identity = atoi(definition_identity_string);
//store this header
// Definition current_definition = Definition(definition_name);
// _definitions[definition_identity] = current_definition;
//store this header
Definition current_definition = Definition(definition_name);
_definitions.insert(pair<int,Definition>(definition_identity,current_definition));
std::string field_type;
std::string field_value;
//read and store the parameters list
std::string final = "%EndEventDef";
while (line.store(file))
{
if(line.operator==( final))
break;
string field_type;
string field_value;
if (line.length()!=3)//verifier le % au lieu de tester le nombre de token
//ajouter un warning vers l'interface
;
//read and store the parameters list
string final = "%EndEventDef";
while (line.store(file)){
if(line == final)
break;
if (line.length()!=3)//verifier le % au lieu de tester le nombre de token
//ajouter un warning vers l'interface
;
field_type = line.item(1);
field_value = line.item(2);
current_definition.store(field_type, field_value);
field_type = line.item(1);
field_value = line.item(2);
current_definition.store(field_type, field_value);
}
}
Definition& ParserDefinitionDecoder::get_definition(int i){
return _definitions[i];
return _definitions[i];
}
......@@ -21,7 +21,7 @@ private:
Type convert(String type, String value);
public:
sort_definition(Definition,ligne);
void sort_definition(Definition,ligne);
......
#include "ParserPaje.hpp"
using namespace std;
void ParserPaje::parse(string filename, Trace &trace){
// We open the file in read only
ifstream file(filename.c_str(), ios::in);
// We check if the file has been opened
if(!file){
cerr << "Unable to open : " << filename << endl;
return ;
}
Line l;
while(!file.eof()){
// We store the first line of the file
l.store(file);
if(l.starts_with("%")){
// We have a new definition
_parser_definition_decoder.store_definition(l, file);
}
else{
// We have a new event
_parser_event_decoder;
trace;
}
}
file.close();
}
......@@ -2,6 +2,9 @@
#define PARSERPAJE_HPP
#include <string>
#include "../../structureDonnee/trace.hpp"
#include "ParserDefinitionDecoder.hpp"
#include "ParserEventDecoder.hpp"
/*!
*
......@@ -9,11 +12,11 @@
* \brief parse the format of Paje.
*
*/
class ParserPaje : public Parser{
class ParserPaje : public Parser {
private:
ParserEventDecoder parser_event_decoder;
ParserDefinitionDecoder parser_definition_decoder;
ParserEventDecoder _parser_event_decoder;
ParserDefinitionDecoder _parser_definition_decoder;
public:
/*!
......@@ -21,9 +24,8 @@ public:
* \param : the name of the file to parse
* \param : the structure of data to fill
*/
void parse(std::string filename);
void parse(std::string filename, Trace &trace);
};
#endif // PARSERPAJE_HPP
......@@ -267,4 +267,4 @@ public :
*/
const list<Container *> get_root_containers() const;
}//end class
};//end class
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment