Mentions légales du service

Skip to content
Snippets Groups Projects
Commit bb37e391 authored by Clément Vuchener's avatar Clément Vuchener
Browse files

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

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