Container.hpp 12.3 KB
Newer Older
Mathieu Faverge's avatar
Mathieu Faverge committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/*
** This file is part of the ViTE project.
**
** This software is governed by the CeCILL-A license under French law
** and abiding by the rules of distribution of free software. You can
** use, modify and/or redistribute the software under the terms of the
** CeCILL-A license as circulated by CEA, CNRS and INRIA at the following
** URL: "http://www.cecill.info".
** 
** As a counterpart to the access to the source code and rights to copy,
** modify and redistribute granted by the license, users are provided
** only with a limited warranty and the software's author, the holder of
** the economic rights, and the successive licensors have only limited
** liability.
** 
** In this respect, the user's attention is drawn to the risks associated
** with loading, using, modifying and/or developing or reproducing the
** software by the user in light of its specific status of free software,
** that may mean that it is complicated to manipulate, and that also
** therefore means that it is reserved for developers and experienced
** professionals having in-depth computer knowledge. Users are therefore
** encouraged to load and test the software's suitability as regards
** their requirements in conditions enabling the security of their
** systems and/or data to be ensured and, more generally, to use and
** operate it in the same conditions as regards security.
** 
** The fact that you are presently reading this means that you have had
** knowledge of the CeCILL-A license and that you accept its terms.
**
**
31
** ViTE developers are (for version 0.* to 1.0):
Mathieu Faverge's avatar
Mathieu Faverge committed
32 33 34 35 36 37 38 39 40 41 42
**
**        - COULOMB Kevin
**        - FAVERGE Mathieu
**        - JAZEIX Johnny
**        - LAGRASSE Olivier
**        - MARCOUEILLE Jule
**        - NOISETTE Pascal
**        - REDONDY Arthur
**        - VUCHENER Clément 
**
*/
43 44 45 46 47 48
#ifndef CONTAINER_HPP
#define CONTAINER_HPP

/*!
 * \file Container.hpp
 */
49 50 51 52
template <typename E> class Node;
template <typename E> class BinaryTree;
class Statistic;
class Interval;
53 54
/*!
 * \class Container
55
 * \brief Contains others containers or entities
56
 */
57 58 59 60 61 62 63
class Container {  
    friend class State;
   
public:
    typedef std::list<Container *>                 Vector;
    typedef std::list<Container *>::const_iterator VectorIt;

64
private:
65 66 67 68 69
    Name                      _name;
    Date                      _creation_time;
    Date                      _destruction_time;
    ContainerType            *_type;
    Container                *_parent;
70
    Vector                    _children;
71
    unsigned int              _n_states;
72 73
    StateChange::Vector       _states;
    StateChange::Tree        *_state_tree;
74
    unsigned int              _n_events;
75 76 77
    Event::Vector             _events;
    Event::Tree              *_event_tree;
    Link::Vector              _links;
78 79 80
    unsigned int              _n_variables;
    std::map<VariableType *, Variable *> _variables;
    std::map<std::string, Value *>       _extra_fields;
Olivier Lagrasse's avatar
Olivier Lagrasse committed
81 82
    int                       _depth;/* The container depth within the datastructure. The _depth of seed is equal to 0 */

Clément Vuchener's avatar
Clément Vuchener committed
83 84 85 86
    /*
     * Temporary stores states before complete definition
     */
    struct current_state_t {
87 88 89
        Date start;
        StateType *type;
        EntityValue *value;
90
        std::map<std::string, Value *> opt;
Mathieu Faverge's avatar
Mathieu Faverge committed
91 92
        current_state_t(Date t,StateType *st,EntityValue *val, std::map<std::string, Value *> o) : start(t), type(st), value(val), opt(o) {}
        current_state_t() : start(0), type(NULL), value(NULL) {}
Clément Vuchener's avatar
Clément Vuchener committed
93
    };
94
    std::stack<current_state_t> _current_states;
Clément Vuchener's avatar
Clément Vuchener committed
95 96 97 98 99 100 101 102 103
        
