Logo AND Algorithmique Numérique Distribuée

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