Logo AND Algorithmique Numérique Distribuée

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