    /*
     * Temporary stores links before complete definition
     */
    struct current_link_t {
        Date start;
        LinkType *type;
        Container *source;
        EntityValue *value;
104
        std::map<std::string, Value *> opt;
Mathieu Faverge's avatar
Mathieu Faverge committed
105 106 107 108
        current_link_t(Date st, LinkType *ty, Container *src, EntityValue *val,  std::map<std::string, Value *> o) : start(st), type(ty), source(src), value(val), opt(o) {}
        current_link_t() : start(0), type(NULL), source(NULL), value(NULL) {}


Clément Vuchener's avatar
Clément Vuchener committed
109
    };
110
    std::map<String, current_link_t, String::less_than> _current_links;
111

112 113
    void add_current_state(Date end);

114
public: 
115
    /*!
116
     * \fn Container(Name name, Date creation_time, ContainerType *type, Container *parent, std::map<std::string, Value *> &opt)
117
     * \brief Constructor of Container
Johnny Jazeix's avatar
Johnny Jazeix committed
118 119 120 121
     * \param name Name of the container
     * \param creation_time Date when the container was created
     * \param type Type of the container
     * \param parent Parent container (NULL if the container is root)
122
     * \param opt Optional fields
123
     */
124
    Container(Name name, Date creation_time, ContainerType *type, Container *parent, std::map<std::string, Value *> &opt);
125 126 127 128 129
    
    /*!
     * \fn ~Container()
     * \brief Destructor of Container
     */
130
    ~Container();
131 132
    
    /*!
133
     * \fn add_child(Container *)
134
     * \brief Add a child to the container
Johnny Jazeix's avatar
Johnny Jazeix committed
135
     * \param child new child container
136
     */
137
    void add_child(Container *child);
138 139
    
    /*!
140
     * \fn set_state(Date time, StateType *type, EntityValue *value, std::map<std::string, Value *> &opt)
141
     * \brief Set the current state of the container
Johnny Jazeix's avatar
Johnny Jazeix committed
142 143 144
     * \param time Date of the event
     * \param type Type of the state
     * \param value Value of the state
145
     * \param opt Optional options of the state
146
     */
147
    void set_state(Date time, StateType *type, EntityValue *value, std::map<std::string, Value *> &opt);
148 149
    
    /*!
150
     * \fn push_state(Date time, StateType *type, EntityValue *value, std::map<std::string, Value *> &opt)
151
     * \brief Set the current state of the container and save the previous state
Johnny Jazeix's avatar
Johnny Jazeix committed
152 153 154
     * \param time Date of the event
     * \param type Type of the state
     * \param value Value of the state
155
     * \param opt Optional options of the state
156
     */
157
    void push_state(Date time, StateType *type, EntityValue *value, std::map<std::string, Value *> &opt);
158 159
    
    /*!
160
     * \fn pop_state(Date time)
161
     * \brief Restore a previous state
Johnny Jazeix's avatar
Johnny Jazeix committed
162
     * \param time Date of the event
163 164
     */
    void pop_state(Date time);
165
    
166
    /*!
167
     * \fn new_event(Date time, EventType *type, EntityValue *value, std::map<std::string, Value *> &opt)
168
     * \brief Add a new event
Johnny Jazeix's avatar
Johnny Jazeix committed
169 170 171
     * \param time Date of the event
     * \param type Type of the event
     * \param value Value of the event
172
     * \param opt Optional options of the state
173
     */
174
    void new_event(Date time, EventType *type, EntityValue *value, std::map<std::string, Value *> &opt);
175
    
Clément Vuchener's avatar
Clément Vuchener committed
176
    /*!
177
     * \fn start_link(Date time, LinkType *type, Container *source, EntityValue *value, String key, std::map<std::string, Value *> &opt)
178
     * \brief Start a new link identified by key
Johnny Jazeix's avatar
Johnny Jazeix committed
179 180 181 182 183
     * \param time Date of the start of the link
     * \param type Type of the link
     * \param source Container from where the link is sent
     * \param value Value of the link
     * \param key String that identifies the link to match its end
184
     * \param opt Optional options of the state
Clément Vuchener's avatar
Clément Vuchener committed
185
     */
186
    void start_link(Date time, LinkType *type, Container *source, EntityValue *value, String key, std::map<std::string, Value *> &opt);
Clément Vuchener's avatar
Clément Vuchener committed
187 188
    
    /*!
189
     * \fn end_link(Date time, Container *destination, String key, std::map<std::string, Value *> &opt)
190
     * \brief End a link identified by key
Johnny Jazeix's avatar
Johnny Jazeix committed
191 192 193
     * \param time Date of the end of the link
     * \param destination Container to where the link is sent
     * \param key String that identifies the link to match its beginning
194
     * \param opt Optional options of the state
Clément Vuchener's avatar
Clément Vuchener committed
195
     */
196
    void end_link(Date time, Container *destination, String key, std::map<std::string, Value *> &opt);
Clément Vuchener's avatar
Clément Vuchener committed
197
    
Clément Vuchener's avatar
Clément Vuchener committed
198 199
    /*!
     * \fn set_variable(Date time, VariableType *type, Double value)
200
     * \brief Set a new value of a variable
Johnny Jazeix's avatar
Johnny Jazeix committed
201 202 203
     * \param time Date of the event
     * \param type Type of the variable
     * \param value New value of the variable
Clément Vuchener's avatar
Clément Vuchener committed
204 205 206 207 208
     */
    void set_variable(Date time, VariableType *type, Double value);
    
    /*!
     * \fn add_variable(Date time, VariableType *type, Double value)
209
     * \brief Add a value to the current value of a variable
Johnny Jazeix's avatar
Johnny Jazeix committed
210 211 212
     * \param time Date of the event
     * \param type Type of the variable
     * \param value Value to add
Clément Vuchener's avatar
Clément Vuchener committed
213 214 215 216
     */
    void add_variable(Date time, VariableType *type, Double value);
    
    /*!
217 218
     * \fn sub_variable(Date time, VariableType *type, Double value)
     * \brief Substract a value to the current value of a variable
Johnny Jazeix's avatar
Johnny Jazeix committed
219 220 221
     * \param time Date of the event
     * \param type Type of the variable
     * \param value Value to substract
Clément Vuchener's avatar
Clément Vuchener committed
222 223 224
     */
    void sub_variable(Date time, VariableType *type, Double value);
    
225 226
    /*!
     * \fn get_name() const
227
     * \brief Get the name and the alias of the container
228 229 230 231 232
     */
    Name get_name() const;                    

    /*!
     * \fn get_parent() const
233
     * \brief Get the parent container
234 235 236 237 238
     */                
    const Container *get_parent() const;
    
    /*!
     * \fn get_type() const
239
     * \brief Get the type of the container
240 241 242 243 244
     */                    
    const ContainerType *get_type() const;
    
    /*!
     * \fn get_children() const
245
     * \brief Get the list of the child containers
246
     */                  
247
    const Vector *get_children() const;
248 249 250
    
    /*!
     * \fn get_creation_time() const
251
     * \brief Get the time when the container was created
252 253 254 255 256
     */                    
    Date get_creation_time() const;
    
    /*!
     * \fn get_destruction_time() const
257
     * \brief Get the time when the container was destroyed
258 259 260 261 262
     */                    
    Date get_destruction_time() const;
    
    /*!
     * \fn get_states() const
263
     * \brief Get the state list
264
     */                              
265
    StateChange::Tree *get_states() const;// MODIF -> enleve * du template/ du const
266
    
Clément Vuchener's avatar
Clément Vuchener committed
267 268
    /*!
     * \fn get_events() const
269
     * \brief Get the event list
Clément Vuchener's avatar
Clément Vuchener committed
270
     */
271
    Event::Tree *get_events() const;
Clément Vuchener's avatar
Clément Vuchener committed
272 273 274
    
