Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
7d9fa60ee7935bb4cd914d4ca3cbf5c447382bdd
[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 <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   static xbt::signal<void(Type&, e_event_type event_type)> on_creation;
27   std::map<std::string, std::unique_ptr<Type>> children_;
28   Container* issuer_ = nullptr;
29
30   Type(e_event_type event_type, const std::string& name, const std::string& alias, const std::string& color,
31        Type* father);
32   virtual ~Type() = default;
33
34   long long int get_id() { return id_; }
35   const std::string& get_name() const { return name_; }
36   const char* get_cname() { return name_.c_str(); }
37   const std::string& get_color() const { return color_; }
38   Type* get_father() const { return father_; }
39   bool is_colored() { return not color_.empty(); }
40
41   Type* by_name(const std::string& name);
42   LinkType* by_name_or_create(const std::string& name, Type* source, Type* dest);
43   VariableType* by_name_or_create(const std::string& name, const std::string& color);
44
45   template <class T> T* by_name_or_create(const std::string& name)
46   {
47     auto cont = children_.find(name);
48     return cont == children_.end() ? new T(name, this) : static_cast<T*>(cont->second.get());
49   }
50
51   Type* set_calling_container(Container* container)
52   {
53     issuer_ = container;
54     return this;
55   }
56 };
57
58 class ContainerType : public Type {
59 public:
60   explicit ContainerType(const std::string& name) : Type(PAJE_DefineContainerType, name, name, "", nullptr){};
61   ContainerType(const std::string& name, Type* father) : Type(PAJE_DefineContainerType, name, name, "", father){};
62 };
63
64 class VariableType : public Type {
65   std::vector<VariableEvent*> events_;
66 public:
67   VariableType(const std::string& name, const std::string& color, Type* father)
68       : Type(PAJE_DefineVariableType, name, name, color, father)
69   {
70   }
71   void instr_event(double now, double delta, const char* resource, double value);
72   void set_event(double timestamp, double value);
73   void add_event(double timestamp, double value);
74   void sub_event(double timestamp, double value);
75 };
76
77 class ValueType : public Type {
78 public:
79   std::map<std::string, EntityValue> values_;
80   ValueType(e_event_type event_type, const std::string& name, const std::string& alias, Type* father)
81       : Type(event_type, name, alias, "", father){};
82   ValueType(e_event_type event_type, const std::string& name, Type* father)
83       : Type(event_type, name, name, "", father){};
84   virtual ~ValueType() = default;
85   void add_entity_value(const std::string& name, const std::string& color);
86   void add_entity_value(const std::string& name);
87   EntityValue* get_entity_value(const std::string& name);
88 };
89
90 class LinkType : public ValueType {
91 public:
92   static xbt::signal<void(LinkType&, Type&, Type&)> on_creation;
93   LinkType(const std::string& name, Type* source, Type* dest, const std::string& alias, Type* father)
94       : ValueType(PAJE_DefineLinkType, name, alias, father)
95   {
96     on_creation(*this, *source, *dest);
97   }
98   void start_event(Container* startContainer, const std::string& value, const std::string& key);
99   void start_event(Container* startContainer, const std::string& value, const std::string& key, int size);
100   void end_event(Container* endContainer, const std::string& value, const std::string& key);
101 };
102
103 class EventType : public ValueType {
104 public:
105   EventType(const std::string& name, Type* father) : ValueType(PAJE_DefineEventType, name, father) {}
106 };
107
108 class StateType : public ValueType {
109   std::vector<StateEvent*> events_;
110 public:
111   StateType(const std::string& name, Type* father) : ValueType(PAJE_DefineStateType, name, father) {}
112   void set_event(const std::string& value_name);
113   void push_event(const std::string& value_name);
114   void push_event(const std::string& value_name, TIData* extra);
115   void pop_event();
116   void pop_event(TIData* extra);
117 };
118 } // namespace instr
119 } // namespace simgrid
120 #endif