Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix invalid read
[simgrid.git] / src / instr / instr_paje_types.hpp
1 /* Copyright (c) 2010-2017. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef INSTR_PAJE_TYPES_HPP
7 #define INSTR_PAJE_TYPES_HPP
8
9 #include "src/instr/instr_private.hpp"
10 #include <string>
11 #include <vector>
12
13 namespace simgrid {
14 namespace instr {
15 enum e_event_type : unsigned int;
16 class EntityValue;
17 class ContainerType;
18 class EventType;
19 class LinkType;
20 class StateType;
21 class VariableType;
22 class StateEvent;
23 class VariableEvent;
24
25 class Type {
26   long long int id_;
27   std::string name_;
28   std::string color_;
29   Type* father_;
30
31 public:
32   std::map<std::string, Type*> children_;
33
34   Type(std::string name, std::string alias, std::string color, Type* father);
35   virtual ~Type();
36
37   std::string getName() { return name_; }
38   const char* getCname() { return name_.c_str(); }
39   long long int getId() { return id_; }
40   bool isColored() { return not color_.empty(); }
41
42   Type* byName(std::string name);
43   ContainerType* getOrCreateContainerType(std::string name);
44   EventType* getOrCreateEventType(std::string name);
45   LinkType* getOrCreateLinkType(std::string name, Type* source, Type* dest);
46   StateType* getOrCreateStateType(std::string name);
47   VariableType* getOrCreateVariableType(std::string name, std::string color);
48
49   void logDefinition(e_event_type event_type);
50   void logDefinition(Type* source, Type* dest);
51 };
52
53 class ContainerType : public Type {
54 public:
55   explicit ContainerType(std::string name) : Type(name, name, "", nullptr){};
56   ContainerType(std::string name, Type* father);
57 };
58
59 class VariableType : public Type {
60   std::vector<VariableEvent*> events_;
61   Container* issuer_ = nullptr;
62
63 public:
64   VariableType(std::string name, std::string color, Type* father);
65   ~VariableType();
66   void setCallingContainer(Container* container) { issuer_ = container; }
67   void setEvent(double timestamp, double value);
68   void addEvent(double timestamp, double value);
69   void subEvent(double timestamp, double value);
70 };
71
72 class ValueType : public Type {
73 public:
74   std::map<std::string, EntityValue*> values_;
75   ValueType(std::string name, std::string alias, Type* father) : Type(name, alias, "", father){};
76   ValueType(std::string name, Type* father) : Type(name, name, "", father){};
77   virtual ~ValueType();
78   void addEntityValue(std::string name, std::string color);
79   void addEntityValue(std::string name);
80   EntityValue* getEntityValue(std::string name);
81 };
82
83 class LinkType : public ValueType {
84 public:
85   LinkType(std::string name, std::string alias, Type* father);
86   void startEvent(Container* source_container, Container* sourceContainer, std::string value, std::string key);
87   void startEvent(Container* source_container, Container* sourceContainer, std::string value, std::string key,
88                   int size);
89   void endEvent(Container* source_container, Container* destContainer, std::string value, std::string key);
90 };
91
92 class EventType : public ValueType {
93 public:
94   EventType(std::string name, Type* father);
95 };
96
97 class StateType : public ValueType {
98   std::vector<StateEvent*> events_;
99   Container* issuer_ = nullptr;
100
101 public:
102   StateType(std::string name, Type* father);
103   ~StateType();
104   void setCallingContainer(Container* container) { issuer_ = container; }
105   void setEvent(std::string value_name);
106   void pushEvent(std::string value_name);
107   void pushEvent(std::string value_name, void* extra);
108   void popEvent();
109 };
110 }
111 }
112 #endif