    /*!
     * \fn get_links() const
275
     * \brief Get the link list
Clément Vuchener's avatar
Clément Vuchener committed
276
     */
277
    const Link::Vector *get_links() const; 
Clément Vuchener's avatar
Clément Vuchener committed
278
    
Clément Vuchener's avatar
Clément Vuchener committed
279 280
    /*!
     * \fn get_variables() const
281
     * \brief Get the variables
Clément Vuchener's avatar
Clément Vuchener committed
282
     */
283
    const std::map<VariableType *, Variable *> *get_variables() const;
Clément Vuchener's avatar
Clément Vuchener committed
284
    
285 286 287 288 289 290
    /*!
     * \fn get_extra_fields() const
     * \brief Get the extra fields
     */
    const std::map<std::string, Value *> *get_extra_fields() const;

291 292 293 294 295 296
    /*!
     * \fn get_state_number() const
     * \brief Get the number of states
     */
    unsigned int get_state_number() const;

Clément Vuchener's avatar
Clément Vuchener committed
297 298
    /*!
     * \fn get_variable_number() const
299
     * \brief Get the number of variables
Clément Vuchener's avatar
Clément Vuchener committed
300
     */
301
    unsigned int get_variable_number() const;
302 303

    /*!
304
     * \fn get_event_number() const
305 306
     * \brief Return the number of events
     */
307
    unsigned int get_event_number() const;
Clément Vuchener's avatar
Clément Vuchener committed
308
    
309 310 311
    /*!
     * \fn destroy(const Date &time)
     * \brief Sets the destruction time of the container
Johnny Jazeix's avatar
Johnny Jazeix committed
312
     * \param time Destruction tim
313 314
     */                         
    void destroy(const Date &time);
315 316
    
    /*!
Johnny Jazeix's avatar
Johnny Jazeix committed
317
     * \fn finish(const Date &time)
318 319 320 321
     * \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);
322 323

    /*!
324
     * \fn fill_stat(Statistic * stat, Interval I)
325 326
     * \brief Fill the stat element with the corresponding data to be displayed
     */
327
    void fill_stat(Statistic * stat, Interval I);
Olivier Lagrasse's avatar
Olivier Lagrasse committed
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343

    /*!
    * \fn set_depth()
    * \brief The depth of the current container.
    *
    * The depth argument specify the depth of the current container. It should be set by the trace instance which store the container.
    */
    void set_depth(int depth);
    
    /*!
      * \fn get_depth()
      * \brief Return the depth of the current container.
      */
    int get_depth();


344 345
};

346
    /*!
347
     * \fn browse_stat_state(Node<StateChange> * node, Statistic * stat, Interval I, Node<StateChange> ** prev)
348 349 350 351
     * \brief Recursive function that browses the tree
     * \param node : The node that is currently added
     * \param stat : The Statistic class that is filled
     * \param I : The interval we want the data in
Kevin Coulomb's avatar
Kevin Coulomb committed
352
     * \param prev : To save the previous state before the interval to be able to count it in the statistic
353
     */
Kevin Coulomb's avatar
Kevin Coulomb committed
354
void browse_stat_state(Node<StateChange> * node, Statistic * stats, Interval I, Node<StateChange> ** prev);
355
    /*!
356
     * \fn browse_stat_link(const Container * cont, Statistic * S, Interval I)
357 358
     * \brief Fill the stat element with the corresponding data to be displayed
     */
Kevin Coulomb's avatar
Kevin Coulomb committed
359
void browse_stat_link(const Container * cont, Statistic * S, Interval I);
360

Olivier Lagrasse's avatar
Olivier Lagrasse committed
361

362
#endif