From f32f3cd8557c1e8432c5700ba8942429effceddd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Vuchener?= <clement.vuchener@inria.fr>
Date: Sun, 1 Mar 2009 15:03:49 +0000
Subject: [PATCH] =?UTF-8?q?Modification=20du=20stockage=20d'=C3=A9tats=20e?=
 =?UTF-8?q?t=20ajout=20du=20stackage=20d'evenement?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 interface/src/src.pro    |  4 ++
 trace/src/Container.cpp  | 39 ++++++++++--------
 trace/src/Container.hpp  | 20 +++++++---
 trace/src/DrawTrace.hpp  | 86 +++++++++++++++++-----------------------
 trace/src/EntityType.cpp |  2 -
 trace/src/Event.cpp      | 19 +++++++++
 trace/src/Event.hpp      | 26 ++++++++++++
 trace/src/EventType.cpp  |  7 ++++
 trace/src/EventType.hpp  | 31 +++++++++++++++
 trace/src/Makefile       |  2 +-
 trace/src/State.cpp      |  6 +--
 trace/src/State.hpp      | 10 +++--
 trace/src/StateType.cpp  |  2 +-
 trace/src/StateType.hpp  |  4 +-
 trace/src/Trace.cpp      | 20 +++++++++-
 trace/src/Trace.hpp      |  4 +-
 16 files changed, 195 insertions(+), 87 deletions(-)
 create mode 100644 trace/src/Event.cpp
 create mode 100644 trace/src/Event.hpp
 create mode 100644 trace/src/EventType.cpp
 create mode 100644 trace/src/EventType.hpp

diff --git a/interface/src/src.pro b/interface/src/src.pro
index 4065f37f..2b582eb7 100644
--- a/interface/src/src.pro
+++ b/interface/src/src.pro
@@ -32,6 +32,8 @@ HEADERS += interface.hpp \
             ../../trace/src/EntityValue.hpp \
             ../../trace/src/State.hpp \
             ../../trace/src/StateType.hpp \
+            ../../trace/src/Event.hpp \
+            ../../trace/src/EventType.hpp \
             ../../trace/src/Trace.hpp \
             ../../trace/src/values/Color.hpp \
             ../../trace/src/values/Date.hpp \
@@ -66,6 +68,8 @@ render_area.cpp \
            ../../trace/src/EntityValue.cpp \
            ../../trace/src/State.cpp \
            ../../trace/src/StateType.cpp \
+           ../../trace/src/Event.cpp \
+           ../../trace/src/EventType.cpp \
            ../../trace/src/Trace.cpp \
             ../../trace/src/values/Color.cpp \
            ../../trace/src/values/Date.cpp \
diff --git a/trace/src/Container.cpp b/trace/src/Container.cpp
index 3a3358ee..0290d915 100644
--- a/trace/src/Container.cpp
+++ b/trace/src/Container.cpp
@@ -1,25 +1,29 @@
 #include "Container.hpp"
+#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) {
     _state_stack.index = -1;
