Commit aaf63f9a authored by Johnny Jazeix's avatar Johnny Jazeix

Ajout de commentaires, degraissage de code ...

parent 3469678e
......@@ -24,7 +24,7 @@ void Svg::afficher(){
}
void Svg::init(char *path){
void Svg::init(const char *path){
_svg_file.open(path , ofstream::out | ofstream::trunc);
......
#ifndef RENDER_SVG
#define RENDER_SVG
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <fstream>
#define BUFFER_SIZE 2048
#define LEVEL 110
......@@ -16,8 +19,8 @@ class Svg{
private:
ostringstream _buffer;
ofstream _svg_file;
std::ostringstream _buffer;
std::ofstream _svg_file;
unsigned int _r,_g,_b;
unsigned long _x,_y,_w,_h;
void afficher();
......@@ -26,7 +29,7 @@ public:
/*!
* \brief SVG header buiding
*/
void init(char *path);
void init(const char *path);
/*!
* \brief SVG bottom file buiding
......
......@@ -12,7 +12,7 @@ Definition::Definition(std::string& eventname){
void Definition::store(std::string name, std::string type){
field e;
Field e;
e._name = name;
e._type = type;
......@@ -29,7 +29,7 @@ void Definition::print() const{
}
const vector<field> &Definition::get_fields() const{
const vector<Field> &Definition::get_fields() const{
return _fields;
}
......
......@@ -2,40 +2,34 @@
#define DEFINITION_HPP
/*! \class Definition Definition.hpp "../parser/src/Definition.hpp"
* Contains the definition of a definition.
*/
#include <vector>
#include <iostream>
#include <string>
struct field{
/*! \struct Field Definition.hpp "../parser/src/Definition.hpp"
* \brief Contains the name and the type of a definition element.
*/
struct Field{
std::string _name;
std::string _type;
};
/*! \class Definition Definition.hpp "../parser/src/Definition.hpp"
* \brief Contains the definition of a definition.
*/
class Definition{
private:
std::vector<field> _fields;
std::vector<Field> _fields;
std::string _event_name;
/*!
* \fn typetoint(std::string)
* \brief : convert to store the code instead of a string
* \param : string
*/
int typetoint(std::string);
/*!
* \fn is_valid_type(const std::string &type_name) const
* \brief Check if the type_name is a real type.
* \param name : the name we want to check.
* \param type_name the name we want to check.
* \return true if the type exists.
*/
bool is_valid_type(const std::string &type_name) const;
......@@ -79,7 +73,7 @@ public:
* \fn : get_fields() const
* \brief : get_fields() : return the vector _fields
*/
const std::vector<field> &get_fields() const;
const std::vector<Field> &get_fields() const;
/*!
* \fn : get_event_name() const
......
......@@ -6,7 +6,8 @@ Line::Line(){
_line_count = 0;
}
Line::Line(Line &){}
Line::Line(Line &){
}
Line::Line(string &filename){
open(filename.c_str());
......@@ -16,20 +17,25 @@ Line::Line(const char *filename){
open(filename);
}
Line::~Line(){
if(!_tokens.empty()){
_tokens.clear();
}
}
void Line::open(const char *filename){
_line_count = 0;
_source.sopen(filename);
_eof = false;
_source.open(filename);
_is_eof = false;
}
void Line::print(){
void Line::print() const{
cout << "-" ;
for(unsigned int i = 0 ; i < _tokens.size() ; i ++)
cout << _tokens[i] << " " ;
cout << "-" <<endl ;
}
Line::~Line(){}
bool Line::starts_with(const string &s) const{
if(!_tokens.empty())
return _tokens[0] == s;
......@@ -37,14 +43,14 @@ bool Line::starts_with(const string &s) const{
return false;
}
bool Line::item (unsigned int i, string &e){
bool Line::item (unsigned int i, string &e) const{
if (i >= _tokens.size())
return false;
e = _tokens[i];
return true;
}
unsigned int Line::length(){
unsigned int Line::length() const{
return _tokens.size();
}
......@@ -52,8 +58,8 @@ void Line::clear(){
_tokens.clear();
}
bool Line::eof(){
return _eof;
bool Line::is_eof() const{
return _is_eof;
}
void Line::newline(){
......@@ -63,25 +69,16 @@ void Line::newline(){
string *tok;
_line_count++;
while ((tok=_source.lire_token()) != NULL){
while ((tok = _source.read_token()) != NULL){
if (*tok == "\n"){
return;
}
_tokens.push_back(*tok);
}
_eof=true;
_is_eof = true;
}
unsigned int Line::get_line_count(){
return _line_count;
unsigned int Line::get_line_count() const{
return _line_count;
}
......@@ -5,7 +5,9 @@
#include <vector>
#include <iostream>
#include <fstream>
#include "TokenSource.hpp"
#define BUFFSIZE 256
......@@ -18,7 +20,7 @@ class Line{
private:
std::vector<std::string> _tokens;
TokenSource _source;
bool _eof;
bool _is_eof;
unsigned int _line_count;
void clear();
......@@ -40,32 +42,35 @@ public:
* \param filename : a filename
*/
Line(std::string &filename);
/*!
* \brief Constructor for the line
* \param filename : a filename
*/
Line(const char* filename);
/*!
* \brief Destructor
* Destroy the line
*/
~Line();
/*!
* \fn starts_with(const std::string &) const
* \param : A string
* \return : true if the line starts with the param, false else
*/
bool starts_with(const std::string &) const;
/*!
* \fn is_eof() const
* \brief test if file ended
* \return true if more lines are available
*/
bool eof();
bool is_eof() const;
/*!
* \fn newline()
* \brief step to the next line of the file, a call to eof is required before newline()
*
*/
......@@ -73,41 +78,50 @@ public:
/*!
* \fn operator==(const Line &l) const
* \brief true if the lines contains the same items
* \param l the line we want to check if it is equal to this
* \return true if the lines are equals
*
*/
bool operator== (Line &l);
bool operator==(const Line &l) const;
/*!
* \fn item(unsigned int i, std::string &e) const
* \brief the ith token in the line
* \return : true if the string is filled, false if no item exist at this index.
* \param i the number of the token we want
* \param e the string where we store the name of the token
* \return true if the string is filled, false if no item exists at this index.
*/
bool item (unsigned int i,std::string &e);
bool item(unsigned int i, std::string &e) const;
/*!
* \fn print()
* \fn print() const
* \brief print the line
* Useful for debug
* Useful for debug.
*
*/
void print();
void print() const;
/*!
* \fn length() const
* \brief number of token
*
* \return the number of tokens in the line.
*/
unsigned int length();
unsigned int length() const;
/*!
* \fn get_line_count() const
* \brief read line amount
* \return the number of lines already read.
*
*/
unsigned int get_line_count();
unsigned int get_line_count() const;
/*!
* \fn open(const char *filename)
* \brief open a file
* \param valid filename
* \param filename valid filename
*/
void open(const char *filename);
......
......@@ -3,9 +3,17 @@
#include <string>
#define WARN_IF(condition, message) if (condition) \
std::cerr << message << std::endl;
#define DIE_IF(condition, message) if (condition){ \
std::cerr << message << std::endl; \
return;}
/*!
* \class Parser Parser.hpp "../parser/src/Parser.hpp"
* Contains the definition of the parser interface.
* \brief Contains the definition of the parser interface.
*/
class Parser{
......
#include "ParserDefinitionDecoder.hpp"
#define OUT_A_DEFINITION 0
#define IN_A_DEFINITION 1
#define WARN_IF(condition, message) if (condition) \
cerr << message << endl;
#define DIE_IF(condition, message) if (condition){ \
cerr << message << endl; \
return;}
using namespace std;
ParserDefinitionDecoder::ParserDefinitionDecoder(){
_state = OUT_A_DEFINITION;
_state = _OUT_A_DEFINITION;
}
int ParserDefinitionDecoder::definitions_number(){
......@@ -22,7 +12,7 @@ int ParserDefinitionDecoder::definitions_number(){
void ParserDefinitionDecoder::enter_definition(Line &line){
DIE_IF(_state == IN_A_DEFINITION, "Error : expected %EndEventDef");
DIE_IF(_state == _IN_A_DEFINITION, "Error : expected %EndEventDef");
string definition_name;
DIE_IF(!line.item(2, definition_name), "Error : a definition need a name");
......@@ -36,15 +26,15 @@ void ParserDefinitionDecoder::enter_definition(Line &line){
_current_definition = definition_identity;
WARN_IF((line.length() > 4), "Warning : extra token in %EventDef");
_state = IN_A_DEFINITION;
_state = _IN_A_DEFINITION;
return;
}
void ParserDefinitionDecoder::leave_definition(Line &line){
DIE_IF(_state != IN_A_DEFINITION, "Error : expected %EventDef");
DIE_IF(_state != _IN_A_DEFINITION, "Error : expected %EventDef");
_state = OUT_A_DEFINITION;
_state = _OUT_A_DEFINITION;
DIE_IF(!_definitions[_current_definition].check_definition(), "Error : unknown event : " + _definitions[_current_definition].get_event_name());
WARN_IF(line.length() > 2, "Warning : extra token in %EventDef");
......@@ -52,7 +42,7 @@ void ParserDefinitionDecoder::leave_definition(Line &line){
void ParserDefinitionDecoder::add_field_to_definition(std::string& first_token,Line& line){
DIE_IF(_state == OUT_A_DEFINITION, "Error : expected %EventDef2");
DIE_IF(_state == _OUT_A_DEFINITION, "Error : expected %EventDef2");
string field_type;
DIE_IF(!line.item(2, field_type), "Error : a field type is missing");
......
......@@ -4,9 +4,17 @@
#include <iostream>
#include <fstream>
#include <map>
#include "Definition.hpp"
#include "Line.hpp"
#define WARN_IF(condition, message) if (condition) \
std::cerr << message << std::endl;
#define DIE_IF(condition, message) if (condition){ \
std::cerr << message << std::endl; \
return;}
/*!
*
* \class ParserDefinitionDecoder
......@@ -16,15 +24,17 @@
class ParserDefinitionDecoder{
/**
*Reads line to find events definition
* Reads line to find events definition
*
*/
private:
/*! \brief Hash table to retrive easily event in Parser Event. */
std::map<unsigned int,Definition> _definitions;
std::map<unsigned int, Definition> _definitions;
int _state;
unsigned int _current_definition;
static const int _OUT_A_DEFINITION = 0;
static const int _IN_A_DEFINITION = 1;
public:
/*!
......@@ -41,9 +51,9 @@ public:
/*!
* \fn store_definition(Line &)
* \param : the line to store,
* \param l the line to store.
*/
void store_definition(Line &);
void store_definition(Line &l);
/*!
* \fn get_definition(unsigned int i)
......
......@@ -27,14 +27,14 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
vector<Value *> extra_fields;
unsigned int i = 1;
vector<field> fields = definition.get_fields();
vector<Field> fields = definition.get_fields();
unsigned int number_of_values = fields.size();
while(i < number_of_values+1) {
string current_value;
if (!line.item(i, current_value)) {
cout << "warning : missing values" << endl;
cerr << "warning : missing values" << endl;
return;
}
......@@ -66,7 +66,7 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
else if (fields[i-1]._name == "Time") {
if(!Date::instantiate(current_value, time)) {
cout << "warning : incompatible value : " << current_value << endl;
cerr << "warning : incompatible value : " << current_value << endl;
return;
}
}
......@@ -82,7 +82,7 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
else if (fields[i-1]._name == "Value") {
if(fields[i-1]._type == "double") {
if(!Double::instantiate(current_value, value_double)) {
cout << "warning : incompatible value : " << current_value << endl;
cerr << "warning : incompatible value : " << current_value << endl;
return;
}
}
......@@ -108,12 +108,10 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
String value = current_value;
extra_fields.push_back(&value);
}
else if(fields[i-1]._type == "double") {
Double value;
if(!Double::instantiate(current_value, value)) {
cout << "warning : incompatible value : " << current_value << endl;
cerr << "warning : incompatible value : " << current_value << endl;
return;
}
extra_fields.push_back(&value);
......@@ -121,7 +119,7 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
else if(fields[i-1]._type == "hex") {
Hex value;
if(!Hex::instantiate(current_value, value)) {
cout << "warning : incompatible value : " << current_value << endl;
cerr << "warning : incompatible value : " << current_value << endl;
return;
}
extra_fields.push_back(&value);
......@@ -129,7 +127,7 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
else if(fields[i-1]._type == "date") {
Date value;
if(!Date::instantiate(current_value, value)) {
cout << "warning : incompatible value : " << current_value << endl;
cerr << "warning : incompatible value : " << current_value << endl;
return;
}
extra_fields.push_back(&value);
......@@ -137,7 +135,7 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
else if(fields[i-1]._type == "int") {
Integer value;
if(!Integer::instantiate(current_value, value)) {
cout << "warning : incompatible value : " << current_value << endl;
cerr << "warning : incompatible value : " << current_value << endl;
return;
}
extra_fields.push_back(&value);
......@@ -145,22 +143,22 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
else if(fields[i-1]._type == "color") {
Color value;
if(!Color::instantiate(current_value, value)) {
cout << "warning : incompatible value : " << current_value << endl;
cerr << "warning : incompatible value : " << current_value << endl;
return;
}
extra_fields.push_back(&value);
}
else {
cout << "warning : unknown type" << endl;
cerr << "warning : unknown type" << endl;
return;
}
}
i++;
i ++;
}
if(line.length() > i+1) {
cout << "warning : extra value(s)" << endl;
cerr << "warning : extra value(s)" << endl;
}
Name alias_name;
......@@ -173,7 +171,6 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
}
string event_name = definition.get_event_name();
if(event_name == "PajeDefineContainerType") {
......@@ -236,11 +233,11 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
trace.sub_variable(time, trace.search_variable_type(type), trace.search_container(container), value_double, extra_fields);
}
else if(event_name == "PajeStartLink") { // key a la place de Integer() mais fautle mettre dans le bon type...
else if(event_name == "PajeStartLink") {
trace.start_link(time, trace.search_link_type(type), trace.search_container(container), trace.search_container(source_container), trace.search_entity_value(value_string), Integer(), extra_fields);
}
else if(event_name == "PajeEndLink") { // key a la place de Integer() mais fautle mettre dans le bon type...
else if(event_name == "PajeEndLink") {
trace.end_link(time, trace.search_link_type(type), trace.search_container(container), trace.search_container(dest_container), trace.search_entity_value(value_string), Integer(), extra_fields);
}
......
......@@ -3,15 +3,11 @@
#include <iostream>
#include <map>
#include "Definition.hpp"
#include "Line.hpp"
#include "../../trace/src/values/Color.hpp"
#include "../../trace/src/values/Date.hpp"
#include "../../trace/src/values/Double.hpp"
#include "../../trace/src/values/Hex.hpp"
#include "../../trace/src/values/Integer.hpp"
#include "../../trace/src/values/Name.hpp"
#include "../../trace/src/values/String.hpp"
#include "../../trace/src/values/Values.hpp"
#ifdef DEBUG
#include "../tests/stub/trace.hpp"
#else
......@@ -27,9 +23,13 @@ class ParserEventDecoder{
public:
ParserEventDecoder();
void store_event(const Definition &, Line &, Trace &);
/*!
* \fn store_event(const Definition &definition, Line &line, Trace &trace)
* \param definition the definition of the event.
* \param line the line containing the event.
* \param trace where we store the event.
*/
void store_event(const Definition &definition, Line &line, Trace &trace);
};
#endif // PARSEREVENTDECODER_HPP
#include "ParserPaje.hpp"
#define DIE_IF(condition,message) if (condition){ \
cout << message << endl; \
return;}
using namespace std;
void ParserPaje::parse(string filename, Trace &trace){
ParserDefinitionDecoder *parserdefinition = new ParserDefinitionDecoder();
ParserEventDecoder *parserevent = new ParserEventDecoder();
ParserDefinitionDecoder *parserdefinition = new ParserDefinitionDecoder();
ParserEventDecoder *parserevent = new ParserEventDecoder();
Line line(filename);
static const string percent = "%";
static const string PERCENT = "%";
string event_identity_string;
unsigned int event_identity;
while(!line.eof()){
while(!line.is_eof()){
line.newline();
if(line.starts_with(percent)){
if(line.starts_with(PERCENT)){
parserdefinition->store_definition(line);
}
}
else if (!line.item(0, event_identity_string)){
// continue;