Commit 8a87996b authored by Johnny Jazeix's avatar Johnny Jazeix
Browse files

suppression des ^M + application des normes de codage

parent 0acd7941
#include "Line.hpp"
#include "Line.hpp"
using namespace std;
Line::Line(){}
Line::Line(Line &){}
Line::Line(string &filename){
source.open(filename.c_str());
_eof = false;
}
Line::Line(const char *filename){
source.open(filename);
_eof = false;
}
Line::Line(){}
void Line::print()
{
cout << "-" ;
for(unsigned int i = 0 ; i < _tokens.size() ; i ++)
cout << _tokens[i] << " " ;
cout << "-" <<endl ;
Line::Line(Line &){}
Line::Line(std::string& filename){
source.open(filename.c_str());
_eof = false;
}
Line::Line(const char* filename){
source.open(filename);
_eof = false;
}
void Line::print()
{
std::cout << "-" ;
for(int i=0;i<_tokens.size();i++)
std::cout << _tokens[i] << " " ;
std::cout << "-" <<endl ;
}
Line::~Line(){}
bool Line::starts_with(const std::string & s) const{
bool Line::starts_with(const string & s) const{
return _tokens[0] == s;
}
/*
bool Line::operator== (Line &l){
int size_of_this_line = length();
......@@ -52,15 +48,15 @@ bool Line::operator== (Line &l){
else
return false;
}
*/
*/
bool Line::item (int i,std::string &e){
if (i>=_tokens.size())
bool Line::item (int i, string &e){
if (i >= _tokens.size())
return false;
e = _tokens[i];
e = _tokens[i];
return true;
}
......@@ -72,28 +68,28 @@ int Line::length(){
void Line::clear()
{
_tokens.clear();
}
bool Line::eof(){
return _eof;
}
void Line::newline(){
clear();
char * tok;
std::string str;
while ((tok=source.lire_token())!=NULL){
str.assign(tok);
if (str == "\n")
return;
_tokens.push_back(str);
}
_eof=true;
}
bool Line::eof(){
return _eof;
}
void Line::newline(){
clear();
char *tok;
string str;
while ((tok=source.lire_token()) != NULL){
str.assign(tok);
if (str == "\n")
return;
_tokens.push_back(str);
}
_eof=true;
}
#include "ParserDefinitionDecoder.hpp"
#define OUT_A_DEFINITION 309480394
#define IN_A_DEFINITION 309480392
#define OUT_A_DEFINITION 309480394
#define IN_A_DEFINITION 309480392
using namespace std;
ParserDefinitionDecoder::ParserDefinitionDecoder(){
_state = OUT_A_DEFINITION;
}
ParserDefinitionDecoder::ParserDefinitionDecoder(){
_state = OUT_A_DEFINITION;
}
int ParserDefinitionDecoder::definitions_number(){
return _definitions.size();
}
void ParserDefinitionDecoder::store_definition(Line &line){
std::string first_token;
if (!line.item(1,first_token))
{
std::cout << "error : a definition line is empty" << endl;
return;
}
if (first_token == "EventDef"){
if (_state == IN_A_DEFINITION){
std::cout << "expected %EndDef" << endl;
return;
}
std::string definition_name;
if (!line.item(2,definition_name)){
std::cout << "a definition has no name" << endl;
return;
}
int definition_identity;
std::string definition_identity_string;
if (!line.item(3,definition_identity_string)){
std::cout<<"definition has no identifier"<<endl;
return;
}
if (sscanf(definition_identity_string.c_str(),"%d",&definition_identity)!=1){
std::cout<<"expected identifier for a definition"<<endl;
return;}
Definition current_definition = Definition(definition_name);
_definitions.insert(pair<int,Definition>(definition_identity, current_definition));
_current_definition = definition_identity;
if (line.length()>4){
std::cout<<"warning extra token in %EvenDef"<<endl;
}
_state = IN_A_DEFINITION;
return;
}
else if (first_token == "EndEventDef")
{
if (_state != IN_A_DEFINITION){
std::cout << "expected %EventDef" << endl;
return;
}
_state = OUT_A_DEFINITION;
if (line.length()>2){
std::cout<<"warning extra token in %EvenDef"<<endl;
}
}
else{
if (_state == OUT_A_DEFINITION){
std::cout << "expected %EventDef2" << endl;
return;
}
std::string field_value;
if (!line.item(2,field_value)){
std::cout << "A field type is missing." << endl;
return;
}
_definitions[_current_definition].store(first_token,field_value);
}
/*
string first_token;
if (!line.item(1,first_token))
{
cout << "error : a definition line is empty" << endl;
return;
}
if (first_token == "EventDef"){
if (_state == IN_A_DEFINITION){
cout << "expected %EndDef" << endl;
return;
}
string definition_name;
if (!line.item(2,definition_name)){
cout << "a definition has no name" << endl;
return;
}
int definition_identity;
string definition_identity_string;
if (!line.item(3,definition_identity_string)){
cout<<"definition has no identifier"<<endl;
return;
}
if (sscanf(definition_identity_string.c_str(),"%d",&definition_identity)!=1){
cout<<"expected identifier for a definition"<<endl;
return;
}
Definition current_definition = Definition(definition_name);
_definitions.insert(pair<int,Definition>(definition_identity, current_definition));
_current_definition = definition_identity;
if (line.length()>4){
cout<<"warning extra token in %EvenDef"<<endl;
}
_state = IN_A_DEFINITION;
return;
}
else if (first_token == "EndEventDef")
{
if (_state != IN_A_DEFINITION){
cout << "expected %EventDef" << endl;
return;
}
_state = OUT_A_DEFINITION;
if (line.length()>2){
cout<<"warning extra token in %EvenDef"<<endl;
}
}
else{
if (_state == OUT_A_DEFINITION){
cout << "expected %EventDef2" << endl;
return;
}
string field_value;
if (!line.item(2,field_value)){
cout << "A field type is missing." << endl;
return;
}
_definitions[_current_definition].store(first_token,field_value);
}
/*
//read the definition header
string &definition_name = line.item(2);
......@@ -103,38 +104,38 @@ void ParserDefinitionDecoder::store_definition(Line &line){
line.clear();
//read and store the parameters list
string final = "EndEventDef";
while (!line.eof()){
while (!line.eof()){
line.newline();
//std::cout << "line " << line.item(0)<< " " << line.item(1);
if(line.item(1) == final)
{
//std::cout << "end" <<endl;
break;
}
else
;//std::cout << "continue"<< endl;
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);
line.clear();
//cout << "line " << line.item(0)<< " " << line.item(1);
if(line.item(1) == final)
{
//cout << "end" <<endl;
break;
}
else
;//cout << "continue"<< endl;
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);
line.clear();
_definitions.insert(pair<int,Definition>(definition_identity, current_definition));
*/
}
line.clear();
_definitions.insert(pair<int,Definition>(definition_identity, current_definition));
*/
}
Definition& ParserDefinitionDecoder::get_definition(int i){
return _definitions[i];
}
std::map<int,Definition>* ParserDefinitionDecoder::HashTableofDefinitions(){
return &_definitions;
}
map<int,Definition>* ParserDefinitionDecoder::get_hash_table_of_definitions(){
return &_definitions;
}
void ParserDefinitionDecoder::print_definitions(){
map<int,Definition>::iterator it;
......
......@@ -23,17 +23,17 @@ class ParserDefinitionDecoder{
private:
/*! \brief Hash table to retrive easily event in Parser Event. */
std::map<int,Definition> _definitions;
int _state;
int _current_definition;
int _state;
int _current_definition;
public:
public:
ParserDefinitionDecoder();
int definitions_number();
void store_definition(Line &);
Definition& get_definition(int i);
Definition &get_definition(int i);
/*! \brief Print all the definitions. Useful for debug.*/
void print_definitions();
std::map<int,Definition>* HashTableofDefinitions();
void print_definitions();
std::map<int,Definition> *get_hash_table_of_definitions();
};
#endif // PARSERDEFINITIONDECODER_HPP
#include "ParserEventDecoder.hpp"
ParserEventDecoder::ParserEventDecoder(){
}
......
#ifndef PARSEREVENTDECODER_HPP
#define PARSEREVENTDECODER_HPP
#include <iostream>
#include <map>
#include "Definition.hpp"
#include "Line.hpp"
#define PARSEREVENTDECODER_HPP
#include <iostream>
#include <map>
#include "Definition.hpp"
#include "Line.hpp"
#include "../../values/color.hpp"
#include "../../values/date.hpp"
#include "../../values/double.hpp"
#include "../../values/hex.hpp"
#include "../../values/integer.hpp"
#include "../../values/name.hpp"
#include "../../values/string.hpp"
#include "../../structureDonnee/trace.hpp"
/**
* \class ParserEventDecoder
* \brief Reads Hash Table to find fill the Str
......@@ -12,24 +22,12 @@
class ParserEventDecoder{
private:
std::map<int,Definition>* _definitions_ptr;
/*!
*
*\fn convert(String type, String value)
*\brief return the appropriate type from a character description
*
*\param String : type ("Name", "Color"...)
* String : value ("integer","string")
*/
public:
private:
public:
ParserEventDecoder();
void sort_definition(Definition& d,Line&);
void store_event(Definition &, Line &, Trace &);
......
......@@ -7,8 +7,8 @@ void ParserPaje::parse(string filename, Trace &trace){
//ParserEventDecoder* parser_event_decoder = new ParserEventDecoder(&parser_definition_decoder);
Line line(filename);
int countline = 0;
int countline = 0;
while(!line.eof()){
// store the first line of the file
......@@ -16,13 +16,13 @@ void ParserPaje::parse(string filename, Trace &trace){
if(line.starts_with("%")){
// new definition
//parser_definition_decoder.store_definition(line);
//parser_definition_decoder.store_definition(line);
std::cout<<"ligne de type 1"<<endl;
}
else{
else{
std::cout<<"ligne de type 2"<<endl;
// new event
//parser_event_decoder.store_event(line, file);
//parser_event_decoder.store_event(line, file, trace);
// trace;
}
}
......
CC = g++
LD = g++
OBJ = ../src/Line.o ../src/ParserDefinitionDecoder.o ../src/Definition.o ../src/TokenSource.o
OBJ = ../src/Line.o ../src/ParserDefinitionDecoder.o ../src/Definition.o ../src/TokenSource.o ../src/ParserEventDecoder.o
OPT = -g -Wall -W
......
#include "../src/Line.hpp"
#include "../src/ParserDefinitionDecoder.hpp"
#include "../src/ParserDefinitionDecoder.hpp"
#include "../src/ParserEventDecoder.hpp"
#include <iostream>
#include <fstream>
......@@ -10,41 +10,41 @@ int main(int argc, char **argv){
ParserDefinitionDecoder *parserdefinition = new ParserDefinitionDecoder();
ParserEventDecoder *parserevent = new ParserEventDecoder();
Line line("trace_to_parse.trace");
int linecount = 0;
std::string pourcent = "%";
while(!line.eof()){
int linecount = 0;
string pourcent = "%";
while(!line.eof()){
line.newline();
if(line.starts_with(pourcent)){
parserdefinition->store_definition(line);
}
else
{
int number;
std::string token;
if (!line.item(0,token))
std::cout<<"line is empty"<<endl;
if (sscanf(token.c_str(),"%d",&number)!=1)
std::cout<<"NAN"<<endl;
else
//parserevent->sort_definition(parserdefinition->get_definition(number),line);
linecount++;
}
else
{
int number;
string token;
if (!line.item(0,token))
std::cout<<"line is empty"<<endl;
if (sscanf(token.c_str(),"%d",&number)!=1)
std::cout<<"NAN"<<endl;
else
//parserevent->sort_definition(parserdefinition->get_definition(number),line);
linecount++;
}
}
parserdefinition->print_definitions();
std::cout << "lu :" << linecount;
cout << "lu :" << linecount;
delete parserdefinition;
delete parserevent;
delete parserdefinition;
delete parserevent;
return EXIT_SUCCESS;
}
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