Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[TO DELETE] Mess with instr includes.
[simgrid.git] / src / instr / instr_paje_types.hpp
1 /* Copyright (c) 2010-2023. 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_paje_events.hpp"
10 #include <map>
11 #include <memory>
12 #include <string>
13 #include <vector>
14
15 namespace simgrid::instr {
16 class ContainerType;
17 class EventType;
18 class VariableEvent;
19 class StateEvent;
20
21 long long int new_paje_id();
22
23 class Type {
24   long long int id_ = new_paje_id();
25   std::string name_;
26   std::string color_;
27   Type* parent_;
28   std::map<std::string, std::unique_ptr<Type>, std::less<>> children_;
29   Container* issuer_ = nullptr;
30
31   static xbt::signal<void(Type const&, PajeEventType event_type)> on_creation;
32
33 protected:
34   Container* get_issuer() const { return issuer_; }
35
36 public:
37   static void on_creation_cb(const std::function<void(Type const&, PajeEventType event_type)>& cb)
38   {
39     on_creation.connect(cb);
40   }
41
42   Type(PajeEventType event_type, const std::string& name, const std::string& alias, const std::string& color,
43        Type* parent);
44   virtual ~Type() = default;
45
46   long long int get_id() const { return id_; }
47   const std::string& get_name() const { return name_; }
48   const char* get_cname() const { return name_.c_str(); }
49   const std::string& get_color() const { return color_; }
50   Type* get_parent() const { return parent_; }
51   const std::map<std::string, std::unique_ptr<Type>, std::less<>>& get_children() const { return children_; }
52   bool is_colored() const { return not color_.empty(); }
53
54   Type* by_name(const std::string& name);
55   LinkType* by_name_or_create(const std::string& name, const Type* source, const Type* dest);
56   VariableType* by_name_or_create(const std::string& name, const std::string& color);
57
58   template <class T> T* by_name_or_create(const std::string& name)
59   {
60     auto cont = children_.find(name);
61     return cont == children_.end() ? new T(name, this) : static_cast<T*>(cont->second.get());
62   }
63
64   Type* set_calling_container(Container* container)
65   {
66     issuer_ = container;
67     return this;
68   }
69 };
70
71 class ContainerType : public Type {
72 public:
73   explicit ContainerType(const std::string& name) : Type(PajeEventType::DefineContainerType, name, name, "", nullptr){};
74   ContainerType(const std::string& name, Type* parent)
75       : Type(PajeEventType::DefineContainerType, name, name, "", parent){};
76 };
77
78 class VariableType : public Type {
79   std::vector<VariableEvent*> events_;
80 public:
81   VariableType(const std::string& name, const std::string& color, Type* parent)
82       : Type(PajeEventType::DefineVariableType, name, name, color, parent)
83   {
84   }
85   void instr_event(double now, double delta, const char* resource, double value);
86   void set_event(double timestamp, double value);
87   void add_event(double timestamp, double value);
88   void sub_event(double timestamp, double value);
89 };
90
91 class ValueType : public Type {
92 public:
93   std::map<std::string, EntityValue, std::less<>> values_;
94   ValueType(PajeEventType event_type, const std::string& name, const std::string& alias, Type* parent)
95       : Type(event_type, name, alias, "", parent){};
96   ValueType(PajeEventType event_type, const std::string& name, Type* parent)
97       : Type(event_type, name, name, "", parent){};
98   void add_entity_value(const std::string& name, const std::string& color);
99   void add_entity_value(const std::string& name);
100   EntityValue* get_entity_value(const std::string& name);
101 };
102
103 class LinkType : public ValueType {
104   static xbt::signal<void(LinkType const&, Type const&, Type const&)> on_creation;
105
106 public:
107   static void on_creation_cb(const std::function<void(LinkType const&, Type const&, Type const&)>& cb)
108   {
109     on_creation.connect(cb);
110   }
111   LinkType(const std::string& name, const Type* source, const Type* dest, const std::string& alias, Type* parent)
112       : ValueType(PajeEventType::DefineLinkType, name, alias, parent)
113   {
114     on_creation(*this, *source, *dest);
115   }
116   void start_event(Container* startContainer, const std::string& value, const std::string& key,
117                    size_t size = static_cast<size_t>(-1));
118   void end_event(Container* endContainer, const std::string& value, const std::string& key);
119 };
120
121 class EventType : public ValueType {
122 public:
123   EventType(const std::string& name, Type* parent) : ValueType(PajeEventType::DefineEventType, name, parent) {}
124 };
125
126 class StateType : public ValueType {
127   std::vector<StateEvent*> events_;
128 public:
129   StateType(const std::string& name, Type* parent) : ValueType(PajeEventType::DefineStateType, name, parent) {}
130   void set_event(const std::string& value_name);
131   void push_event(const std::string& value_name);
132   void push_event(const std::string& value_name, TIData* extra);
133   void pop_event();
134   void pop_event(TIData* extra);
135 };
136 } // namespace simgrid::instr
137 #endif