Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
443032bee26066b87ea078985d80f49415cd43eb
[simgrid.git] / src / instr / instr_paje_types.hpp
1 /* Copyright (c) 2010-2019. 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 <sstream>
11 #include <string>
12 #include <vector>
13
14 namespace simgrid {
15 namespace instr {
16 class ContainerType;
17 class EventType;
18
19 class Type {
20   long long int id_;
21   std::string name_;
22   std::string color_;
23   Type* father_;
24
25 public:
26   std::map<std::string, Type*> children_;
27   Container* issuer_ = nullptr;
28   std::stringstream stream_;
29
30   Type(std::string name, std::string alias, std::string color, Type* father);
31   virtual ~Type();
32
33   std::string get_name() { return name_; }
34   const char* get_cname() { return name_.c_str(); }
35   long long int get_id() { return id_; }
36   bool is_colored() { return not color_.empty(); }
37
38   Type* by_name(std::string name);
39   LinkType* by_name_or_create(std::string name, Type* source, Type* dest);
40   VariableType* by_name_or_create(std::string name, std::string color);
41
42   template <class T> T* by_name_or_create(std::string name)
43   {
44     auto cont = children_.find(name);
45     return cont == children_.end() ? new T(name, this) : static_cast<T*>(cont->second);
46   }
47
48   void set_calling_container(Container* container) { issuer_ = container; }
49
50   void log_definition(e_event_type event_type);
51   void log_definition(Type* source, Type* dest);
52 };
53
54 class ContainerType : public Type {
55 public:
56   explicit ContainerType(std::string name) : Type(name, name, "", nullptr){};
57   ContainerType(std::string name, Type* father);
58 };
59
60 class VariableType : public Type {
61   std::vector<VariableEvent*> events_;
62 public:
63   VariableType(std::string name, std::string color, Type* father);
64   ~VariableType();
65   void instr_event(double now, double delta, const char* resource, double value);
66   void set_event(double timestamp, double value);
67   void add_event(double timestamp, double value);
68   void sub_event(double timestamp, double value);
69 };
70
71 class ValueType : public Type {
72 public:
73   std::map<std::string, EntityValue*> values_;
74   ValueType(std::string name, std::string alias, Type* father) : Type(name, alias, "", father){};
75   ValueType(std::string name, Type* father) : Type(name, name, "", father){};
76   virtual ~ValueType();
77   void add_entity_value(std::string name, std::string color);
78   void add_entity_value(std::string name);
79   EntityValue* get_entity_value(std::string name);
80 };
81
82 class LinkType : public ValueType {
83 public:
84   LinkType(std::string name, std::string alias, Type* father);
85   void start_event(Container* startContainer, std::string value, std::string key);
86   void start_event(Container* startContainer, std::string value, std::string key, int size);
87   void end_event(Container* endContainer, std::string value, std::string key);
88 };
89
90 class EventType : public ValueType {
91 public:
92   EventType(std::string name, Type* father);
93 };
94
95 class StateType : public ValueType {
96   std::vector<StateEvent*> events_;
97 public:
98   StateType(std::string name, Type* father);
99   ~StateType();
100   void set_event(std::string value_name);
101   void push_event(std::string value_name);
102   void push_event(std::string value_name, TIData* extra);
103   void pop_event();
104   void pop_event(TIData* extra);
105 };
106 }
107 }
108 #endif