Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 658dddcf authored by Pascal Noisette's avatar Pascal Noisette
Browse files

codage

parent 7840eff8
Branches
No related tags found
No related merge requests found
#include "ParserDefinitionDecoder"
using namespace std;
int ParserDefinitionDecoder::definitions_number(){
return definitions.size();
}
void ParserDefinitionDecoder::store_definition(Line &line, ifstream &file){
//read header of one definition
string &tokens = line.read_token();
Definition d = Definition(token[2]);
Definitions[tokens[3]] = d;
//read list of parameters
while (line.store(f))
{
if(line == "%EndEventDef")
break;
tokens = line.read_token();
if (tokens.length()!=3)
//warning();
;
d.store(token[1],token[2]);
}
}
Definition& ParserDefinitionDecoder::get_definition(int i){
return Definitions[i];
}
...@@ -26,14 +26,29 @@ private: ...@@ -26,14 +26,29 @@ private:
int typetoint(std::string); int typetoint(std::string);
public: public:
/*!
* \brief : constructor
* \param : string event name
*
*/
Definition(String& eventname);
/*! /*!
* \brief : add a field * \brief : add a field to definition
* \param : name * \param : name
* \param : value * \param : value
*/ */
store(std::string name,std::string value); void store(std::string name,std::string value);
void print()
/*!
* \brief : print() : debug
*
*
*/
void print();
} }
......
#include <Line.hpp>
//std::vector<std::string> tokens;
// string buffer;
int starttoken(int* cursor){
while(line[cursor]==' ')
cursor++;
return cursor;
}
int stopnexttoken(int* cursor){
while(line[cursor]!=' ' || line[cursor]!='\n' || line[cursor]!='\0')
cursor++;
return cursor;
}
void Line::store(std::ifstream &file){
char buffer[BUFFSIZE];
file.getline (buffer,BUFFSIZE);
string line = buffer;
this.store(line);
}
void Line::store(std::string s){
int cursor = 0;
int start;
int stop;
while(cursor<line.length())
{
start = starttoken(&cursor);
stop = endtoken(&cursor);
tokens.push_back(line.substr(start,stop));
}
}
void Line::tokenize();
Line::Line();
Line::Line(Line &);
Line::~Line();
bool Line::starts_with(std::string & s)
{
return tokens[0].compare(s)==0;
}
bool Line::operator== (std::string s)
{
Line l;
l.store(s);
this == l;
}
bool Line::operator== (Line)
{
if (this.length==l.lentgth)
{
for (int i =0;i<this.length();i++)
if (this.item(i)==l.item(i))
return false;
return true
}
else
return false;
}
std::string& Line::item (int i );
int Line::length();
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#define BUFFSIZE 256
/*! \class Line Line.hpp "../parser/src/Line.hpp" /*! \class Line Line.hpp "../parser/src/Line.hpp"
* Contains the definition of a line. * Contains the definition of a line.
...@@ -12,7 +13,19 @@ class Line{ ...@@ -12,7 +13,19 @@ class Line{
private: private:
std::vector<std::string> token; std::vector<std::string> tokens;
/*!
* \brief tokenize() divide into tokens
*
*/
void tokenize();
public: public:
/*! /*!
* \brief Constructor * \brief Constructor
...@@ -26,32 +39,46 @@ public: ...@@ -26,32 +39,46 @@ public:
* \param : A reference of the line to be copied * \param : A reference of the line to be copied
*/ */
Line(Line &); Line(Line &);
/*! /*!
* \brief Destructor * \brief Destructor
* Destroy the line * Destroy the line
*/ */
~Line(); ~Line();
/*! /*!
* \param : the string we want to know if the line starts with it * \param : the string we want to know if the line starts with it
* \return : true if ths line starts with the param, false else * \return : true if the line starts with the param, false else
*/ */
bool starts_with(std::string &); bool starts_with(std::string &);
/*! /*!
* \brief store() read the next line and divide into tokens * \brief store() read the next line and divide into tokens
* *
*/ */
bool store(std::ifstream &); void store(std::ifstream &);
/*!
* \brief line compare
*
*/
bool operator== (std::string &);
/*! /*!
* \brief next token if exist * \brief the ith token in the line
* *
*/ */
std::string operator[] (); std::string& item (int i );
bool operator== (std::string &);
int length();
/*!
* \brief number of token
*
*/
int length();
}; };
......
using namespace std;
int ParserDefinitionDecoder::definitions_number(){
return definitions.size();
}
void ParserDefinitionDecoder::store_definition(Line &line, ifstream &file){
//read header of one definition
line.store(file);
Definition d = Definition(line.item(2));
Definitions[line.item(3)] = d;
//read list of parameters
while (line.store(file))
{
if(line == "%EndEventDef")
break;
if (line.length()!=3)
//warning();
;
d.store(line.item(1),line.item(2));
}
}
Definition& ParserDefinitionDecoder::get_definition(int i){
return Definitions[i];
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment