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

Affichage des compteurs (mais ne marche pas encore), Réécriture complète du...

Affichage des compteurs (mais ne marche pas encore), Réécriture complète du parcours des contenerus eurs pour l'affichage
parent d0e529e8
......@@ -47,6 +47,7 @@ message/endwarning.hpp \
trace/StateType.hpp \
trace/Link.hpp \
trace/LinkType.hpp \
trace/Variable.hpp \
trace/VariableType.hpp \
trace/Trace.hpp \
trace/values/Color.hpp \
......@@ -88,6 +89,7 @@ SOURCES += message/enderror.cpp \
trace/StateType.cpp \
trace/Link.cpp \
trace/Linktype.cpp \
trace/Variable.cpp \
trace/VariableType.cpp \
trace/Trace.cpp \
trace/values/Color.cpp \
......
......@@ -28,7 +28,7 @@ Container::~Container() {
clear_list<Link>(_links);
// Delete variables
for (map<VariableType *, list<pair<Date, Double> > *>::iterator it = _variables.begin();
for (map<VariableType *, Variable *>::iterator it = _variables.begin();
it != _variables.end();
it++) {
delete (*it).second;
......@@ -101,40 +101,38 @@ void Container::end_link(Date time, Container *destination, String key) {
}
void Container::set_variable(Date time, VariableType *type, Double value) {
map<VariableType *, list<pair<Date, Double> > *>::iterator i = _variables.find(type);
map<VariableType *, Variable *>::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));
_variables[type] = new Variable;
_variables[type]->add_value(time, value);
_n_variables++;
}
else {
(*i).second->push_back(pair<Date, Double>(time, value));
(*i).second->add_value(time, value);
}
}
void Container::add_variable(Date time, VariableType *type, Double value) {
map<VariableType *, list<pair<Date, Double> > *>::iterator i = _variables.find(type);
map<VariableType *, Variable *>::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));
_variables[type] = new Variable;
_variables[type]->add_value(time, value);
_n_variables++;
}
else {
(*i).second->push_back(pair<Date, Double>(time,
(*i).second->back().second + value));
(*i).second->add_value(time, (*i).second->get_last_value() + value);
}
}
void Container::sub_variable(Date time, VariableType *type, Double value) {
map<VariableType *, list<pair<Date, Double> > *>::iterator i = _variables.find(type);
map<VariableType *, Variable *>::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));
_variables[type] = new Variable;
_variables[type]->add_value(time, -value);
_n_variables++;
}
else {
(*i).second->push_back(pair<Date, Double>(time,
(*i).second->back().second - value));
(*i).second->add_value(time, (*i).second->get_last_value() - value);
}
}
......@@ -174,7 +172,7 @@ const list<Link *> *Container::get_links() const {
return &_links;
}
const map<VariableType *, list<pair<Date, Double> > *> *Container::get_variables() const {
const map<VariableType *, Variable *> *Container::get_variables() const {
return &_variables;
}
......
......@@ -16,7 +16,6 @@ using std::list;
using std::map;
#include <stack>
using std::stack;
using std::pair;
#include "values/Values.hpp"
......@@ -29,6 +28,7 @@ class Container;
#include "Link.hpp"
#include "VariableType.hpp"
#include "Variable.hpp"
#define STATE_STACK_SIZE 16
......@@ -49,7 +49,7 @@ private:
list<State *> _states;
list<Event *> _events;
list<Link *> _links;
map<VariableType *, list<pair<Date, Double> > *> _variables;
map<VariableType *, Variable *> _variables;
int _n_variables;
/*
......@@ -227,7 +227,7 @@ public:
* \brief Returns the variables
*
*/
const map<VariableType *, list<pair<Date, Double> > *> *get_variables() const;
const map<VariableType *, Variable *> *get_variables() const;
/*!
*
......
This diff is collapsed.
......@@ -184,6 +184,14 @@ StateType *Trace::search_state_type(String name) const {
}
VariableType *Trace::search_variable_type(String name) const {
for (list<VariableType *>::const_iterator it = _variable_types.begin();
it != _variable_types.end();
it++) {
if ((*it)->get_name() == name)
return *it;
}
// std::cout << "Unknown variable type: " << name.to_string() << std::endl;
return 0;
}
......
#include "Variable.hpp"
Variable::Variable(): _min(0.0), _max(0.0) {
}
void Variable::add_value(Date time, Double value) {
if (_values.empty())
_min = _max = value;
else if (value > _max)
_max = value;
else if (value < _min)
_min = value;
_values.push_back(pair<Date, Double>(time, value));
}
Double Variable::get_last_value() const {
return _values.back().second;
}
const list<pair<Date, Double> > *Variable::get_values() const {
return &_values;
}
Double Variable::get_min() const {
return _min;
}
Double Variable::get_max() const {
return _max;
}
#ifndef VARIABLE_HPP
#define VARIABLE_HPP
#include "values/Date.hpp"
#include "values/Double.hpp"
#include <list>
using std::list;
using std::pair;
class Variable {
private:
list<pair<Date, Double> > _values;
Double _min, _max;
public:
Variable();
void add_value(Date, Double);
Double get_last_value() const;
const list<pair<Date, Double> > *get_values() const;
Double get_min() const;
Double get_max() const;
};
#endif
......@@ -69,3 +69,11 @@ Double Double::operator-(const Double &d) {
return Double(_value - d._value);
}
bool Double::operator<(const Double &d) {
return _value < d._value;
}
bool Double::operator>(const Double &d) {
return _value > d._value;
}
......@@ -64,6 +64,8 @@ public:
Double operator+(const Double &);
Double operator-();
Double operator-(const Double &);
bool operator<(const Double &);
bool 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