Commit aff3d465 authored by Clément Vuchener's avatar Clément Vuchener

Ajout des liens

parent 5381dfd5
......@@ -34,6 +34,7 @@ HEADERS += interface.hpp \
../../trace/src/StateType.hpp \
../../trace/src/Event.hpp \
../../trace/src/EventType.hpp \
../../trace
../../trace/src/Trace.hpp \
../../trace/src/values/Color.hpp \
../../trace/src/values/Date.hpp \
......
......@@ -235,11 +235,11 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
}
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);
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), Integer(), extra_fields);
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 {
......
......@@ -45,6 +45,8 @@ HEADERS += main_resource.hpp \
trace/resource.hpp \
trace/State.hpp \
trace/StateType.hpp \
trace/Link.hpp \
trace/LinkType.hpp \
trace/Trace.hpp \
trace/values/Color.hpp \
trace/values/Date.hpp \
......@@ -82,6 +84,8 @@ SOURCES += main.cpp \
trace/EventType.cpp \
trace/State.cpp \
trace/StateType.cpp \
trace/Link.cpp \
trace/Linktype.cpp \
trace/Trace.cpp \
trace/values/Color.cpp \
trace/values/Date.cpp \
......
......@@ -3,7 +3,6 @@
Container::Container(Name name, Date creation_time, ContainerType *type, Container *parent):
_name(name), _creation_time(creation_time), _type(type), _parent(parent) {
_state_stack.index = -1;
}
template <class T>
......@@ -34,43 +33,62 @@ void Container::add_child(Container *child) {
void Container::add_current_state(Date end) {
_states.push_back(new State(
_state_stack.states[_state_stack.index].start,
_current_states.top().start,
end,
_state_stack.states[_state_stack.index].type,
_current_states.top().type,
this,
_state_stack.states[_state_stack.index].value));
_current_states.top().value));
}
void Container::set_state(Date time, StateType *type, EntityValue *value) {
if (_state_stack.index >= 0)
if (!_current_states.empty()) {
add_current_state(time);
else
_state_stack.index = 0;
_current_states.pop();
}
_state_stack.states[_state_stack.index] = (state_stack_t::current_state_t){time, type, value};
_current_states.push((current_state_t){time, type, value});
}
void Container::push_state(Date time, StateType *type, EntityValue *value) {
if (_state_stack.index >= 0)
if (!_current_states.empty())
add_current_state(time);
_state_stack.states[++_state_stack.index] = (state_stack_t::current_state_t){time, type, value};
_current_states.push((current_state_t){time, type, value});
}
void Container::pop_state(Date time) {
if (_state_stack.index >= 0) {
if (!_current_states.empty()) {
add_current_state(time);
--_state_stack.index;
_current_states.pop();
}
if (_state_stack.index >= 0) {
_state_stack.states[_state_stack.index].start = time;
if (!_current_states.empty()) {
_current_states.top().start = time;
}
}
void Container::new_event(Date time, EventType *type, EntityValue *value) {
_events.push_back(new Event(time, type, this, value));
}
void Container::start_link(Date time, LinkType *type, Container *source, EntityValue *value, String key) {
_current_links[key] = (current_link_t){time, type, source, value};
}
void Container::end_link(Date time, Container *destination, String key) {
map<String, current_link_t, String::less_than>::iterator i = _current_links.find(key);
if (i == _current_links.end()) /* TODO: Error message */
return;
_links.push_back(new Link(
(*i).second.start,
time,
(*i).second.type,
this,
(*i).second.source,
destination,
(*i).second.value));
_current_links.erase(i);
}
Name Container::get_name() const {
return _name;
......@@ -99,6 +117,14 @@ Date Container::get_destruction_time() const {
const list<State *> *Container::get_states() const {
return &_states;
}
const list<Event *> *Container::get_events() const {
return &_events;
}
const list<Link *> *Container::get_links() const {
return &_links;
}
void Container::destroy(const Date &time) {
_destruction_time = time;
......
......@@ -12,6 +12,10 @@
#include <list>
using std::list;
#include <map>
using std::map;
#include <stack>
using std::stack;
#include "values/Name.hpp"
#include "values/Date.hpp"
......@@ -22,6 +26,7 @@ class Container;
#include "State.hpp"
#include "Event.hpp"
#include "Link.hpp"
#define STATE_STACK_SIZE 16
......@@ -41,16 +46,28 @@ private:
list<Container *> _children;
list<State *> _states;
list<Event *> _events;
//list<Link *> _links;
list<Link *> _links;
struct state_stack_t {
struct current_state_t {
/*
* Temporary stores states before complete definition
*/
struct current_state_t {
Date start;
StateType *type;
EntityValue *value;
} states[STATE_STACK_SIZE];
int index;
} _state_stack;
};
stack<current_state_t> _current_states;
/*
* Temporary stores links before complete definition
*/
struct current_link_t {
Date start;
LinkType *type;
Container *source;
EntityValue *value;
};
map<String, current_link_t, String::less_than> _current_links;
void add_current_state(Date end);
......@@ -93,6 +110,20 @@ public:
*/
void new_event(Date time, EventType *type, EntityValue *value);
/*!
*
* \fn start_link(Date time, LinkType *type, Container *source, Container *destination, EntityValue *value, String key)
*
*/
void start_link(Date time, LinkType *type, Container *source, EntityValue *value, String key);
/*!
*
* \fn end_link(Date time, String key)
*
*/
void end_link(Date time, Container *destination, String key);
/*!
*
* \fn get_name() const
......@@ -144,11 +175,27 @@ public:
/*!
*
* \fn get_states() const
* \brief Returns the list of the states between min and max
* \brief Returns the state list
*
*/
const list<State *> *get_states() const;
/*!
*
* \fn get_events() const
* \brief Returns the event list
*
*/
const list<Event *> *get_events() const;
/*!
*
* \fn get_links() const
* \brief Returns the link list
*
*/
const list<Link *> *get_links() const;
/*!
*
* \fn destroy(const Date &time)
......
......@@ -8,7 +8,6 @@
#include "resource.hpp"
#include "../interface/render_area.hpp"
#include "../interface/render_svg.hpp"
......@@ -71,13 +70,9 @@ protected:
public:
/***********************************
*
*
*
* Constructor and destructor.
*
*
*
**********************************/
/*!
......@@ -107,13 +102,9 @@ public:
/***********************************
*
*
*
* Building functions.
*
*
*
**********************************/
......@@ -136,23 +127,12 @@ public:
draw_object->end_draw();
}
//protected:
/***********************************
*
*
*
* Browsing functions.
*
*
*
**********************************/
inline void browse_container_tree(T* draw_object, Trace* trace){
......@@ -195,51 +175,35 @@ public:
/***********************************
*
* Start loop.
*
**********************************/
while (isAnotherContainer == true){
while (isAnotherContainer == true) {
Element_pos buf_pos;
buf_pos = return_last_visited_child(position_stack);
/* If all children are not yet visited */
if (buf_pos < number_of_children(container)){
if (buf_pos < number_of_children(container)) {
/***********************************
*
* Browse children.
*
**********************************/
position_stack.top() ++;/* add a child */
position_stack.push(0);/* prepare for the next child */
container = get_container(container->get_children(), buf_pos);
x += _container_width+_container_h_space;/* if there is just one child, container can be draw horizontally */
}else{/* all children have been visited or there is not child, thus it's time to draw ! */
}
else { /* all children have been visited or there is not child, thus it's time to draw ! */
position_stack.pop();/* remove the information of the container hence it will be drawn */
if (1 >= number_of_children(container)){/* Should be drawn horizontally */
if (1 >= number_of_children(container)) { /* Should be drawn horizontally */
/***********************************
*
* Draw container with one or less child.
*
**********************************/
height_buf = 0;
if (0 == number_of_children(container)){
if (0 == number_of_children(container)) {
/* y contains the current height, y_buf the new adding height */
y_buf = _container_height+_container_v_space;
height_stack.push(y_buf);
......@@ -249,8 +213,9 @@ public:
_stack_states.push(container->get_states());
height_buf = _container_height;
}else
}
else
height_buf = height_stack.top()-_container_v_space;/* take the child's height */
......@@ -259,19 +224,16 @@ public:
draw_object->draw_container_text(x- _container_width+_container_h_space, y-height_buf/2, container->get_name().to_string());
x -= (_container_width + _container_h_space);
}
else{ /* Should be drawn vertically */
else { /* Should be drawn vertically */
/***********************************
*
* Draw container with more than one child.
*
**********************************/
height_buf = 0;
for (int i = 0 ; i < number_of_children(container) ; i ++){
for (int i = 0 ; i < number_of_children(container) ; i ++) {
height_buf += height_stack.top();
height_stack.pop();
}
......@@ -288,19 +250,15 @@ public:
}
/* Now, container was drawn. It's time to go back up */
if (container->get_parent() != NULL){
if (container->get_parent() != NULL) {
/***********************************
*
* Browse parents.
*
**********************************/
int buf = position_stack.top();
position_stack.pop();
if (container->get_parent()->get_parent() != NULL){
if (container->get_parent()->get_parent() != NULL) {
container = get_container( container->get_parent()->get_parent()->get_children(), position_stack.top()-1);/* '-1' because we continu with the same container, not the following */
}
else
......@@ -319,10 +277,10 @@ public:
}/* end browse_container_tree */
inline void browse_state_tree(T* draw_object){
/*!
* \brief Browse the states list and draw them
*/
inline void browse_state_tree(T* draw_object) {
const list<State *> *buf_list;
State* buf_entity;
Element_count i;/* for the level (y axis) of the states */
......@@ -332,7 +290,7 @@ public:
while (!_stack_states.empty()){
buf_list = _stack_states.top();
for(list<State *>::const_iterator it = buf_list->begin();
for (list<State *>::const_iterator it = buf_list->begin();
it != buf_list->end();
it++) {
......@@ -349,19 +307,15 @@ public:
}/* end while (!_stack_states.empty()) */
}/* end list */
}
/***********************************
*
*
*
* Browsing tools.
*
*
*
**********************************/
inline Element_count number_of_children(const Container* c){
......
#include "Link.hpp"
Link::Link(Date start, Date end, LinkType *type, Container *container, Container *source, Container *destination, EntityValue *value):
Entity(container), _start(start), _end(end), _type(type), _value(value), _source(source), _destination(destination) {
}
Date Link::get_start_time() const {
return _start;
}
Date Link::get_end_time() const {
return _end;
}
double Link::get_duration() const {
return _end - _start;
}
const LinkType *Link::get_type() const {
return _type;
}
const EntityValue *Link::get_value() const {
return _value;
}
const Container *Link::get_source() const {
return _source;
}
const Container *Link::get_destination() const {
return _destination;
}
#ifndef LINK_HPP
#define LINK_HPP
/*!
*
* \file Link.hpp
* \author Clément Vuchener
* \brief
* \date 2009 January 30th
*
*/
class Link;
#include "values/Date.hpp"
#include "LinkType.hpp"
#include "EntityValue.hpp"
#include "Entity.hpp"
/*!
*
* \class Link
* \brief An container link
*
*/
class Link: public Entity {
private:
Date _start, _end;
LinkType *_type;
EntityValue *_value;
Container *_source, *_destination;
public:
/*!
*
* \brief Constructor
*
*/
Link(Date start, Date end, LinkType *type, Container *container, Container *source, Container *destination, EntityValue *value);
/*!
*
* \fn get_start_time() const;
* \brief Returns the start time of the link
*
*/
Date get_start_time() const;
/*!
*
* \fn get_end_time() const
* \brief Returns the end time of the link
*
*/
Date get_end_time() const;
/*!
*
* \fn get_duration() const
* \brief Returns the duration of the link
*
*/
double get_duration() const;
/*!
*
* \fn get_type() const
* \brief Returns the type of the link
*
*/
const LinkType *get_type() const;
/*!
*
* \fn get_value() const
* \brief Returns the value of the link
*
*/
const EntityValue *get_value() const;
/*!
*
* \fn get_source() const
* \brief Returns the source container of the link
*
*/
const Container *get_source() const;
/*!
*
* \fn get_destination() const
* \brief Returns the destination container of the link
*
*/
const Container *get_destination() const;
};
#endif
#include "LinkType.hpp"
LinkType::LinkType(Name name, ContainerType *container_type, ContainerType *source_type, ContainerType *destination_type):
EntityType(name, container_type), _source_type(source_type), _destination_type(destination_type) {
}
#ifndef LINKTYPE_HPP
#define LINKTYPE_HPP
/*!
*
* \author Coulomb, Vuchener
* \brief Describes the type of the links
*
*/
class LinkType;
#include "EntityType.hpp"
#include "values/Name.hpp"
#include "ContainerType.hpp"
/*!
*
*\class LinkType
*\brief The class that describes the links
*
*/
class LinkType : public EntityType {
private:
ContainerType *_source_type, *_destination_type;