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

Compteurs

parent 132e80c8
......@@ -47,6 +47,7 @@ HEADERS += main_resource.hpp \
trace/StateType.hpp \
trace/Link.hpp \
trace/LinkType.hpp \
trace/VariableType.hpp \
trace/Trace.hpp \
trace/values/Color.hpp \
trace/values/Date.hpp \
......@@ -87,6 +88,7 @@ SOURCES += main.cpp \
trace/StateType.cpp \
trace/Link.cpp \
trace/Linktype.cpp \
trace/VariableType.cpp \
trace/Trace.cpp \
trace/values/Color.cpp \
trace/values/Date.cpp \
......
......@@ -2,7 +2,7 @@
#include <iostream>
Container::Container(Name name, Date creation_time, ContainerType *type, Container *parent):
_name(name), _creation_time(creation_time), _type(type), _parent(parent) {
_name(name), _creation_time(creation_time), _type(type), _parent(parent), _n_variables(0) {
}
template <class T>
......@@ -23,6 +23,16 @@ Container::~Container() {
// Delete events
clear_list<Event>(_events);
// Delete links
clear_list<Link>(_links);
// Delete variables
for (map<VariableType *, list<pair<Date, Double> > *>::iterator it = _variables.begin();
it != _variables.end();
it++) {
delete (*it).second;
}
}
void Container::add_child(Container *child) {
......@@ -89,6 +99,44 @@ void Container::end_link(Date time, Container *destination, String key) {
(*i).second.value));
_current_links.erase(i);
}
void Container::set_variable(Date time, VariableType *type, Double value) {
map<VariableType *, list<pair<Date, Double> > *>::iterator i = _variables.find(type);
if (i == _variables.end()) {
_variables[type] = new list<pair<Date, Double> >;
_variables[type]->push_back(pair<Date, Double>(time, value));
_n_variables++;
}
else {
(*i).second->push_back(pair<Date, Double>(time, value));
}
}
void Container::add_variable(Date time, VariableType *type, Double value) {
map<VariableType *, list<pair<Date, Double> > *>::iterator i = _variables.find(type);
if (i == _variables.end()) {
_variables[type] = new list<pair<Date, Double> >;
_variables[type]->push_back(pair<Date, Double>(time, value));
_n_variables++;
}
else {
(*i).second->push_back(pair<Date, Double>(time,
(*i).second->back().second + value));
}
}
void Container::sub_variable(Date time, VariableType *type, Double value) {
map<VariableType *, list<pair<Date, Double> > *>::iterator i = _variables.find(type);
if (i == _variables.end()) {
_variables[type] = new list<pair<Date, Double> >;
_variables[type]->push_back(pair<Date, Double>(time, -value));
_n_variables++;
}
else {
(*i).second->push_back(pair<Date, Double>(time,
(*i).second->back().second - value));
}
}
Name Container::get_name() const {
return _name;
......@@ -115,15 +163,23 @@ Date Container::get_destruction_time() const {
}
const list<State *> *Container::get_states() const {
return &_states;
return &_states;
}
const list<Event *> *Container::get_events() const {
return &_events;
return &_events;
}
const list<Link *> *Container::get_links() const {
return &_links;
return &_links;
}
const map<VariableType *, list<pair<Date, Double> > *> *Container::get_variables() const {
return &_variables;
}
int Container::get_variable_number() const {
return _n_variables;
}
void Container::destroy(const Date &time) {
......
......@@ -16,9 +16,9 @@ using std::list;
using std::map;
#include <stack>
using std::stack;
using std::pair;
#include "values/Name.hpp"
#include "values/Date.hpp"
#include "values/Values.hpp"
#include "ContainerType.hpp"
......@@ -28,6 +28,8 @@ class Container;
#include "Event.hpp"
#include "Link.hpp"
#include "VariableType.hpp"
#define STATE_STACK_SIZE 16
/*!
......@@ -47,6 +49,8 @@ private:
list<State *> _states;
list<Event *> _events;
list<Link *> _links;
map<VariableType *, list<pair<Date, Double> > *> _variables;
int _n_variables;
/*
* Temporary stores states before complete definition
......@@ -124,6 +128,27 @@ public:
*/
void end_link(Date time, Container *destination, String key);
/*!
*
* \fn set_variable(Date time, VariableType *type, Double value)
*
*/
void set_variable(Date time, VariableType *type, Double value);
/*!
*
* \fn add_variable(Date time, VariableType *type, Double value)
*
*/
void add_variable(Date time, VariableType *type, Double value);
/*!
*
* \fn set_variable(Date time, VariableType *type, Double value)
*
*/
void sub_variable(Date time, VariableType *type, Double value);
/*!
*
* \fn get_name() const
......@@ -196,6 +221,22 @@ public:
*/
const list<Link *> *get_links() const;
/*!
*
* \fn get_variables() const
* \brief Returns the variables
*
*/
const map<VariableType *, list<pair<Date, Double> > *> *get_variables() const;
/*!
*
* \fn get_variable_number() const
* \brief Returns the number of variables
*
*/
int get_variable_number() const;
/*!
*
* \fn destroy(const Date &time)
......
......@@ -206,7 +206,8 @@ public:
if (0 == number_of_children(container)) {
/* y contains the current height, y_buf the new adding height */
y_buf = _container_height+_container_v_space;
int n = container->get_variable_number();
y_buf = (1+n)*(_container_height+_container_v_space);
height_stack.push(y_buf);
y += y_buf;
......@@ -294,6 +295,8 @@ public:
Event *event;
const list<Link *> *link_list;
Link *link;
const map<VariableType *, list<pair<Date, Double> > *> *variable_map;
list<pair<Date, Double> > *variable_values;
const map<std::string, Value *> *extra_fields;
const Color *color;
Element_count i;/* for the level (y axis) of the states */
......@@ -339,6 +342,27 @@ public:
draw_object->draw_event(event->get_time().get_value(), base, _state_height);
}/* end for */
// Browse events
variable_map = container->get_variables();
for (map<VariableType *, list<pair<Date, Double> > *>::const_iterator it = variable_map->begin();
it != variable_map->end();
it++) {
i++; // Variable are on another line
variable_values = (*it).second;
draw_object->start_draw_counter();
for (list<pair<Date, Double> >::const_iterator value = variable_values->begin();
value != variable_values->end();
value++) {
Element_pos base = ((Element_pos)i)*(_container_height+_container_v_space)+_container_v_space+(*value).second.get_value();
/* Call the object state drawing function */
draw_object->draw_counter((*value).first.get_value(), base);
}
draw_object->end_draw_counter();
}/* end for */
/* next container */
_leaf_containers.pop();
i++;
......
......@@ -12,9 +12,6 @@ class StateType;
#include "EntityType.hpp"
#include "values/Name.hpp"
#include "ContainerType.hpp"
/*!
*
*\class StateType
......
......@@ -51,7 +51,8 @@ void Trace::define_state_type(Name &name, ContainerType *container_type, const m
}
void Trace::define_variable_type(Name &name, ContainerType *container_type, const map<std::string, Value *> &opt) {
if (container_type)
_variable_types.push_back(new VariableType(name, container_type));
}
void Trace::define_link_type(Name &name, ContainerType *ancestor, ContainerType *source, ContainerType *destination, const map<std::string, Value *> &opt) {
......@@ -85,15 +86,18 @@ void Trace::new_event(Date &time, EventType *type, Container *container, EntityV
}
void Trace::set_variable(Date &time, VariableType *type, Container *container, Double value, const map<std::string, Value *> &opt) {
if (container)
container->set_variable(time, type, value);
}
void Trace::add_variable(Date &time, VariableType *type, Container *container, Double value, const map<std::string, Value *> &opt) {
if (container)
container->add_variable(time, type, value);
}
void Trace::sub_variable(Date &time, VariableType *type, Container *container, Double value, const map<std::string, Value *> &opt) {
if (container)
container->sub_variable(time, type, value);
}
void Trace::start_link(Date &time, LinkType *type, Container *ancestor, Container *source, EntityValue *value, String key, const map<std::string, Value *> &opt) {
......
......@@ -30,14 +30,12 @@ using std::vector;
#include "StateType.hpp"
#include "EventType.hpp"
#include "LinkType.hpp"
#include "VariableType.hpp"
#include "EntityValue.hpp"
#include "State.hpp"
#include "Event.hpp"
#include "Link.hpp"
class VariableType;
class LinkType;
/*!
*
* \class Trace
......@@ -52,6 +50,7 @@ private:
list <StateType *> _state_types;
list <EventType *> _event_types;
list <LinkType *> _link_types;
list <VariableType *> _variable_types;
public :
......
......@@ -47,3 +47,16 @@ std::string Double::to_string() const{
double Double::get_value() const{
return _value;
}
Double Double::operator+(const Double &d) {
return Double(_value + d._value);
}
Double Double::operator-() {
return Double(-_value);
}
Double Double::operator-(const Double &d) {
return Double(_value - d._value);
}
......@@ -60,6 +60,10 @@ public:
*
*/
double get_value() const;
Double operator+(const Double &);
Double operator-();
Double operator-(const Double &);
};
#endif // DOUBLE_HPP
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment