Commit aa018e70 authored by Johnny Jazeix's avatar Johnny Jazeix

Ajout de la gestion des couleurs pour les points ou les virgules.

Normes sur render_svg et main.
TokenSource en un seul fichier avec macros pour différencier windows du 
reste du monde (à vérifier sous windows). Makefile sans les erreurs au 
cas où les fichiers n'existent pas pour la suppression.
parent a13157a3
......@@ -21,7 +21,7 @@ DIR_TRACE = trace/src
all:
# @(cd $(DIR_TRACE) && make)
# @(cd $(DIR_PARSER) && make)
@(cd $(DIR_INTERFACE) && make)
make -C $(DIR_INTERFACE)
@echo " "
@echo "Compilation completed! File created in 'bin' folder."
@echo " "
......@@ -35,9 +35,11 @@ doc:
debugs:
@(cd $(DIR_INTERFACE) && make debugs)
make debugs -C $(DIR_INTERFACE)
# @(cd $(DIR_INTERFACE) && make debugs)
# @(cd $(DIR_TRACE) && make)
@(cd $(DIR_PARSER) && make debug)
make debug -C $(DIR_PARSER)
# @(cd $(DIR_PARSER) && make debug)
@echo " "
@echo "Compilation completed! (debug)"
@echo " "
......@@ -52,8 +54,9 @@ clean:
# Must be called with option -i, otherwise an error occured in the first instructions, the followings won't be executed.
wash:
@(cd $(DIR_TRACE) && make clean)
@(cd $(DIR_INTERFACE) && make clean)
@(cd $(DIR_PARSER) && make clean)
make clean -C $(DIR_INTERFACE)
make clean -C $(DIR_TRACE)
make clean -C $(DIR_PARSER)
cd bin && $(RM) *
......@@ -65,7 +65,7 @@ clean:
# Must be called with option -i, otherwise an error occured in the first instructions, the followings won't be executed.
wash:
cd ./src && rm *~ *.o Makefile qrc_vite.cpp core
cd ./tests && rm *~ *.o Makefile core
cd ./bin && rm *.o
cd ./debug && rm *
cd ./src && $(RM) *~ *.o Makefile qrc_vite.cpp core
cd ./tests && $(RM) *~ *.o Makefile core
cd ./bin && $(RM) *.o
cd ./debug && $(RM) *
#include "render_svg.hpp"
using namespace std;
void Svg::rectangle()
{
_buffer << "<rect title='container' width='" << _w
<<"' height='"<< _h
<<"' x='" << _x
<<"' y='" << _y
<<"' fill='rgb("<<_r<<","<<_g<<","<<_b
<<")'/>";
afficher();
}
void Svg::rectangle(){
_buffer << "<rect title='container' width='" << _w
<<"' height='"<< _h
<<"' x='" << _x
<<"' y='" << _y
<<"' fill='rgb("<<_r<<","<<_g<<","<<_b
<<")'/>";
afficher();
}
void Svg::afficher()
{
void Svg::afficher(){
if (_buffer.str().size()>BUFFER_SIZE){
svg_file.write(_buffer.str().c_str(), _buffer.str().size());
if (_buffer.str().size()>BUFFER_SIZE){
_svg_file.write(_buffer.str().c_str(), _buffer.str().size());
_buffer.flush();
}
}
}
}
void Svg::init(char * path)
{
void Svg::init(char *path){
svg_file.open(path , ofstream::out | ofstream::trunc);
_svg_file.open(path , ofstream::out | ofstream::trunc);
if (svg_file.is_open()==false){
if (_svg_file.is_open()==false){
std::cerr<<"unable to open file";
}
_buffer << "<?xml version='1.0' encoding='utf-8' standalone='no'?>\n<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 20010904//EN' 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>\n<svg xmlns='http://www.w3.org/2000/svg' x='0' y='0' width='1280' height='728' id='svg2'>\n\t<style type='text/css' id='stylecss' >\n\t\trect:hover\n\t\t\t{\n\t\t\t\tfill:#8fbbd0;\n\t\t\t}\n\t</style>\n\t<desc>Rectangles</desc>\n";
afficher();
}
void Svg::end()
{
_buffer << "</svg>";
svg_file.write(_buffer.str().c_str(), _buffer.str().size());
_buffer.flush();
svg_file.close();
}
void Svg::draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h)
{
_r=0xff;
_g=0x44;
_b=0xcc;
_w=(unsigned long)w;
_h=(unsigned long)h;
_x=(unsigned long)x;
_y=(unsigned long)y;
rectangle();
}
void Svg::draw_state(const Element_pos start , const Element_pos end, const Element_count level, const Element_col r, const Element_col g, const Element_col b)
{
_r=(unsigned char)r;
_g=(unsigned char)g;
_b=(unsigned char)b;
_w=(unsigned long)(end-start);
_h=(unsigned long)LEVEL - 10;
_x=(unsigned long)start;
_y=(unsigned long)level*LEVEL;
rectangle();
}
}
_buffer << "<?xml version='1.0' encoding='utf-8' standalone='no'?>\n<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 20010904//EN' 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>\n<svg xmlns='http://www.w3.org/2000/svg' x='0' y='0' width='1280' height='728' id='svg2'>\n\t<style type='text/css' id='stylecss' >\n\t\trect:hover\n\t\t\t{\n\t\t\t\tfill:#8fbbd0;\n\t\t\t}\n\t</style>\n\t<desc>Rectangles</desc>\n";
afficher();
}
void Svg::end(){
_buffer << "</svg>";
_svg_file.write(_buffer.str().c_str(), _buffer.str().size());
_buffer.flush();
_svg_file.close();
}
void Svg::draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h){
_r=0xff;
_g=0x44;
_b=0xcc;
_w=(unsigned long)w;
_h=(unsigned long)h;
_x=(unsigned long)x;
_y=(unsigned long)y;
rectangle();
}
void Svg::draw_state(const Element_pos start , const Element_pos end, const Element_count level, const Element_col r, const Element_col g, const Element_col b){
_r=(unsigned char)r;
_g=(unsigned char)g;
_b=(unsigned char)b;
_w=(unsigned long)(end-start);
_h=(unsigned long)LEVEL - 10;
_x=(unsigned long)start;
_y=(unsigned long)level*LEVEL;
rectangle();
}
#ifndef RENDER_SGV
#ifndef RENDER_SVG
#define RENDER_SVG
#include <stdio.h>
#include <iostream>
......@@ -6,8 +6,6 @@
#include <fstream>
#define BUFFER_SIZE 2048
#define LEVEL 110
using namespace std;
typedef unsigned long Element_count ;
typedef double Element_pos;
......@@ -17,44 +15,44 @@ typedef unsigned int Element_col;
class Svg{
private:
private:
ostringstream _buffer;
ofstream svg_file;
ofstream _svg_file;
unsigned int _r,_g,_b;
unsigned long _x,_y,_w,_h;
void afficher();
void rectangle();
public:
/*!
public:
/*!
* \brief SVG header buiding
*/
void init(char *path);
void init(char *path);
/*!
/*!
* \brief SVG bottom file buiding
*/
void end();
void end();
/*!
/*!
* \brief Draw a container according to the parameters
* \param x the x position of the container
* \param y the y position of the container
* \param w the width of the container
* \param h the height of the container
*/
void draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h) ;
/*!
* \brief Draw a state of the trace.
* \param r the red color rate of the state.
* \param g the green color rate of the state.
* \param b the blue color rate of the state.
* \param start the beginning time of the state.
* \param end the ending time of the state.
* \param level refer to the container which state belongs to.
*/
void draw_state(const Element_pos start , const Element_pos end, const Element_count level, const Element_col r, const Element_col g, const Element_col b) ;
};
#endif// RENDER_SGV
void draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h) ;
/*!
* \brief Draw a state of the trace.
* \param r the red color rate of the state.
* \param g the green color rate of the state.
* \param b the blue color rate of the state.
* \param start the beginning time of the state.
* \param end the ending time of the state.
* \param level refer to the container which state belongs to.
*/
void draw_state(const Element_pos start , const Element_pos end, const Element_count level, const Element_col r, const Element_col g, const Element_col b) ;
};
#endif // RENDER_SVG
......@@ -13,8 +13,7 @@
/*!
*\brief The main function of ViTE.
*/
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
glutInit(&argc, argv);
Interface_console console(argc, argv);
......
#ifndef MAPPINGDENIED
#include "TokenSource_mmap.cpp"
#include "TokenSource.hpp"
using namespace std;
TokenSource::TokenSource(){
//no file are opened
//you must use open later
_eof = true;
}
TokenSource::TokenSource(const char *filename){
sopen(filename);
}
TokenSource::~TokenSource(){
#ifdef WIN32
_file.close();
#else
#include "TokenSource_fstream.hpp"
if (munmap(_buffer, _filesize) == -1){
perror("error : munmap");
}
close(_fd);
#endif
}
void TokenSource::sopen(const char *filename){
_cursor = 0;
_eof = false;
#ifdef WIN32
_file.open(filename, ios::in);
fill_buffer();
#else
if ((_fd = open(filename, O_RDONLY)) == -1){
perror("error : open file");
exit(-1);
}
struct stat buf;
if(fstat(_fd, &buf) == -1){
perror("error status file");
exit(-1);
}
_filesize = buf.st_size;
if ((_buffer = (char *)mmap(0, _filesize, PROT_READ, MAP_PRIVATE, _fd, 0)) == MAP_FAILED){
perror("error mmap");
exit(-1);
}
#endif
}
#ifdef WIN32
bool TokenSource::fill_buffer(){
if (_file.eof()){
return false;
}
else{
_file.read(_buffer, BUFFER_SIZE);
_buffer_size = _file.gcount();
return true;
}
}
#endif
bool TokenSource::go_to_next_token(){
while(_buffer[_cursor] == ' ' || _buffer[_cursor] == '\t'){
_cursor ++;
#ifdef WIN32
if (_cursor >= _buffer_size){
if (!fill_buffer()){
return true;
}
_cursor = 0;
}
#else
if(ensure_capacity())
break;
#endif
}
return false;
}
void TokenSource::build_composite_token(){
_cursor ++;
#ifdef WIN32
if (_cursor == _buffer_size){
if (!fill_buffer()){
cout << "found \" at end of file" << endl;
return;
}
_cursor = 0;
}
#else
if (ensure_capacity()){
cout << "error :found \" at end of file" << endl;
return;
}
#endif
do{
_token.push_back(_buffer[_cursor]);
_cursor ++;
if (ensure_capacity()){
break;
}
}
while(_buffer[_cursor] != '"');
_cursor ++;
ensure_capacity();
}
void TokenSource::build_simple_token(){
while(_buffer[_cursor] != ' ' && _buffer[_cursor] != '\n' && _buffer[_cursor] != '\t'){
_token.push_back(_buffer[_cursor]);
_cursor ++;
if (ensure_capacity()){
break;
}
}
}
bool TokenSource::ensure_capacity(){
#ifdef WIN32
if (_cursor >= _buffer_size){
if (!fill_buffer()){
_eof = true;
return true;
}
_cursor = 0;
}
return false;
#else
if (_cursor < _filesize)
return false;
_eof = true;
return true;
#endif
}
void TokenSource::build_line_breaks(){
while(_buffer[_cursor] == '\n'){
_cursor ++;
if (ensure_capacity()){
break;
}
}
_token.push_back('\n');
}
void TokenSource::build_definition_starter(){
_cursor ++;
ensure_capacity();
_token.push_back('%');
}
std::string *TokenSource::lire_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){
return NULL;
}
if(go_to_next_token())
return NULL;
if (_buffer[_cursor] == '\n'){
build_line_breaks();
}
else if (_buffer[_cursor] == '%'){
build_definition_starter();
}
else if (_buffer[_cursor] != '"'){
build_simple_token();
}
else{
build_composite_token();
}
return &_token;
}
#ifndef TOKENSOURCE_HPP
#define TOKENSOURCE_HPP
#include <string>
#include <iostream>
#ifndef MAPPINGDENIED
#include "TokenSource_mmap.hpp"
#ifdef WIN32 // They do not have mmap
#define BUFFER_SIZE 2048
#define WORD_SIZE 64
#include <fstream>
#else
#include "TokenSource_fstream.hpp"
#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
/*!
* \class TokenSource
* \brief supply tokens from a file trace. Tokens are word unit used in PajeFile trace formats.
*/
class TokenSource{
private:
#ifdef WIN32
char _buffer[BUFFER_SIZE];
#else
char* _buffer;
#endif
std::string _token;
int _cursor;
#ifdef WIN32
int _buffer_size;
bool _eof;
std::ifstream _file;
#else
off_t _filesize;
bool _eof;
int _fd;
#endif
#ifdef WIN32
bool fill_buffer();
#endif
bool go_to_next_token();
bool ensure_capacity();
void build_definition_starter();
void build_line_breaks();
void build_composite_token();
void build_simple_token();
public:
/*!
* \fn TokenSource(const char* filename);
* \brief Constructor opening a file
* \param Valid filename
*/
TokenSource(const char* filename);
/*!
* \fn TokenSource
* \brief This constructor needs a file to be openned
*/
TokenSource();
/*!
* \fn open(const char *filename)
* \brief open a file
* \param valid filename
*/
void sopen(const char *filename);
/*!
* \fn lire_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();
};
#endif // TOKENSOURCE_HPP
#include "TokenSource.hpp"
using namespace std;
TokenSource::TokenSource(){
//no file are opened
//you must use open later
_eof = true;
}
TokenSource::TokenSource(const char *filename){
sopen(filename);
}
TokenSource::~TokenSource(){
_file.close();
}
void TokenSource::sopen(const char *filename){
_cursor = 0;
_eof = false;
_file.open(filename, ios::in);
fill_buffer();
}
bool TokenSource::fill_buffer(){
if (_file.eof()){
return false;
}
else{
_file.read(_buffer, BUFFER_SIZE);
_buffer_size = _file.gcount();
return true;
}
}
bool TokenSource::go_to_next_token(){
while(_buffer[_cursor] == ' ' || _buffer[_cursor] == '\t'){
_cursor ++;
if (_cursor >= _buffer_size){
if (!fill_buffer()){
return true;
}
_cursor = 0;
}
}
return false;
}
void TokenSource::build_composite_token(){
_cursor ++;
if (_cursor == _buffer_size){
if (!fill_buffer()){
cout << "found \" at end of file" << endl;
return;
}
_cursor = 0;
}
do{
_token.push_back(_buffer[_cursor]);
_cursor ++;