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

Ajout des des derniers états lorsque le conteneur n'est pas détruit

parent 5d104643
......@@ -20,18 +20,16 @@ void ParserPaje::parse(string filename, Trace &trace){
string event_identity_string;
unsigned int event_identity;
while(!line.is_eof()){
line.newline();
while(!line.is_eof()) {
line.newline();
if(line.starts_with(PERCENT)){
if(line.starts_with(PERCENT)){
parserdefinition->store_definition(line);
}
else if (!line.item(0, event_identity_string)){
else if (!line.item(0, event_identity_string)){
continue; // We have \n
}
else{
}
else{
// We check if we have an event identifier
if(sscanf(event_identity_string.c_str(), "%d", &event_identity) != 1){
Error::set_and_print(Error::_EXPECT_ID_DEF, line.get_line_count(), Error::_ERROR);
......@@ -48,6 +46,8 @@ void ParserPaje::parse(string filename, Trace &trace){
}
}
trace.finish();
// We print the warnings and errors
Error::print_numbers();
Error::flush_in_file("log.txt");
......
......@@ -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), _n_variables(0) {
_name(name), _creation_time(creation_time), _destruction_time(0.0), _type(type), _parent(parent), _n_variables(0) {
}
template <class T>
......@@ -48,6 +48,7 @@ void Container::add_current_state(Date end) {
_current_states.top().type,
this,
_current_states.top().value));
_n_states++;
}
void Container::set_state(Date time, StateType *type, EntityValue *value) {
......@@ -79,6 +80,7 @@ void Container::pop_state(Date time) {
void Container::new_event(Date time, EventType *type, EntityValue *value) {
_events.push_back(new Event(time, type, this, value));
_n_events++;
}
void Container::start_link(Date time, LinkType *type, Container *source, EntityValue *value, String key) {
......@@ -188,3 +190,8 @@ void Container::destroy(const Date &time) {
_destruction_time = time;
}
void Container::finish(const Date &time) {
if (_destruction_time.get_value() == 0.0)
destroy(time);
}
......@@ -37,7 +37,9 @@ private:
ContainerType *_type;
Container *_parent;
list<Container *> _children;
int _n_states;
list<State *> _states;
int _n_events;
list<Event *> _events;
list<Link *> _links;
map<VariableType *, Variable *> _variables;
......@@ -243,6 +245,13 @@ public:
* \arg time Destruction tim
*/
void destroy(const Date &time);
/*!
* \fn finish()
* \brief Finish to initialize the container (flush temporary states)
* \param time Time to set destruction time if it was not destroy
*/
void finish(const Date &time);
};
#endif
......@@ -2,6 +2,10 @@
#include "../message/Message.hpp"
Trace::Trace(): _max_date(0.0) {
}
Trace::~Trace() {
// Delete containers
while (!_root_containers.empty()){
......@@ -30,7 +34,7 @@ void Trace::define_container_type(Name &name, ContainerType *parent, map<std::st
parent->add_child(type);
else
_root_container_types.push_back(type);
// Delete unused extra fields
delete_opt(opt);
}
......@@ -44,6 +48,9 @@ void Trace::create_container(Date &time, Name &name, ContainerType *type, Contai
parent->add_child(cont);
else
_root_containers.push_back(cont);
if (time > _max_date)
_max_date = time;
// Delete unused extra fields
delete_opt(opt);
......@@ -53,6 +60,9 @@ void Trace::destroy_container(Date &time, Container *cont, ContainerType *type,
if (cont && type)
cont->destroy(time);
if (time > _max_date)
_max_date = time;
// Delete unused extra fields
delete_opt(opt);
}
......@@ -98,6 +108,9 @@ void Trace::set_state(Date &time, StateType *type, Container *container, EntityV
if (container && type)
container->set_state(time, type, value);
if (time > _max_date)
_max_date = time;
// Delete unused extra fields
delete_opt(opt);
}
......@@ -106,6 +119,9 @@ void Trace::push_state(Date &time, StateType *type, Container *container, Entity
if (container && type)
container->push_state(time, type, value);
if (time > _max_date)
_max_date = time;
// Delete unused extra fields
delete_opt(opt);
}
......@@ -114,6 +130,9 @@ void Trace::pop_state(Date &time, StateType *type, Container *container, map<std
if (container && type)
container->pop_state(time);
if (time > _max_date)
_max_date = time;
// Delete unused extra fields
delete_opt(opt);
}
......@@ -122,6 +141,9 @@ void Trace::new_event(Date &time, EventType *type, Container *container, EntityV
if (container && type)
container->new_event(time, type, value);
if (time > _max_date)
_max_date = time;
// Delete unused extra fields
delete_opt(opt);
}
......@@ -130,6 +152,9 @@ void Trace::set_variable(Date &time, VariableType *type, Container *container, D
if (container && type)
container->set_variable(time, type, value);
if (time > _max_date)
_max_date = time;
// Delete unused extra fields
delete_opt(opt);
}
......@@ -138,6 +163,9 @@ void Trace::add_variable(Date &time, VariableType *type, Container *container, D
if (container && type)
container->add_variable(time, type, value);
if (time > _max_date)
_max_date = time;
// Delete unused extra fields
delete_opt(opt);
}
......@@ -146,6 +174,9 @@ void Trace::sub_variable(Date &time, VariableType *type, Container *container, D
if (container && type)
container->sub_variable(time, type, value);
if (time > _max_date)
_max_date = time;
// Delete unused extra fields
delete_opt(opt);
}
......@@ -154,6 +185,9 @@ void Trace::start_link(Date &time, LinkType *type, Container *ancestor, Containe
if (ancestor && type && source)
ancestor->start_link(time, type, source, value, key);
if (time > _max_date)
_max_date = time;
// Delete unused extra fields
delete_opt(opt);
}
......@@ -162,10 +196,31 @@ void Trace::end_link(Date &time, LinkType *type, Container *ancestor, Container
if (ancestor && type && destination)
ancestor->end_link(time, destination, key);
if (time > _max_date)
_max_date = time;
// Delete unused extra fields
delete_opt(opt);
}
void Trace::finish() {
std::stack<Container *> containers;
for (std::list<Container *>::const_iterator i = _root_containers.begin();
i != _root_containers.end();
i++)
containers.push(*i);
while (!containers.empty()) {
Container * c = containers.top();
containers.pop();
c->finish(_max_date);
for (std::list<Container *>::const_iterator i = c->get_children()->begin();
i != c->get_children()->end();
i++)
containers.push(*i);
}
}
const list <Container *> *Trace::get_root_containers() const {
return &_root_containers;
}
......
......@@ -45,6 +45,7 @@ using std::vector;
class Trace {
private:
Date _max_date;
list <ContainerType *> _root_container_types;
list <Container *> _root_containers;
list <StateType *> _state_types;
......@@ -53,7 +54,7 @@ private:
list <VariableType *> _variable_types;
public :
Trace();
~Trace();
/*!
......@@ -232,6 +233,11 @@ public :
*/
void end_link(Date &time, LinkType *type, Container *ancestor, Container *destination, EntityValue *value, String key, map<std::string, Value *> &opt);
/*!
* \fn finish()
* \brief Finish to initialize the trace
*/
void finish();
/*!
* \fn get_root_containers() const
......
......@@ -59,7 +59,7 @@ public :
* \return the value
*/
double get_value() const;
/*!
*
* \fn operator< (const Date &) const
......
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