Commit 7a590417 authored by Clément Vuchener's avatar Clément Vuchener

Ajout des champs supplementaires et correction des conteneurs de taille nulle

parent 736311b2
......@@ -48,7 +48,8 @@ void Container::add_current_state(Date end) {
end,
_current_states.top().type,
this,
_current_states.top().value);
_current_states.top().value,
_current_states.top().opt);
// Set the change to the new state
if (!_states.empty())
......@@ -63,20 +64,20 @@ void Container::add_current_state(Date end) {
_n_states++;
}
void Container::set_state(Date time, StateType *type, EntityValue *value) {
void Container::set_state(Date time, StateType *type, EntityValue *value, map<std::string, Value *> &opt) {
if (!_current_states.empty()) {
add_current_state(time);
_current_states.pop();
}
_current_states.push((current_state_t){time, type, value});
_current_states.push((current_state_t){time, type, value, opt});
}
void Container::push_state(Date time, StateType *type, EntityValue *value) {
void Container::push_state(Date time, StateType *type, EntityValue *value, map<std::string, Value *> &opt) {
if (!_current_states.empty())
add_current_state(time);
_current_states.push((current_state_t){time, type, value});
_current_states.push((current_state_t){time, type, value, opt});
}
void Container::pop_state(Date time) {
......@@ -90,19 +91,25 @@ 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));
void Container::new_event(Date time, EventType *type, EntityValue *value, map<std::string, Value *> &opt) {
_events.push_back(new Event(time, type, this, value, opt));
_n_events++;
}
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::start_link(Date time, LinkType *type, Container *source, EntityValue *value, String key, map<std::string, Value *> &opt) {
_current_links[key] = (current_link_t){time, type, source, value, opt};
}
void Container::end_link(Date time, Container *destination, String key) {
void Container::end_link(Date time, Container *destination, String key, map<std::string, Value *> &opt) {
map<String, current_link_t, String::less_than>::iterator i = _current_links.find(key);
if (i == _current_links.end()) /* TODO: Error message */
if (i == _current_links.end())
return;
for (map<std::string, Value *>::const_iterator j = opt.begin();
j != opt.end();
j++)
(*i).second.opt[(*j).first] = (*j).second;
_links.push_back(new Link(
(*i).second.start,
time,
......@@ -110,7 +117,8 @@ void Container::end_link(Date time, Container *destination, String key) {
this,
(*i).second.source,
destination,
(*i).second.value));
(*i).second.value,
(*i).second.opt));
_current_links.erase(i);
}
......
......@@ -53,9 +53,10 @@ private:
* Temporary stores states before complete definition
*/
struct current_state_t {
Date start;
StateType *type;
EntityValue *value;
Date start;
StateType *type;
EntityValue *value;
map<std::string, Value *> opt;
};
stack<current_state_t> _current_states;
......@@ -67,6 +68,7 @@ private:
LinkType *type;
Container *source;
EntityValue *value;
map<std::string, Value *> opt;
};
map<String, current_link_t, String::less_than> _current_links;
......@@ -103,7 +105,7 @@ public:
* \param type Type of the state
* \param value Value of the state
*/
void set_state(Date time, StateType *type, EntityValue *value);
void set_state(Date time, StateType *type, EntityValue *value, map<std::string, Value *> &opt);
/*!
* \fn push_state(Date time, StateType *type, EntityValue *value)
......@@ -112,7 +114,7 @@ public:
* \param type Type of the state
* \param value Value of the state
*/
void push_state(Date time, StateType *type, EntityValue *value);
void push_state(Date time, StateType *type, EntityValue *value, map<std::string, Value *> &opt);
/*!
* \fn pop_state(Date time)
......@@ -128,7 +130,7 @@ public:
* \param type Type of the event
* \param value Value of the event
*/
void new_event(Date time, EventType *type, EntityValue *value);
void new_event(Date time, EventType *type, EntityValue *value, map<std::string, Value *> &opt);
/*!
* \fn start_link(Date time, LinkType *type, Container *source, EntityValue *value, String key)
......@@ -139,7 +141,7 @@ public:
* \param value Value of the link
* \param key String that identifies the link to match its end
*/
void start_link(Date time, LinkType *type, Container *source, EntityValue *value, String key);
void start_link(Date time, LinkType *type, Container *source, EntityValue *value, String key, map<std::string, Value *> &opt);
/*!
* \fn end_link(Date time, Container *destination, String key)
......@@ -148,7 +150,7 @@ public:
* \param destination Container to where the link is sent
* \param key String that identifies the link to match its beginning
*/
void end_link(Date time, Container *destination, String key);
void end_link(Date time, Container *destination, String key, map<std::string, Value *> &opt);
/*!
* \fn set_variable(Date time, VariableType *type, Double value)
......
......@@ -201,6 +201,9 @@ public:
size += container->get_variable_number();
}
if (size < 1) // Minimum size
size = 1;
// Push containers with links to draw
if (!container->get_links()->empty())
_link_containers.push_back(container);
......@@ -403,7 +406,9 @@ public:
<< "<strong>Destination:</strong> " << link->get_destination()->get_name().to_string() << "<br />"
<< "<strong>Type:</strong> " << link->get_type()->get_name().to_string() << "<br />"
<< "<strong>Date:</strong> " << link->get_start_time().get_value() << " - " << link->get_end_time().get_value() << "<br />";
print_extra_fields("Link", link->get_extra_fields());
print_extra_fields("Value", link->get_value()->get_extra_fields());
print_extra_fields("Type", link->get_type()->get_extra_fields());
*Message::get_instance() << Message::endsi;
return;
}
......@@ -421,7 +426,9 @@ public:
<< "<strong>Container:</strong> " << event->get_container()->get_name().to_string() << "<br />"
<< "<strong>Type:</strong> " << event->get_type()->get_name().to_string() << "<br />"
<< "<strong>Date:</strong> " << event->get_time().get_value() << "<br />";
print_extra_fields("Event", event->get_extra_fields());
print_extra_fields("Value", event->get_value()->get_extra_fields());
print_extra_fields("Type", event->get_type()->get_extra_fields());
*Message::get_instance() << Message::endsi;
return;
}
......@@ -432,7 +439,9 @@ public:
<< "<strong>Type:</strong> " << state->get_type()->get_name().to_string() << "<br />"
<< "<strong>Date:</strong> " << state->get_start_time().get_value() << " - " << state->get_end_time().get_value() << "<br />"
<< "<strong>Duration:</strong> " << state->get_duration() << "<br />";
print_extra_fields("State", state->get_extra_fields());
print_extra_fields("Value", state->get_value()->get_extra_fields());
print_extra_fields("Type", state->get_type()->get_extra_fields());
*Message::get_instance() << Message::endsi;
return;
}
......@@ -452,8 +461,9 @@ public:
<< "<strong>Container:</strong> " << variable->get_container()->get_name().to_string() << "<br />"
<< "<strong>Type:</strong> " << variable->get_type()->get_name().to_string() << "<br />"
<< "<strong>Min:</strong> " << variable->get_min().get_value() << "<br />"
<< "<strong>Max:</strong> " << variable->get_max().get_value() << "<br />"
<< Message::endsi;
<< "<strong>Max:</strong> " << variable->get_max().get_value() << "<br />";
print_extra_fields("Type", variable->get_type()->get_extra_fields());
*Message::get_instance() << Message::endsi;
return;
}
......@@ -494,6 +504,10 @@ public:
if (container->get_variable_number() > 0)
size += container->get_variable_number();
if (children->empty() && size < 1) // Minimum size
size = 1;
// Test if the position is in this container
if (y < size*(_container_height+_container_v_space))
return container;
......
#include "Entity.hpp"
Entity::Entity(Container *container): _container(container) {
Entity::Entity(Container *container, map<std::string, Value *> opt): _container(container), _extra_fields(opt) {
};
......@@ -8,3 +8,7 @@ const Container *Entity::get_container() const {
return _container;
}
const map<std::string, Value *> *Entity::get_extra_fields() const {
return &_extra_fields;
}
......@@ -7,6 +7,11 @@
class Container;
#include <map>
using std::map;
#include <string>
#include "values/Value.hpp"
/*!
* \class Entity
* \brief Abstract class that describe trace entities (events, states, links, variables)
......@@ -14,9 +19,10 @@ class Container;
class Entity {
private:
Container *_container;
map<std::string, Value *> _extra_fields;
protected:
Entity(Container *container);
Entity(Container *container, map<std::string, Value *> opt);
public:
/*!
......@@ -24,6 +30,12 @@ public:
* \brief Get the container of the entity
*/
const Container *get_container() const;
/*!
* \fn get_extra_fields() const
* \brief Get the extra fields
*/
const map<std::string, Value *> *get_extra_fields() const;
};
#include "Container.hpp"
......
#include "EntityType.hpp"
EntityType::EntityType(Name name, ContainerType *container_type): _name(name), _container_type(container_type) {
EntityType::EntityType(Name name, ContainerType *container_type, map<std::string, Value *> opt):
_name(name), _container_type(container_type), _extra_fields(opt) {
}
......@@ -29,3 +30,8 @@ EntityType::~EntityType(){
_values.pop_front();
}
}
const map<std::string, Value *> *EntityType::get_extra_fields() const {
return &_extra_fields;
}
......@@ -20,13 +20,14 @@ private:
Name _name;
ContainerType *_container_type;
list<EntityValue *> _values;
map<std::string, Value *> _extra_fields;
protected:
/*!
* \fn EntityType(Name name, ContainerType *container_type)
* \brief Default constructor
*/
EntityType(Name name, ContainerType *container_type);
EntityType(Name name, ContainerType *container_type, map<std::string, Value *> opt);
public:
/*
......@@ -58,6 +59,12 @@ public:
* \brief Get the list of the values
*/
const list<EntityValue *> *get_values() const;
/*!
* \fn get_extra_fields() const
* \brief Get the extra fields
*/
const map<std::string, Value *> *get_extra_fields() const;
};
#endif
......
#include "Event.hpp"
Event::Event(Date time, EventType *type, Container *container, EntityValue *value):
Entity(container), _time(time), _type(type), _value(value) {
Event::Event(Date time, EventType *type, Container *container, EntityValue *value, map<std::string, Value *> opt):
Entity(container, opt), _time(time), _type(type), _value(value) {
}
......
......@@ -31,7 +31,7 @@ public:
* \param container Container of the event
* \param value Value of the event
*/
Event(Date time, EventType *type, Container *container, EntityValue *value);
Event(Date time, EventType *type, Container *container, EntityValue *value, map<std::string, Value *> opt);
/*!
* \fn get_time() const
......
#include "EventType.hpp"
EventType::EventType(Name name, ContainerType *container_type):
EntityType(name, container_type) {
EventType::EventType(Name name, ContainerType *container_type, map<std::string, Value *> opt):
EntityType(name, container_type, opt) {
};
......@@ -26,7 +26,7 @@ public :
* \param name Name of the type
* \param container_type Type of the container for event of this type
*/
EventType(Name name, ContainerType *container_type);
EventType(Name name, ContainerType *container_type, map<std::string, Value *> opt);
};
#endif
#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) {
Link::Link(Date start, Date end, LinkType *type, Container *container, Container *source, Container *destination, EntityValue *value, map<std::string, Value *> opt):
Entity(container, opt), _start(start), _end(end), _type(type), _value(value), _source(source), _destination(destination) {
}
......
......@@ -28,7 +28,7 @@ public:
/*!
* \brief Constructor
*/
Link(Date start, Date end, LinkType *type, Container *container, Container *source, Container *destination, EntityValue *value);
Link(Date start, Date end, LinkType *type, Container *container, Container *source, Container *destination, EntityValue *value, map<std::string, Value *> opt);
/*!
* \fn get_start_time() const;
......
#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) {
LinkType::LinkType(Name name, ContainerType *container_type, ContainerType *source_type, ContainerType *destination_type, map<std::string, Value *> opt):
EntityType(name, container_type, opt), _source_type(source_type), _destination_type(destination_type) {
}
......@@ -29,7 +29,7 @@ public :
* \param source_type Type of the source container
* \param destination_type Type of the destination container
*/
LinkType(Name name, ContainerType *container_type, ContainerType *source_type, ContainerType *destination_type);
LinkType(Name name, ContainerType *container_type, ContainerType *source_type, ContainerType *destination_type, map<std::string, Value *> opt);
};
#endif
#include "State.hpp"
State::State(Date start, Date end, StateType *type, Container *container, EntityValue *value):
Entity(container), _start(start), _end(end), _type(type), _value(value) {
State::State(Date start, Date end, StateType *type, Container *container, EntityValue *value, map<std::string, Value *> opt):
Entity(container, opt), _start(start), _end(end), _type(type), _value(value) {
}
......
......@@ -27,7 +27,7 @@ public:
/*!
* \brief Constructor
*/
State(Date start, Date end, StateType *type, Container *container, EntityValue *value);
State(Date start, Date end, StateType *type, Container *container, EntityValue *value, map<std::string, Value *> opt);
/*!
* \fn get_start_time() const;
......
#include "StateType.hpp"
StateType::StateType(Name name, ContainerType *container_type):
EntityType(name, container_type) {
StateType::StateType(Name name, ContainerType *container_type, map<std::string, Value *> opt):
EntityType(name, container_type, opt) {
};
......@@ -21,7 +21,7 @@ public:
* \fn StateType(Name name, ContainerType *container_type)
* \brief Constructor
*/
StateType(Name name, ContainerType *container_type);
StateType(Name name, ContainerType *container_type, map<std::string, Value *> opt);
};
#endif
......@@ -69,34 +69,22 @@ void Trace::destroy_container(Date &time, Container *cont, ContainerType *type,
void Trace::define_event_type(Name &name, ContainerType *container_type, map<std::string, Value *> &opt) {
if (container_type)
_event_types.push_back(new EventType(name, container_type));
// Delete unused extra fields
delete_opt(opt);
_event_types.push_back(new EventType(name, container_type, opt));
}
void Trace::define_state_type(Name &name, ContainerType *container_type, map<std::string, Value *> &opt) {
if (container_type)
_state_types.push_back(new StateType(name, container_type));
// Delete unused extra fields
delete_opt(opt);
_state_types.push_back(new StateType(name, container_type, opt));
}
void Trace::define_variable_type(Name &name, ContainerType *container_type, map<std::string, Value *> &opt) {
if (container_type)
_variable_types.push_back(new VariableType(name, container_type));
// Delete unused extra fields
delete_opt(opt);
_variable_types.push_back(new VariableType(name, container_type, opt));
}
void Trace::define_link_type(Name &name, ContainerType *ancestor, ContainerType *source, ContainerType *destination, map<std::string, Value *> &opt) {
if (ancestor && source && destination)
_link_types.push_back(new LinkType(name, ancestor, source, destination));
// Delete unused extra fields
delete_opt(opt);
_link_types.push_back(new LinkType(name, ancestor, source, destination, opt));
}
void Trace::define_entity_value(Name &name, EntityType *entity_type, map<std::string, Value *> &opt) {
......@@ -106,24 +94,18 @@ void Trace::define_entity_value(Name &name, EntityType *entity_type, map<std::st
void Trace::set_state(Date &time, StateType *type, Container *container, EntityValue *value, map<std::string, Value *> &opt) {
if (container && type)
container->set_state(time, type, value);
container->set_state(time, type, value, opt);
if (time > _max_date)
_max_date = time;
// Delete unused extra fields
delete_opt(opt);
}
void Trace::push_state(Date &time, StateType *type, Container *container, EntityValue *value, map<std::string, Value *> &opt) {
if (container && type)
container->push_state(time, type, value);
container->push_state(time, type, value, opt);
if (time > _max_date)
_max_date = time;
// Delete unused extra fields
delete_opt(opt);
}
void Trace::pop_state(Date &time, StateType *type, Container *container, map<std::string, Value *> &opt) {
......@@ -139,13 +121,10 @@ void Trace::pop_state(Date &time, StateType *type, Container *container, map<std
void Trace::new_event(Date &time, EventType *type, Container *container, EntityValue *value, map<std::string, Value *> &opt) {
if (container && type)
container->new_event(time, type, value);
container->new_event(time, type, value, opt);
if (time > _max_date)
_max_date = time;
// Delete unused extra fields
delete_opt(opt);
}
void Trace::set_variable(Date &time, VariableType *type, Container *container, Double value, map<std::string, Value *> &opt) {
......@@ -183,24 +162,18 @@ void Trace::sub_variable(Date &time, VariableType *type, Container *container, D
void Trace::start_link(Date &time, LinkType *type, Container *ancestor, Container *source, EntityValue *value, String key, map<std::string, Value *> &opt) {
if (ancestor && type && source)
ancestor->start_link(time, type, source, value, key);
ancestor->start_link(time, type, source, value, key, opt);
if (time > _max_date)
_max_date = time;
// Delete unused extra fields
delete_opt(opt);
}
void Trace::end_link(Date &time, LinkType *type, Container *ancestor, Container *destination, EntityValue */*value*/, String key, map<std::string, Value *> &opt) {
if (ancestor && type && destination)
ancestor->end_link(time, destination, key);
ancestor->end_link(time, destination, key, opt);
if (time > _max_date)
_max_date = time;
// Delete unused extra fields
delete_opt(opt);
}
void Trace::finish() {
......
#include "Variable.hpp"
Variable::Variable(Container *container, VariableType *type): Entity(container), _min(0.0), _max(0.0), _type(type) {
Variable::Variable(Container *container, VariableType *type): Entity(container, map<std::string, Value *>()), _min(0.0), _max(0.0), _type(type) {
}
......
#include "VariableType.hpp"
VariableType::VariableType(Name name, ContainerType *container_type): EntityType(name, container_type) {
VariableType::VariableType(Name name, ContainerType *container_type, map<std::string, Value *> opt): EntityType(name, container_type, opt) {
}
......@@ -20,7 +20,7 @@ public:
* \param name Name of the type
* \param container_type Type of the container
*/
VariableType(Name name, ContainerType *container_type);
VariableType(Name name, ContainerType *container_type, map<std::string, Value *> opt);
};
#endif
......
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