Commit 845c8912 authored by Johnny Jazeix's avatar Johnny Jazeix
Browse files

Application des normes et débogage.

parent c6e0aca0
......@@ -48,11 +48,11 @@ bool Definition::check_definition() const{
bool has_container_type = false;
for(int i = 0 ; i < number_of_fields ; i ++){
// We check if we have the name or the alias
if((_fields[i]._name == "Name" || _fields[i]._name == "Alias") && (_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
if((_fields[i]._name == "Name" || _fields[i]._name == "Alias") && (_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_name_or_alias = true;
}
// We check if we have the ContainerType
else if(_fields[i]._name == "ContainerType" && (_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
else if(_fields[i]._name == "ContainerType" && (_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_container_type = true;
}
// We return true if we have the compulsory fields and we don't care of others
......@@ -70,11 +70,11 @@ bool Definition::check_definition() const{
bool has_container = false;
for(int i = 0 ; i < number_of_fields ; i ++){
// We check if we have the name or the alias
if((_fields[i]._name == "Name" || _fields[i]._name == "Alias") && (_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
if((_fields[i]._name == "Name" || _fields[i]._name == "Alias") && (_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_name_or_alias = true;
}
// We check if we have the container
else if(_fields[i]._name == "Container" && (_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
else if(_fields[i]._name == "Container" && (_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_container = true;
}
// We check if we have the time
......@@ -82,7 +82,7 @@ bool Definition::check_definition() const{
has_time = true;
}
// We check if we have the type
else if(_fields[i]._name == "Type" && (_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
else if(_fields[i]._name == "Type" && (_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_type = true;
}
// We return true if we have the compulsory fields and we don't care of others
......@@ -99,7 +99,7 @@ bool Definition::check_definition() const{
bool has_type = false;
for(int i = 0 ; i < number_of_fields ; i ++){
// We check if we have the name or the alias
if((_fields[i]._name == "Name" || _fields[i]._name == "Alias") && (_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
if((_fields[i]._name == "Name" || _fields[i]._name == "Alias") && (_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_name_or_alias = true;
}
// We check if we have the time
......@@ -107,7 +107,7 @@ bool Definition::check_definition() const{
has_time = true;
}
// We check if we have the type
else if(_fields[i]._name == "Type" && (_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
else if(_fields[i]._name == "Type" && (_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_type = true;
}
// We return true if we have the compulsory fields and we don't care of others
......@@ -126,19 +126,19 @@ bool Definition::check_definition() const{
bool has_DestContainerType = false;
for(int i = 0 ; i < number_of_fields ; i ++){
// We check if we have the name or the alias
if((_fields[i]._name == "Name" || _fields[i]._name == "Alias") && (_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
if((_fields[i]._name == "Name" || _fields[i]._name == "Alias") && (_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_name_or_alias = true;
}
// We check if we have the ContainerType
else if(_fields[i]._name == "ContainerType" && (_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
else if(_fields[i]._name == "ContainerType" && (_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_ContainerType = true;
}
// We check if we have the SourceContainerType
else if(_fields[i]._name == "SourceContainerType" && (_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
else if(_fields[i]._name == "SourceContainerType" && (_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_SourceContainerType = true;
}
// We check if we have the DestContainerType
else if(_fields[i]._name == "DestContainerType" && (_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
else if(_fields[i]._name == "DestContainerType" && (_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_DestContainerType = true;
}
// We return true if we have the compulsory fields and we don't care of others
......@@ -153,11 +153,11 @@ bool Definition::check_definition() const{
bool has_EntityType = false;
for(int i = 0 ; i < number_of_fields ; i ++){
// We check if we have the name or the alias
if((_fields[i]._name == "Name" || _fields[i]._name == "Alias") && (_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
if((_fields[i]._name == "Name" || _fields[i]._name == "Alias") && (_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_name_or_alias = true;
}
// We check if we have the time
else if(_fields[i]._name == "EntityType" && (_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
else if(_fields[i]._name == "EntityType" && (_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_EntityType = true;
}
// We return true if we have the compulsory fields and we don't care of others
......@@ -176,7 +176,7 @@ bool Definition::check_definition() const{
for(int i = 0 ; i < number_of_fields ; i ++){
// We check if we have the name or the alias
if(_fields[i]._name == "Container" &&
(_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
(_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_Container = true;
}
// We check if we have the time
......@@ -184,11 +184,11 @@ bool Definition::check_definition() const{
has_time = true;
}
// We check if we have the type
else if(_fields[i]._name == "Type" && (_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
else if(_fields[i]._name == "Type" && (_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_type = true;
}
// We check if we have the value
else if(_fields[i]._name == "Value" && (_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
else if(_fields[i]._name == "Value" && (_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_Value = true;
} // We return true if we have the compulsory fields and we don't care of others
if(has_Container && has_time && has_type && has_Value){
......@@ -208,12 +208,12 @@ bool Definition::check_definition() const{
}
// We check if we have the type
else if(_fields[i]._name == "Type" &&
(_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
(_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_type = true;
}
// We check if we have the value
else if(_fields[i]._name == "Container" &&
(_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
(_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_Container = true;
} // We return true if we have the compulsory fields and we don't care of others
if(has_Container && has_time && has_type){
......@@ -231,7 +231,7 @@ bool Definition::check_definition() const{
for(int i = 0 ; i < number_of_fields ; i ++){
// We check if we have the name or the alias
if(_fields[i]._name == "Container" &&
(_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
(_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_Container = true;
}
// We check if we have the time
......@@ -240,7 +240,7 @@ bool Definition::check_definition() const{
}
// We check if we have the type
else if(_fields[i]._name == "Type" &&
(_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
(_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_type = true;
}
// We check if we have the value
......@@ -265,7 +265,7 @@ bool Definition::check_definition() const{
for(int i = 0 ; i < number_of_fields ; i ++){
// We check if we have the name or the alias
if(_fields[i]._name == "Container" &&
(_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
(_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_Container = true;
}
// We check if we have the time
......@@ -274,22 +274,22 @@ bool Definition::check_definition() const{
}
// We check if we have the type
else if(_fields[i]._name == "Type" &&
(_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
(_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_type = true;
}
// We check if we have the key
else if(_fields[i]._name == "Key" &&
(_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
(_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_key = true;
}
// We check if we have the SourceContainer
else if(_fields[i]._name == "SourceContainer" &&
(_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
(_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_SourceContainer = true;
}
// We check if we have the value
else if(_fields[i]._name == "Value" &&
(_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
(_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_Value = true;
} // We return true if we have the compulsory fields and we don't care of others
if(has_Container && has_time && has_type && has_Value && has_key && has_SourceContainer){
......@@ -310,7 +310,7 @@ bool Definition::check_definition() const{
for(int i = 0 ; i < number_of_fields ; i ++){
// We check if we have the name or the alias
if(_fields[i]._name == "Container" &&
(_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
(_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_Container = true;
}
// We check if we have the time
......@@ -319,22 +319,22 @@ bool Definition::check_definition() const{
}
// We check if we have the type
else if(_fields[i]._name == "Type" &&
(_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
(_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_type = true;
}
// We check if we have the key
else if(_fields[i]._name == "Key" &&
(_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
(_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_key = true;
}
// We check if we have the SourceContainer
else if(_fields[i]._name == "DestContainer" &&
(_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
(_fields[i]._type == "string"|| _fields[i]._type == "int")){
has_DestContainer = true;
}
// We check if we have the value
else if(_fields[i]._name == "Value" &&
(_fields[i]._type == "string" || _fields[i]._type == "integer" || _fields[i]._type == "int")){
(_fields[i]._type == "string" || _fields[i]._type == "int")){
has_Value = true;
} // We return true if we have the compulsory fields and we don't care of others
if(has_Container && has_time && has_type && has_Value && has_key && has_DestContainer){
......
......@@ -26,12 +26,13 @@ private:
/*!
* \fn typetoint(std::string)
* \brief : convert to store the code instead of a string
* \param : string
* \param : string
*/
int typetoint(std::string);
/*!
/*!
* \fn valid_type(std::string &type_name)
* \brief Check if the type_name is a real type.
* \param name : the name we want to check.
......@@ -42,8 +43,9 @@ private:
public:
/*!
* \fn Definition()
* \brief : constructor
* \param : string event name
* \param : string event name
*
*/
Definition();
......@@ -56,6 +58,7 @@ public:
Definition(std::string &eventname);
/*!
* \fn store(std::string name, std::string type)
* \brief : add a field to definition
* \param name : the name of the event
* \param type : the type of the event
......@@ -65,6 +68,7 @@ public:
/*!
* \fn print() \
* \brief : print() : display the definitions
*
*/
......@@ -72,8 +76,8 @@ public:
/*!
* \fn : get_fields() const
* \brief : get_fields() : return the vector _fields
*
*/
const std::vector<field> &get_fields() const;
......
......@@ -8,29 +8,27 @@ Line::Line(Line &){}
Line::Line(string &filename){
source.open(filename.c_str());
_source.open(filename.c_str());
_eof = false;
}
Line::Line(const char *filename){
source.open(filename);
_source.open(filename);
_eof = false;
}
void Line::print()
{
cout << "-" ;
void Line::print(){
cout << "-" ;
for(unsigned int i = 0 ; i < _tokens.size() ; i ++)
cout << _tokens[i] << " " ;
cout << "-" <<endl ;
cout << "-" <<endl ;
}
Line::~Line(){}
bool Line::starts_with(const string & s) const{
bool Line::starts_with(const string &s) const{
if(!_tokens.empty())
return _tokens[0] == s;
return _tokens[0] == s;
else // tokens is empty
return false;
}
......@@ -68,14 +66,13 @@ int Line::length(){
return _tokens.size();
}
void Line::clear()
{
void Line::clear(){
_tokens.clear();
}
bool Line::eof(){
return _eof;
return _eof;
}
void Line::newline(){
if(!_tokens.empty()){
......@@ -84,14 +81,15 @@ void Line::newline(){
char *tok;
string str;
while ((tok=source.lire_token()) != NULL){
while ((tok=_source.lire_token()) != NULL){
str.assign(tok);
str.assign(tok);
if (str == "\n")
return;
if (str == "\n"){
return;
}
_tokens.push_back(str);
_tokens.push_back(str);
}
......
......@@ -17,7 +17,7 @@ class Line{
private:
std::vector<std::string> _tokens;
TokenSource source;
TokenSource _source;
bool _eof;
void clear();
......@@ -35,21 +35,21 @@ public:
*/
Line(Line &l);
/*!
/*!
* \brief Constructor for the line
* \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
*/
......@@ -69,14 +69,14 @@ public:
/*!
/*!
* \brief step to the next line of the file, a call to eof is required before newline()
*
*/
void newline();
/*!
/*!
* \brief true if the lines contains the same items
*
*/
......@@ -95,7 +95,7 @@ public:
* Useful for debug
*
*/
void print();
void print();
/*!
......
......@@ -3,7 +3,8 @@
#include <string>
/*! \class Parser Parser.hpp "../parser/src/Parser.hpp"
/*!
* \class Parser Parser.hpp "../parser/src/Parser.hpp"
* Contains the definition of the parser interface.
*/
......
......@@ -2,52 +2,51 @@
#define OUT_A_DEFINITION 0
#define IN_A_DEFINITION 1
#define WARN_IF(condition,message) if (condition) \
cerr << message << endl;
#define WARN_IF(condition, message) if (condition) \
cerr << message << endl;
#define DIE_IF(condition,message) if (condition){ \
cerr << message << endl; \
return;}
#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(){
return _definitions.size();
return _definitions.size();
}
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");
string definition_name;
DIE_IF(!line.item(2, definition_name), "Error : a definition need a name");
int definition_identity;
string definition_identity_string;
DIE_IF(!line.item(3, definition_identity_string), "Error : definition has no identifier");
DIE_IF(sscanf(definition_identity_string.c_str(), "%d", &definition_identity) != 1, "Error : expected identifier for a definition");
int definition_identity;
string definition_identity_string;
DIE_IF(!line.item(3, definition_identity_string), "Error : definition has no identifier");
DIE_IF(sscanf(definition_identity_string.c_str(), "%d", &definition_identity) != 1, "Error : expected identifier for a definition");
Definition current_definition = Definition(definition_name);
_definitions.insert(pair<int,Definition>(definition_identity, current_definition));
_current_definition = definition_identity;
WARN_IF((line.length() > 4), "Warning : extra token in %EventDef");
Definition current_definition = Definition(definition_name);
_definitions.insert(pair<int,Definition>(definition_identity, current_definition));
_current_definition = definition_identity;
WARN_IF((line.length() > 4), "Warning : extra token in %EventDef");
_state = IN_A_DEFINITION;
return;
_state = IN_A_DEFINITION;
return;
}
void ParserDefinitionDecoder::leave_definition(Line&line){
void ParserDefinitionDecoder::leave_definition(Line &line){
DIE_IF(_state != IN_A_DEFINITION, "Error : expected %EventDef");
_state = OUT_A_DEFINITION;
DIE_IF(!_definitions[_current_definition].check_definition(), "Error : unknown event" );
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");
}
......@@ -58,7 +57,10 @@ void ParserDefinitionDecoder::add_field_to_definition(std::string& first_token,L
string field_type;
DIE_IF(!line.item(2, field_type), "Error : a field type is missing");
DIE_IF(field_type!="string"&&field_type!="int"&&field_type!="hex"&&field_type!="date"&&field_type!="double"&&field_type!="color", "Error : unknown type");
DIE_IF(field_type != "string" && field_type != "int" &&
field_type != "hex" && field_type != "date" &&
field_type != "double" && field_type != "color"
, "Error : unknown type");
_definitions[_current_definition].store(first_token, field_type);
}
......@@ -69,13 +71,13 @@ void ParserDefinitionDecoder::store_definition(Line &line){
DIE_IF(!line.item(1,first_token), "Warning : a definition line is empty");
if (first_token == "EventDef"){
enter_definition(line);
enter_definition(line);
}
else if (first_token == "EndEventDef"){
leave_definition(line);
leave_definition(line);
}
else{
add_field_to_definition(first_token,line);
add_field_to_definition(first_token,line);
}
}
......@@ -91,11 +93,11 @@ map<int,Definition>* ParserDefinitionDecoder::get_hash_table_of_definitions(){
void ParserDefinitionDecoder::print_definitions(){
map<int,Definition>::iterator it;
for (it = _definitions.begin (); it != _definitions.end() ; ++ it){
// (*it).second represents the current definition
for (it = _definitions.begin(); it != _definitions.end() ; ++ it){
cout << "# " << (*it).first << endl;
// (*it).second represents the current definition
(*it).second.print();
}
}
......@@ -2,8 +2,6 @@
using namespace std;
ParserEventDecoder::ParserEventDecoder(){
}
......@@ -32,7 +30,7 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
vector<field> fields = definition.get_fields();
int number_of_values = fields.size();
while(i < number_of_values) {
while(i < number_of_values+1) {
string current_value;
if (!line.item(i, current_value)) {
......@@ -226,24 +224,24 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
trace.new_event(time, trace.search_event_type(type), trace.search_container(container), trace.search_entity_value(value_string), extra_fields);
}
else if(event_name == "PajeSetVariable") {
else if(event_name == "PajeSetVariable") {
trace.set_variable(time, trace.search_variable_type(type), trace.search_container(container), value_double, extra_fields);
}
else if(event_name == "PajeAddVariable") {
else if(event_name == "PajeAddVariable") {
trace.add_variable(time, trace.search_variable_type(type), trace.search_container(container), value_double, extra_fields);
}
else if(event_name == "PajeSubVariable") {
else if(event_name == "PajeSubVariable") {
trace.sub_variable(time, trace.search_variable_type(type), trace.search_container(container), value_double, extra_fields);
}
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), key, extra_fields);
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), key, extra_fields);
}
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), key, extra_fields);
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), key, extra_fields);
}
else {
......
......@@ -12,7 +12,7 @@
#include "../../trace/src/values/Integer.hpp"
#include "../../trace/src/values/Name.hpp"
#include "../../trace/src/values/String.hpp"
#include "../tests/stub/trace.hpp"
#include "../tests/stub/trace.hpp"
/**
......@@ -23,9 +23,6 @@
class ParserEventDecoder{
private:
public:
ParserEventDecoder();
void store_event(const Definition &, Line &, Trace &);
......