From aaf63f9a15834f11be11f2ca1a3f4e6908740e48 Mon Sep 17 00:00:00 2001 From: Jonnhy Jazeix <jazeix@gmail.com> Date: Mon, 23 Feb 2009 16:46:25 +0000 Subject: [PATCH] Ajout de commentaires, degraissage de code ... --- interface/src/render_svg.cpp | 2 +- interface/src/render_svg.hpp | 9 ++-- parser/src/Definition.cpp | 4 +- parser/src/Definition.hpp | 30 +++++------- parser/src/Line.cpp | 43 ++++++++--------- parser/src/Line.hpp | 44 ++++++++++++------ parser/src/Parser.hpp | 10 +++- parser/src/ParserDefinitionDecoder.cpp | 22 +++------ parser/src/ParserDefinitionDecoder.hpp | 18 ++++++-- parser/src/ParserEventDecoder.cpp | 31 ++++++------- parser/src/ParserEventDecoder.hpp | 20 ++++---- parser/src/ParserPaje.cpp | 30 ++++-------- parser/src/ParserPaje.hpp | 7 +-- parser/src/TokenSource.cpp | 37 +++++++-------- parser/src/TokenSource.hpp | 64 +++++++++++--------------- trace/src/values/Color.hpp | 4 +- trace/src/values/Date.hpp | 49 ++++++++++++++++++-- trace/src/values/String.hpp | 4 +- trace/src/values/Value.hpp | 2 + trace/src/values/Values.hpp | 22 +++++++++ 20 files changed, 252 insertions(+), 200 deletions(-) create mode 100644 trace/src/values/Values.hpp diff --git a/interface/src/render_svg.cpp b/interface/src/render_svg.cpp index 750d57bb..14712a46 100644 --- a/interface/src/render_svg.cpp +++ b/interface/src/render_svg.cpp @@ -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); diff --git a/interface/src/render_svg.hpp b/interface/src/render_svg.hpp index 0ba3b67e..2aeccb08 100644 --- a/interface/src/render_svg.hpp +++ b/interface/src/render_svg.hpp @@ -1,9 +1,12 @@ #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 diff --git a/parser/src/Definition.cpp b/parser/src/Definition.cpp index c33574ce..b341b064 100644 --- a/parser/src/Definition.cpp +++ b/parser/src/Definition.cpp @@ -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; } diff --git a/parser/src/Definition.hpp b/parser/src/Definition.hpp index 6f82eae4..639b31e3 100644 --- a/parser/src/Definition.hpp +++ b/parser/src/Definition.hpp @@ -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 diff --git a/parser/src/Line.cpp b/parser/src/Line.cpp index 0fece0b0..fb49c3b8 100644 --- a/parser/src/Line.cpp +++ b/parser/src/Line.cpp @@ -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; } diff --git a/parser/src/Line.hpp b/parser/src/Line.hpp index 9c181323..70c8cad9 100644 --- a/parser/src/Line.hpp +++ b/parser/src/Line.hpp @@ -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); diff --git a/parser/src/Parser.hpp b/parser/src/Parser.hpp index 62ceedd9..c82cf08b 100644 --- a/parser/src/Parser.hpp +++ b/parser/src/Parser.hpp @@ -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{ diff --git a/parser/src/ParserDefinitionDecoder.cpp b/parser/src/ParserDefinitionDecoder.cpp index a53f645c..2ce3db1c 100644 --- a/parser/src/ParserDefinitionDecoder.cpp +++ b/parser/src/ParserDefinitionDecoder.cpp @@ -1,19 +1,9 @@ #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"); diff --git a/parser/src/ParserDefinitionDecoder.hpp b/parser/src/ParserDefinitionDecoder.hpp index 122f6c64..b8823349 100644 --- a/parser/src/ParserDefinitionDecoder.hpp +++ b/parser/src/ParserDefinitionDecoder.hpp @@ -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) diff --git a/parser/src/ParserEventDecoder.cpp b/parser/src/ParserEventDecoder.cpp index 5e6d8150..bbf788cd 100644 --- a/parser/src/ParserEventDecoder.cpp +++ b/parser/src/ParserEventDecoder.cpp @@ -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); } diff --git a/parser/src/ParserEventDecoder.hpp b/parser/src/ParserEventDecoder.hpp index 05974759..eb78fd0a 100644 --- a/parser/src/ParserEventDecoder.hpp +++ b/parser/src/ParserEventDecoder.hpp @@ -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 diff --git a/parser/src/ParserPaje.cpp b/parser/src/ParserPaje.cpp index 5c681630..eca71f0e 100644 --- a/parser/src/ParserPaje.cpp +++ b/parser/src/ParserPaje.cpp @@ -1,48 +1,38 @@ #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; } else{ - - DIE_IF(sscanf(event_identity_string.c_str(), "%d", &event_identity) != 1, "expected identifier for a definition"); + DIE_IF(sscanf(event_identity_string.c_str(), "%d", &event_identity) != 1, "expected identifier for a definition"); parserevent->store_event( parserdefinition->get_definition(event_identity), line, trace); - - ; - } + } } delete parserdefinition; delete parserevent; - return; } diff --git a/parser/src/ParserPaje.hpp b/parser/src/ParserPaje.hpp index 2ffb498e..6bdf4aea 100644 --- a/parser/src/ParserPaje.hpp +++ b/parser/src/ParserPaje.hpp @@ -4,6 +4,7 @@ #include <iostream> #include <fstream> #include <string> + #include "ParserDefinitionDecoder.hpp" #include "ParserEventDecoder.hpp" #include "Parser.hpp" @@ -22,7 +23,6 @@ */ class ParserPaje : public Parser{ - public: /*! * \fn parse(std::string filename, Trace &trace) @@ -30,10 +30,7 @@ public: * \param trace : the structure of data to fill */ void parse(std::string filename, Trace &trace); - - - - + }; #endif // PARSERPAJE_HPP diff --git a/parser/src/TokenSource.cpp b/parser/src/TokenSource.cpp index 62d38efa..1d9dfd18 100644 --- a/parser/src/TokenSource.cpp +++ b/parser/src/TokenSource.cpp @@ -5,12 +5,12 @@ using namespace std; TokenSource::TokenSource(){ //no file are opened //you must use open later - _eof = true; + _is_eof = true; } TokenSource::TokenSource(const char *filename){ - sopen(filename); + open(filename); } TokenSource::~TokenSource(){ @@ -24,16 +24,16 @@ TokenSource::~TokenSource(){ #endif } -void TokenSource::sopen(const char *filename){ +void TokenSource::open(const char *filename){ _cursor = 0; - _eof = false; + _is_eof = false; #ifdef WIN32 _file.open(filename, ios::in); fill_buffer(); #else - if ((_fd = open(filename, O_RDONLY)) == -1){ + if ((_fd = ::open(filename, O_RDONLY)) == -1){ perror("error : open file"); exit(-1); } @@ -104,15 +104,13 @@ void TokenSource::build_composite_token(){ return; } #endif - do{ + do { _token.push_back(_buffer[_cursor]); _cursor ++; - if (ensure_capacity()){ break; } - } while(_buffer[_cursor] != '"'); _cursor ++; @@ -124,12 +122,10 @@ void TokenSource::build_simple_token(){ while(_buffer[_cursor] != ' ' && _buffer[_cursor] != '\n' && _buffer[_cursor] != '\t'){ _token.push_back(_buffer[_cursor]); _cursor ++; - if (ensure_capacity()){ break; } - } } @@ -137,16 +133,16 @@ bool TokenSource::ensure_capacity(){ #ifdef WIN32 if (_cursor >= _buffer_size){ if (!fill_buffer()){ - _eof = true; + _is_eof = true; return true; } _cursor = 0; } return false; #else - if (_cursor < _filesize) + if (_cursor < _filesize) return false; - _eof = true; + _is_eof = true; return true; #endif } @@ -165,20 +161,21 @@ void TokenSource::build_definition_starter(){ _cursor ++; ensure_capacity(); _token.push_back('%'); - } -std::string *TokenSource::lire_token(){ + +std::string *TokenSource::read_token(){ //regexp recognition //a token is //(1) a line break //(2) composite : a char buffer delimited by \" //(3) a char buffer delimited by space - if (!_token.empty()) - _token.clear(); - - if (_eof){ + if (!_token.empty()){ + _token.clear(); + } + + if (_is_eof){ return NULL; } @@ -198,7 +195,5 @@ std::string *TokenSource::lire_token(){ build_composite_token(); } - - return &_token; } diff --git a/parser/src/TokenSource.hpp b/parser/src/TokenSource.hpp index ffa786df..f10d4a49 100644 --- a/parser/src/TokenSource.hpp +++ b/parser/src/TokenSource.hpp @@ -5,17 +5,17 @@ #include <iostream> #ifdef WIN32 // They do not have mmap - #define BUFFER_SIZE 2048 - #define WORD_SIZE 64 - #include <fstream> + #define BUFFER_SIZE 2048 + #define WORD_SIZE 64 + #include <fstream> #else - #include <sys/types.h> - #include <sys/stat.h> - #include <fcntl.h> - #include <sys/mman.h> - #include <stdio.h> - #include <stdlib.h> - #include <unistd.h> + #include <sys/types.h> + #include <sys/stat.h> + #include <fcntl.h> + #include <sys/mman.h> + #include <stdio.h> + #include <stdlib.h> + #include <unistd.h> #endif /*! @@ -25,7 +25,7 @@ class TokenSource{ private: - + #ifdef WIN32 char _buffer[BUFFER_SIZE]; #else @@ -34,14 +34,14 @@ private: std::string _token; int _cursor; + + bool _is_eof; #ifdef WIN32 int _buffer_size; - bool _eof; std::ifstream _file; #else off_t _filesize; - bool _eof; int _fd; #endif @@ -59,48 +59,40 @@ private: void build_simple_token(); public: - - + + /*! + * \fn TokenSource() + * \brief This constructor needs a file to be opened + */ + TokenSource(); + /*! * \fn TokenSource(const char* filename); * \brief Constructor opening a file - * \param Valid filename + * \param filename the name of the file we want to open. */ TokenSource(const char* filename); - - - /*! - * \fn TokenSource - * \brief This constructor needs a file to be openned + * \fn ~TokenSource + * \brief Destuctor which release the file */ - TokenSource(); - + ~TokenSource(); /*! * \fn open(const char *filename) * \brief open a file - * \param valid filename + * \param filename the name of the file we want to open. */ - void sopen(const char *filename); - - + void open(const char *filename); /*! - * \fn lire_token + * \fn read_token * \brief supplies a token * \return a \\0-ended character string (char*), NULL if the file ended, NULL if no file is opened */ - std::string* lire_token(); - - - /*! - * \fn ~TokenSource - * \brief Destuctor which release the file - */ - ~TokenSource(); + std::string* read_token(); }; diff --git a/trace/src/values/Color.hpp b/trace/src/values/Color.hpp index 39b8c1a1..1567b570 100644 --- a/trace/src/values/Color.hpp +++ b/trace/src/values/Color.hpp @@ -42,7 +42,7 @@ public: /*! * - * \fn instantiate(const std::string &in, Color &out) + * \fn instantiate(std::string &in, Color &out) * \brief Convert a string to a Color * \param in String to convert * \param out Color to be initialized @@ -62,7 +62,7 @@ public: private: /*! * - * \fn replace_in_string(std::string &characters, char to_replace, char replace_by) const + * \fn replace_in_string(std::string &characters, char to_replace, char replace_by) * \brief Replace in the string the character to_replace by replace_by. * \param characters string to be replaced. * \param to_replace the character we want to replace. diff --git a/trace/src/values/Date.hpp b/trace/src/values/Date.hpp index 760b7ea6..c950055b 100644 --- a/trace/src/values/Date.hpp +++ b/trace/src/values/Date.hpp @@ -24,7 +24,7 @@ class Date: public Value { private : double _value; -public: +public : /*! * \brief Constructor */ @@ -43,27 +43,66 @@ public: * \param out Date to be initialized * \return true, if the conversion succeeded * - */ + */ static bool instantiate(const std::string &in, Date &out); /*! * * \fn to_string() const * \return a string of the date - */ + */ std::string to_string() const; - /*! + /*! * * \fn get_value() const * \return the value - */ + */ double get_value() const; + /*! + * + * \fn operator< (const Date &) const + * \brief Compare the date + * \return true if the Date is lower than this. + * + */ bool operator<(const Date &) const; + + /*! + * + * \fn operator> (const Date &) const + * \brief Compare the date + * \return true if the Date is greater than this. + * + */ bool operator>(const Date &) const; + + /*! + * + * \fn operator<= (const Date &) const + * \brief Compare the date + * \return true if the Date is lower or equal than this. + * + */ bool operator<=(const Date &) const; + + /*! + * + * \fn operator>= (const Date &) const + * \brief Compare the date + * \return true if the Date is greater or equal than this. + * + */ bool operator>=(const Date &) const; + + /*! + * + * \fn operator- (const Date &) const + * \brief Make the difference between two Dates + * \return the difference of the two values + * + */ double operator-(const Date &) const; }; diff --git a/trace/src/values/String.hpp b/trace/src/values/String.hpp index 51fb2f5d..156fc6d5 100644 --- a/trace/src/values/String.hpp +++ b/trace/src/values/String.hpp @@ -53,12 +53,14 @@ public: /*! * \fn operator ==(const std::string &) const + * \return true if they are equals. */ bool operator ==(const std::string &) const; + /*! * \fn operator= (const std::string &) + * \return this String with the new value. */ - String operator= (const std::string &); }; diff --git a/trace/src/values/Value.hpp b/trace/src/values/Value.hpp index 41eee36b..69edd8c2 100644 --- a/trace/src/values/Value.hpp +++ b/trace/src/values/Value.hpp @@ -24,6 +24,8 @@ public: /*! * * \fn to_string() const = 0 + * \brief a to string method. + * \return the value in a string format. * */ virtual std::string to_string() const = 0; diff --git a/trace/src/values/Values.hpp b/trace/src/values/Values.hpp new file mode 100644 index 00000000..881183c7 --- /dev/null +++ b/trace/src/values/Values.hpp @@ -0,0 +1,22 @@ +#ifndef VALUES_HPP +#define VALUES_HPP + +/*! + * + * \file Values.hpp + * \author Johnny Jazeix + * \brief Contains the include of all the headers from this directory + * \date 2009 February 23rd + * + */ + +#include "Color.hpp" +#include "Date.hpp" +#include "Double.hpp" +#include "Hex.hpp" +#include "Integer.hpp" +#include "Name.hpp" +#include "String.hpp" +#include "Value.hpp" + +#endif // VALUES_HPP -- GitLab