-    _states = new EntityList;
+}
+
+template <class T>
+static void clear_list(list<T *> &l) {
+    for (typename list<T *>::iterator it = l.begin();
+        it != l.end();
+        it++) {
+        delete *it;
+    }
 }
 
 Container::~Container() {
     // Delete children
-    while (!_children.empty()){
-        delete _children.front();
-        _children.pop_front();
-    }
+    clear_list<Container>(_children);
     
     // Delete states
-    _states->go_beginning();
-    while (!_states->is_empty()) {
-        delete _states->get_current_entity();
-        _states->remove_current();
-    }
-    delete _states;
+    clear_list<State>(_states);
+
+    // Delete events
+    clear_list<Event>(_events);
 }
 
 void Container::add_child(Container *child) {
@@ -29,8 +33,7 @@ void Container::add_child(Container *child) {
 }
 
 void Container::add_current_state(Date end) {
-    _states->go_end();
-    _states->insert_after(new State(
+    _states.push_back(new State(
         _state_stack.states[_state_stack.index].start,
         end,
         _state_stack.states[_state_stack.index].type,
@@ -64,6 +67,10 @@ void Container::pop_state(Date time) {
         _state_stack.states[_state_stack.index].start = time;
     }
 }
+
+void Container::new_event(Date time, EventType *type, EntityValue *value) {
+    _events.push_back(new Event(time, type, this, value));
+}
 
 Name Container::get_name() const {
     return _name;
@@ -89,8 +96,8 @@ Date Container::get_destruction_time() const {
     return _destruction_time;
 }
 
-EntityList *Container::get_states() const {
-  return _states;
+const list<State *> *Container::get_states() const {
+  return &_states;
 }
 
 void Container::destroy(const Date &time) {
diff --git a/trace/src/Container.hpp b/trace/src/Container.hpp
index 4fb7683b..7b8875b8 100644
--- a/trace/src/Container.hpp
+++ b/trace/src/Container.hpp
@@ -21,9 +21,7 @@ using std::list;
 class Container;
 
 #include "State.hpp"
-#include "StateType.hpp"
-#include "EntityValue.hpp"
-#include "EntityList.hpp"
+#include "Event.hpp"
 
 #define STATE_STACK_SIZE 16
 
@@ -41,7 +39,10 @@ private:
     ContainerType *_type;
     Container *_parent;
     list<Container *> _children;
-    EntityList *_states;
+    list<State *> _states;
+    list<Event *> _events;
+    //list<Link *> _links;
+    
     struct state_stack_t {
         struct current_state_t {
             Date start;
@@ -54,7 +55,7 @@ private:
     void add_current_state(Date end);
 
 public: 
-    Container(Name &name, Date &creation_time, ContainerType *type, Container *parent);
+    Container(Name name, Date creation_time, ContainerType *type, Container *parent);
     ~Container();
     
     /*!
@@ -85,6 +86,13 @@ public:
      */
     void pop_state(Date time);
     
+    /*!
+     *
+     * \fn new_event(Date time, EventType *type, EntityValue *value)
+     *
+     */
+    void new_event(Date time, EventType *type, EntityValue *value);
+    
     /*!
      *
      * \fn get_name() const
@@ -139,7 +147,7 @@ public:
      * \brief Returns the list of the states between min and max
      * 
      */                              
-    EntityList *get_states() const;
+    const list<State *> *get_states() const;
     
     /*!
      *
diff --git a/trace/src/DrawTrace.hpp b/trace/src/DrawTrace.hpp
index 2d80b971..0ce5d50b 100644
--- a/trace/src/DrawTrace.hpp
+++ b/trace/src/DrawTrace.hpp
@@ -21,38 +21,38 @@ class DrawTrace
 protected:
 
     //  Interface_graphic* _window;
-    std::stack<EntityList *> _stack_states;
+    std::stack<const list<State *> *> _stack_states;
    
     /*!
-      * \brief The default height for containers.
-      */
-     static const float _DRAWING_CONTAINER_HEIGHT_DEFAULT = 1.2f;
+     * \brief The default height for containers.
+     */
+    static const float _DRAWING_CONTAINER_HEIGHT_DEFAULT = 1.2f;
      
-     /*!
-      * \brief The default width for containers.
-      */
-     static const float _DRAWING_CONTAINER_WIDTH_DEFAULT = 2.5f;
+    /*!
+     * \brief The default width for containers.
+     */
+    static const float _DRAWING_CONTAINER_WIDTH_DEFAULT = 2.5f;
 
-     /*!
-      * \brief The default horizontal space between containers.
-      */
-     static const float _DRAWING_CONTAINER_H_SPACE_DEFAULT = 0.1f;
+    /*!
+     * \brief The default horizontal space between containers.
+     */
+    static const float _DRAWING_CONTAINER_H_SPACE_DEFAULT = 0.1f;
 
-     /*!
-      * \brief The default vertical space between containers.
-      */
-     static const float _DRAWING_CONTAINER_V_SPACE_DEFAULT = 0.2f;
+    /*!
+     * \brief The default vertical space between containers.
+     */
+    static const float _DRAWING_CONTAINER_V_SPACE_DEFAULT = 0.2f;
 
 
     /*!
-      * \brief The default height for states.
-      */
-     static const float _DRAWING_STATE_HEIGHT_DEFAULT = 1.2f;
+     * \brief The default height for states.
+     */
+    static const float _DRAWING_STATE_HEIGHT_DEFAULT = 1.2f;
  
-     /*!
-      * \brief The default vertical space between states.
-      */
-     static const float _DRAWING_STATE_V_SPACE_DEFAULT = 0.2f;
+    /*!
+     * \brief The default vertical space between states.
+     */
+    static const float _DRAWING_STATE_V_SPACE_DEFAULT = 0.2f;
 
 
     /*!
@@ -82,7 +82,7 @@ public:
     /*!
      * \brief The default constructor
      */
-    DrawTrace(){
+    DrawTrace() {
 
         //   _window = NULL;
         _container_width = _DRAWING_CONTAINER_WIDTH_DEFAULT;
@@ -99,7 +99,8 @@ public:
     /*!
      * \brief The destructor
      */
-    virtual ~DrawTrace(){
+    virtual ~DrawTrace() {
+    
     }
 
 
@@ -118,14 +119,14 @@ public:
     /*!
      * \brief The trace building function.
      * \param draw_object the kind of object which will be drawn (OpenGL, SVG...).
-     * \param _trace the trace data.
+     * \param trace the trace data.
      */
-    void build(T* draw_object, Trace* _trace){
+    void build(T* draw_object, Trace* trace) {
 
         draw_object->start_draw();
 
         draw_object->start_draw_containers();
-        browse_container_tree(draw_object, _trace);
+        browse_container_tree(draw_object, trace);
         draw_object->end_draw_containers();
 
         draw_object->start_draw_states();
@@ -153,7 +154,7 @@ public:
      *
      **********************************/
     
-    inline void browse_container_tree(T* draw_object, Trace* _trace){
+    inline void browse_container_tree(T* draw_object, Trace* trace){
          
         /*** Drawing containers ***/
         
@@ -170,7 +171,7 @@ public:
         Element_pos y_buf;/* buffer for the y position */
         Element_pos height_buf;/* buffer for the container height */
         const Container* container;
-        const std::list<Container *> *trace_container = _trace->get_root_containers();
+        const std::list<Container *> *trace_container = trace->get_root_containers();
          
         std::list<Container *>::iterator it;
          
@@ -321,42 +322,27 @@ public:
     inline void browse_state_tree(T* draw_object){
 
 
-        EntityList *buf_list;
+        const list<State *> *buf_list;
         State* buf_entity;
         Element_count i;/* for the level (y axis) of the states */
         
         i=0;
         
         while (!_stack_states.empty()){
-
             buf_list = _stack_states.top();
-         
 	 
-            for (buf_list->go_beginning() ; buf_list->has_next() ; buf_list->next() ) {
+            for(list<State *>::const_iterator it = buf_list->begin();
+                it != buf_list->end();
+                it++) {
 	               
-                buf_entity = (State*)buf_list->get_current_entity();
-     
+                buf_entity = *it;
                 Element_pos base = ((Element_pos)i)*_container_height+((Element_pos)i)*_container_v_space+_container_v_space;
-   
                 /* Call the object state drawing function */ 
                 draw_object->draw_state(buf_entity->get_start_time().get_value(), buf_entity->get_end_time().get_value(), base, _state_height, 0.7, 0.7, 0.75); 
-
             }/* end for */
 
             i++;
 
-
-            /*To draw the last element of the list*/
-            if(!buf_list->is_empty()){
-                buf_entity = (State*)buf_list->get_current_entity();
-                
-                Element_pos base = ((Element_pos)i)*_container_height+((Element_pos)i)*_container_v_space+_container_v_space;
-   
-                 /* Call the object state drawing function */ 
-                draw_object->draw_state(buf_entity->get_start_time().get_value(), buf_entity->get_end_time().get_value(), base, _state_height, 0.7, 0.7, 0.75);
- 
-            }/* end if */
-
             /* pop the top of the stack */
             _stack_states.pop();
 
diff --git a/trace/src/EntityType.cpp b/trace/src/EntityType.cpp
index 5952833b..f975097f 100644
--- a/trace/src/EntityType.cpp
+++ b/trace/src/EntityType.cpp
@@ -25,9 +25,7 @@ EntityType::~EntityType(){
     // Destruction of the list _values
     // As long as everithing has not been cleaned
     while (!_values.empty()){
-      // Deleting the pointed area
         delete _values.front();
-	// Deleting the element of the list
         _values.pop_front();
     }
 }
diff --git a/trace/src/Event.cpp b/trace/src/Event.cpp
new file mode 100644
index 00000000..185e0ceb
--- /dev/null
+++ b/trace/src/Event.cpp
@@ -0,0 +1,19 @@
+#include "Event.hpp"
+
+Event::Event(Date time, EventType *type, Container *container, EntityValue *value):
+    Entity(container), _time(time), _type(type), _value(value) {
+
+}
+
+Date Event::get_time() const {
+    return _time;
+}
+
+const EventType *Event::get_type() const {
+    return _type;
+}
+
+const EntityValue *Event::get_value() const {
+    return _value;
+}
+
diff --git a/trace/src/Event.hpp b/trace/src/Event.hpp
new file mode 100644
index 00000000..8e7c287d
--- /dev/null
+++ b/trace/src/Event.hpp
@@ -0,0 +1,26 @@
+#ifndef EVENT_HPP
+#define EVENT_HPP
+
+class Event;
+
+#include "EventType.hpp"
+#include "EntityValue.hpp"
+#include "values/Date.hpp"
+#include "Entity.hpp"
+
+class Event: public Entity {
+private:
+    Date _time;
+    EventType *_type;
+    EntityValue *_value;
+
+public:
+    Event(Date time, EventType *type, Container *container, EntityValue *value);
+    
+    Date get_time() const;
+    const EventType *get_type() const;
+    const EntityValue *get_value() const;
+};
+
+#endif 
+
diff --git a/trace/src/EventType.cpp b/trace/src/EventType.cpp
new file mode 100644
index 00000000..28ffad07
--- /dev/null
+++ b/trace/src/EventType.cpp
@@ -0,0 +1,7 @@
+#include "EventType.hpp"
+
+EventType::EventType(Name name, ContainerType *container_type):
+    EntityType(name, container_type) {
+    
+};
+
diff --git a/trace/src/EventType.hpp b/trace/src/EventType.hpp
new file mode 100644
index 00000000..f94e40cc
--- /dev/null
+++ b/trace/src/EventType.hpp
@@ -0,0 +1,31 @@
+#ifndef EVENTTYPE_HPP
+#define EVENTTYPE_HPP
+
+/*!
+ *
+ * \author Coulomb, Vuchener
+ * \brief Describes the type of the states
+ *
+ */
+
+class EventType;
+
+#include "EntityType.hpp"
+
+#include "values/Name.hpp"
+#include "ContainerType.hpp"
+
+/*!
+ *
+ *\class EventType
+ *\brief The class that describes the events
+ *
+ */
+class EventType : public EntityType {
+private:
+
+public :
+    EventType(Name name, ContainerType *container_type);
+};
+
+#endif
diff --git a/trace/src/Makefile b/trace/src/Makefile
index c2f73daa..faeb0067 100755
--- a/trace/src/Makefile
+++ b/trace/src/Makefile
@@ -1,6 +1,6 @@
 
 LD = g++
-OBJ = Container.o ContainerType.o Entity.o EntityType.o EntityValue.o State.o StateType.o  Trace.o #-> A decommenter quand fait
+OBJ = Container.o ContainerType.o Entity.o EntityType.o EntityValue.o State.o StateType.o Event.o EventType.o Trace.o
 
 OPT = -g -Wall -W
 LIBS = 
diff --git a/trace/src/State.cpp b/trace/src/State.cpp
index d217adc3..7408bcac 100644
--- a/trace/src/State.cpp
+++ b/trace/src/State.cpp
@@ -1,15 +1,15 @@
 #include "State.hpp"
 
-State::State(Date &start, Date &end, StateType *type, Container *container, EntityValue *value):
+State::State(Date start, Date end, StateType *type, Container *container, EntityValue *value):
 	Entity(container), _start(start), _end(end), _type(type), _value(value) {
 	
 }
 
-const Date &State::get_start_time() const {
+Date State::get_start_time() const {
     return _start;
 }
 
-const Date &State::get_end_time() const {
+Date State::get_end_time() const {
     return _end;
 }
 
diff --git a/trace/src/State.hpp b/trace/src/State.hpp
index 1a1640f3..c88dd9e6 100644
--- a/trace/src/State.hpp
+++ b/trace/src/State.hpp
@@ -10,12 +10,14 @@
  *  
  */
 
-#include "Entity.hpp"
+class State;
 
 #include "values/Date.hpp"
 #include "StateType.hpp"
 #include "EntityValue.hpp"
 
+#include "Entity.hpp"
+
 /*!
  *
  * \class State
@@ -34,7 +36,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);
     
     /*!
      *
@@ -42,7 +44,7 @@ public:
      * \brief Returns the start time of the state
      * 
      */                    
-    const Date &get_start_time() const;
+    Date get_start_time() const;
     
     /*!
      *
@@ -50,7 +52,7 @@ public:
      * \brief Returns the end time of the state
      * 
      */                    
-    const Date &get_end_time() const;
+    Date get_end_time() const;
     
     /*!
      *
diff --git a/trace/src/StateType.cpp b/trace/src/StateType.cpp
index 9b383411..e7242dce 100644
--- a/trace/src/StateType.cpp
+++ b/trace/src/StateType.cpp
@@ -1,6 +1,6 @@
 #include "StateType.hpp"
 
-StateType::StateType(const Name &name, ContainerType *container_type):
+StateType::StateType(Name name, ContainerType *container_type):
     EntityType(name, container_type) {
     
 };
diff --git a/trace/src/StateType.hpp b/trace/src/StateType.hpp
index 2cb6017d..d9247341 100644
--- a/trace/src/StateType.hpp
+++ b/trace/src/StateType.hpp
@@ -8,6 +8,8 @@
  *
  */
 
+class StateType;
+
 #include "EntityType.hpp"
 
 #include "values/Name.hpp"
@@ -23,7 +25,7 @@ class StateType : public EntityType {
 private:
 
 public :
-    StateType(const Name &name, ContainerType *container_type);
+    StateType(Name name, ContainerType *container_type);
 };
 
 #endif
diff --git a/trace/src/Trace.cpp b/trace/src/Trace.cpp
index 2f70d555..85c8eea5 100644
--- a/trace/src/Trace.cpp
+++ b/trace/src/Trace.cpp
@@ -41,7 +41,8 @@ void Trace::destroy_container(Date &time, Container *cont, ContainerType *type,
 }
 
 void Trace::define_event_type(Name &name, ContainerType *container_type, const vector<Value *> &opt) {
-    
+    if (container_type)
+        _event_types.push_back(new EventType(name, container_type));
 }
 
 void Trace::define_state_type(Name &name, ContainerType *container_type, const vector<Value *> &opt) {
@@ -78,7 +79,8 @@ void Trace::pop_state(Date &time, StateType *type, Container *container, const v
 }
 
 void Trace::new_event(Date &time, EventType *type, Container *container, EntityValue *value, const vector<Value *> &opt) {
-
+    if (container)
+        container->new_event(time, type, value);
 }
 
 void Trace::set_variable(Date &time, VariableType *type, Container *container, Double value, const vector<Value *> &opt) {
@@ -151,6 +153,14 @@ Container *Trace::search_container(String name) const {
 }
 
 EventType *Trace::search_event_type(String name) const {
+    for (list<EventType *>::const_iterator it = _event_types.begin();
+        it != _event_types.end();
+        it++) {
+        if ((*it)->get_name() == name)
+            return *it;
+    }
+    
+    //    std::cout << "Unknown event: " << name.to_string() << std::endl;
     return 0;
 }
 
@@ -181,6 +191,12 @@ EntityType *Trace::search_entity_type(String name) const {
         if ((*it)->get_name() == name)
             return *it;
     }
+    for (list<EventType *>::const_iterator it = _event_types.begin();
+        it != _event_types.end();
+        it++) {
+        if ((*it)->get_name() == name)
+            return *it;
+    }
     
     //    std::cout << "Unknown entity type: " << name.to_string() << std::endl;
     return 0;
diff --git a/trace/src/Trace.hpp b/trace/src/Trace.hpp
index 8cd49c06..d3f32650 100644
--- a/trace/src/Trace.hpp
+++ b/trace/src/Trace.hpp
@@ -28,10 +28,11 @@ using std::vector;
 #include "ContainerType.hpp"
 #include "Container.hpp"
 #include "StateType.hpp"
+#include "EventType.hpp"
 #include "EntityValue.hpp"
 #include "State.hpp"
+#include "Event.hpp"
 
-class EventType;
 class VariableType;
 class LinkType;
 
@@ -47,6 +48,7 @@ private:
     list <ContainerType *> _root_container_types;
     list <Container *> _root_containers;
     list <StateType *> _state_types;
+    list <EventType *> _event_types;
 
 public :
 
-- 
GitLab